javax.swing.text.GlyphView Java Examples

The following examples show how to use javax.swing.text.GlyphView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 * Determines the best location (in the model) to break
 * the given view.
 * This method attempts to break on a whitespace
 * location.  If a whitespace location can't be found, the
 * nearest character location is returned.
 *
 * @param v the view
 * @param p0 the location in the model where the
 *  fragment should start its representation >= 0
 * @param x the graphic location along the axis that the
 *  broken view would occupy >= 0; this may be useful for
 *  things like tab calculations
 * @param len specifies the distance into the view
 *  where a potential break is desired >= 0
 * @return the model location desired for a break
 * @see View#breakView
 */
@Override
public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
    int ret;
    
    try {
        sync(v);
        TabExpander expander = v.getTabExpander();
        String s = v.getDocument().getText(p0, v.getEndOffset()-p0);
        int index = getTabbedTextOffset(v,s, (int)x, (int)(x+len), expander, p0, false, null);
        int p1 = p0 + index;
        ret = p1;
    } catch (BadLocationException e) {
        //e.printStackTrace();
        ret = -1;
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }

    return ret;
}
 
Example #2
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 * Determine the span the glyphs given a start location
 * (for tab expansion).
 * @param exp
 * @return 
 */
@Override
public float getSpan(GlyphView v, int p0, int p1,
                     TabExpander exp, float x) {
    try {
        sync(v);
        String docText = v.getDocument().getText(p0,p1-p0);
        float width = getTabbedTextWidth(v, docText, x, exp, p0, null);
        return width;
    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }

    return 0;
}
 
Example #3
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 6 votes vote down vote up
private void checkKerning(GlyphView v) {
    Object testKVal = v.getElement().getAttributes().getAttribute(KEY_KERNING);
    if (testKVal != null) {
        float kValue;
        
        if (testKVal instanceof Double) {
            kValue = ((Double)testKVal).floatValue();
        } else if (testKVal instanceof Float) {
            kValue = (Float)testKVal;
        } else {
            kValue = (float)testKVal;
        }
        
        for (int i=glyphVector.getNumGlyphs()-1; i>=0; i--) {
            Point2D p=glyphVector.getGlyphPosition(i);
            p.setLocation(p.getX() + i * kValue, p.getY());
            glyphVector.setGlyphPosition(i, p);
        }
    }
}
 
Example #4
Source File: WrapHTMLFactory.java    From SmartIM with Apache License 2.0 6 votes vote down vote up
public View breakView(int axis, int p0, float pos, float len) {
    if (axis == View.X_AXIS) {
        checkPainter();
        int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
        try {
            // if the view contains line break char break the view
            int index = getDocument().getText(p0, p1 - p0).indexOf(WrapHTMLFactory.SEPARATOR);
            if (index >= 0) {
                GlyphView v = (GlyphView)createFragment(p0, p0 + index + 1);
                return v;
            }
        } catch (BadLocationException ex) {
            // should never happen
        }

    }
    return super.breakView(axis, p0, pos, len);
}
 
Example #5
Source File: bug8014863.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #6
Source File: bug8014863.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #7
Source File: bug6857057.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #8
Source File: bug6857057.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #9
Source File: bug6857057.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #10
Source File: bug8014863.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #11
Source File: bug6857057.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #12
Source File: bug8014863.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #13
Source File: bug6857057.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #14
Source File: bug8014863.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #15
Source File: bug6857057.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #16
Source File: bug8014863.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #17
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
public GlyphVectorPainter(String text, GlyphView v) {
    if (v!=null) {
        this.text=text;
        this.font=v.getFont();
        init(v);
    }
}
 
Example #18
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
void sync(GlyphView v) {
    try {
        String localText=v.getDocument().getText(v.getStartOffset(), v.getEndOffset()-v.getStartOffset());
        if (!localText.equals(text)) {
            this.text=localText;
            init(v);
        }
    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
}
 
Example #19
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
private void init(GlyphView v) {
    AffineTransform defaultTransform = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform();
    FontRenderContext frc = new FontRenderContext(defaultTransform, true, true);
    lm = font.getLineMetrics(text.toCharArray(), 0, text.toCharArray().length, frc);

    glyphVector=font.layoutGlyphVector(frc,text.toCharArray(), 0, text.length(), 0);
    checkKerning(v);
    checkOppositeItalic(v);
    checkScale(v);
    spaceVector=font.layoutGlyphVector(frc," ".toCharArray(), 0, 1, 0);
}
 
Example #20
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
private void checkOppositeItalic(GlyphView v) {
    TextShapeTransform value=(TextShapeTransform)v.getElement().getAttributes().getAttribute(KEY_OPPOSITE_ITALIC);
    if (value!=null) {
        isOppositeItalic=true;
        transform=value;
    }
}
 
Example #21
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
private void checkScale(GlyphView v) {
    TextShapeTransform value=(TextShapeTransform)v.getElement().getAttributes().getAttribute(KEY_SCALE_TRANSFORM);
    if (value!=null) {
        isScale=true;
        transform=value;
    }
}
 
Example #22
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
@Override
public GlyphView.GlyphPainter getPainter(GlyphView v, int p0, int p1) {
    try {
        String localText=v.getDocument().getText(p0, p1-p0);
        return new GlyphVectorPainter(localText, v);
    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
    return null;
}
 
Example #23
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Provides a mapping from the view coordinate space to the logical
 * coordinate space of the model.
 *
 * @param v the view containing the view coordinates
 * @param x the X coordinate
 * @param y the Y coordinate
 * @param a the allocated region to render into
 * @param biasReturn always returns <code>Position.Bias.Forward</code>
 *   as the zero-th element of this array
 * @return the location within the model that best represents the
 *  given point in the view
 * @see View#viewToModel
 */
@Override
public int viewToModel(GlyphView v, float x, float y, Shape a,
                       Position.Bias[] biasReturn) {
    int ret;
    
    try {
        if (a != null) {
            sync(v);
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
            int p0 = v.getStartOffset();
            int p1 = v.getEndOffset();
            TabExpander expander = v.getTabExpander();
            String docText = v.getDocument().getText(p0, p1-p0);
            int offs = getTabbedTextOffset(v, docText, alloc.x, (int) x, expander, p0, true, null);
            int retValue = p0 + offs;
            if(retValue == p1) {
                // No need to return backward bias as GlyphPainter1 is used for
                // ltr text only.
                retValue--;
            }
            biasReturn[0] = Position.Bias.Forward;
            ret = retValue;
        } else {
            ret = -1;
        }
    } catch (BadLocationException e) {
        //e.printStackTrace();
        ret = -1;
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
    return ret;
}
 
Example #24
Source File: bug6857057.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #25
Source File: bug6857057.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #26
Source File: bug8014863.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #27
Source File: bug6857057.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example #28
Source File: bug8014863.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #29
Source File: bug8014863.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example #30
Source File: bug6857057.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}