Java Code Examples for java.awt.font.GlyphMetrics

The following are top voted examples for showing how to use java.awt.font.GlyphMetrics. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 2
Project: OpenJSharp   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
@Override
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length()) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
    		strike.getGlyphMetrics( glyphs.charAt( ix ) );
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                      (byte)0);
    return gm;
}
 
Example 3
Project: jdk8u-jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 4
Project: openjdk-jdk10   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 5
Project: openjdk9   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 6
Project: jdk8u_jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 7
Project: lookaside_java-1.8.0-openjdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 8
Project: cachebox3.0   File: FontSystem.java   Source Code and License 6 votes vote down vote up
@Override
public MissingGlyph getGlyph(String unicode)
{
    FontRenderContext frc = new FontRenderContext(null, true, true);
    GlyphVector vec = sysFont.createGlyphVector(frc, unicode);
    
    Glyph glyph = (Glyph)glyphCache.get(unicode);
    if (glyph == null)
    {
        glyph = new Glyph();
        glyph.setPath(vec.getGlyphOutline(0));

        GlyphMetrics gm = vec.getGlyphMetrics(0);
        glyph.setHorizAdvX((int)gm.getAdvanceX());
        glyph.setVertAdvY((int)gm.getAdvanceY());
        glyph.setVertOriginX(0);
        glyph.setVertOriginY(0);
        
        glyphCache.put(unicode, glyph);
    }
    
    return glyph;
}
 
Example 9
Project: javify   File: FreetypeGlyphVector.java   Source Code and License 6 votes vote down vote up
public Shape getGlyphLogicalBounds(int glyphIndex)
{
  GlyphMetrics gm = getGlyphMetrics( glyphIndex );
  if( gm == null )
    return null;
  Rectangle2D r = gm.getBounds2D();
  Point2D p = getGlyphPosition( glyphIndex );

  double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
                                  p.getY() + r.getY(),
                                  p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
                                  p.getY() + r.getY() + r.getHeight()};

  if (glyphTransforms[glyphIndex] != null)
    glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);

  return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
                                bounds[3] - bounds[1]);
}
 
Example 10
Project: jvm-stm   File: FreetypeGlyphVector.java   Source Code and License 6 votes vote down vote up
public Shape getGlyphLogicalBounds(int glyphIndex)
{
  GlyphMetrics gm = getGlyphMetrics( glyphIndex );
  if( gm == null )
    return null; 
  Rectangle2D r = gm.getBounds2D();
  Point2D p = getGlyphPosition( glyphIndex );
  
  double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
                                  p.getY() + r.getY(),
                                  p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
                                  p.getY() + r.getY() + r.getHeight()};
  
  if (glyphTransforms[glyphIndex] != null)
    glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);
  
  return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
                                bounds[3] - bounds[1]);
}
 
Example 11
Project: jcadencii   File: BLabel.java   Source Code and License 6 votes vote down vote up
private GlyphVector getWrappedGlyphVector(String str, float wrapping,
    Font font, FontRenderContext frc) {
    Point2D gmPos = new Point2D.Double(0.0d, 0.0d);
    GlyphVector gv = font.createGlyphVector(frc, str);
    float lineheight = (float) gv.getLogicalBounds().getHeight();
    float xpos = 0.0f;
    float advance = 0.0f;
    int lineCount = 0;
    GlyphMetrics gm;

    for (int i = 0; i < gv.getNumGlyphs(); i++) {
        gm = gv.getGlyphMetrics(i);
        advance = gm.getAdvance();

        if ((xpos < wrapping) && (wrapping <= (xpos + advance))) {
            lineCount++;
            xpos = 0.0f;
        }

        gmPos.setLocation(xpos, lineheight * lineCount);
        gv.setGlyphPosition(i, gmPos);
        xpos = xpos + advance;
    }

    return gv;
}
 
Example 12
Project: infobip-open-jdk-8   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 13
Project: jdk8u-dev-jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 14
Project: jdk7-jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 15
Project: libgdxcn   File: Glyph.java   Source Code and License 6 votes vote down vote up
Glyph (int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 16
Project: openjdk-source-code-learn   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 17
Project: OLD-OpenJDK8   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 18
Project: GdxStudio   File: Glyph.java   Source Code and License 6 votes vote down vote up
Glyph (int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 19
Project: cn1   File: LinuxGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public LinuxGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 20
Project: cn1   File: WinGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public WinGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 21
Project: cn1   File: FLGlyph.java   Source Code and License 6 votes vote down vote up
@Override
public GlyphMetrics getGlyphMetrics(){
    if (glMetrics == null) {
        float[] metrics = getGlyphMetrics(glyphPointer);
        
        this.glMetrics = new GlyphMetrics(
                true, 
                Math.round(metrics[0]),//metrics[0], 
                Math.round(metrics[1]),//metrics[1],
                //new Rectangle2D.Double(initOutline().getBounds2D().getMinX(), initOutline().getBounds2D().getMinY(), initOutline().getBounds2D().getMaxX() + 5, initOutline().getBounds2D().getMaxY()),                    
                initOutline().getBounds2D(),//new Rectangle2D.Float(metrics[2], -metrics[5]-1,metrics[4]- metrics[2] + 1, metrics[5] - metrics[3] + 1),
                GlyphMetrics.STANDARD);
    }
    
    return glMetrics;
}
 
Example 22
Project: JamVM-PH   File: FreetypeGlyphVector.java   Source Code and License 6 votes vote down vote up
public Shape getGlyphLogicalBounds(int glyphIndex)
{
  GlyphMetrics gm = getGlyphMetrics( glyphIndex );
  if( gm == null )
    return null; 
  Rectangle2D r = gm.getBounds2D();
  Point2D p = getGlyphPosition( glyphIndex );
  
  double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
                                  p.getY() + r.getY(),
                                  p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
                                  p.getY() + r.getY() + r.getHeight()};
  
  if (glyphTransforms[glyphIndex] != null)
    glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);
  
  return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
                                bounds[3] - bounds[1]);
}
 
Example 23
Project: r2cat   File: PDFFontEmbedderType3.java   Source Code and License 6 votes vote down vote up
protected void writeGlyph(String characterName, Shape glyph,
        GlyphMetrics glyphMetrics) throws IOException {

    PDFStream glyphStream = pdf.openStream(
            createCharacterReference(characterName), new String[] {
                    "Flate", "ASCII85" });

    Rectangle2D bounds = glyphMetrics != null ? glyphMetrics.getBounds2D()
            : glyph.getBounds2D();
    double advance = glyphMetrics != null ? glyphMetrics.getAdvance()
            : getUndefinedWidth();
    glyphStream.glyph(advance, 0, bounds.getX(), bounds.getY(), bounds
            .getX()
            + bounds.getWidth(), bounds.getY() + bounds.getHeight());

    boolean windingRule = glyphStream.drawPath(glyph);
    if (windingRule) {
        glyphStream.fillEvenOdd();
    } else {
        glyphStream.fill();
    }
    pdf.close(glyphStream);
}
 
Example 24
Project: openjdk-jdk7u-jdk   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 25
Project: classpath   File: FreetypeGlyphVector.java   Source Code and License 6 votes vote down vote up
public Shape getGlyphLogicalBounds(int glyphIndex)
{
  GlyphMetrics gm = getGlyphMetrics( glyphIndex );
  if( gm == null )
    return null;
  Rectangle2D r = gm.getBounds2D();
  Point2D p = getGlyphPosition( glyphIndex );

  double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
                                  p.getY() + r.getY(),
                                  p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
                                  p.getY() + r.getY() + r.getHeight()};

  if (glyphTransforms[glyphIndex] != null)
    glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);

  return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
                                bounds[3] - bounds[1]);
}
 
Example 26
Project: freeVM   File: LinuxGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public LinuxGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 27
Project: freeVM   File: WinGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public WinGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 28
Project: freeVM   File: LinuxGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public LinuxGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 29
Project: freeVM   File: WinGlyph.java   Source Code and License 6 votes vote down vote up
/**
 * Default Glyph constructor
 */
public WinGlyph(char c, int glyphIndex) {
    float metrics[] = new float[6];
    int[] pxlMetrics = new int[6];

    this.pFont = 0;
    this.fontSize = 0;

    Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                    -metrics[1],
                                                    metrics[4],
                                                    metrics[5]);
    this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)0);

    this.glCode = glyphIndex;
    this.glChar = c;

    Rectangle rct  = new Rectangle(pxlMetrics[0],
                                                    -pxlMetrics[1],
                                                    pxlMetrics[4],
                                                    pxlMetrics[5]);
    this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
}
 
Example 30
Project: freeVM   File: FLGlyph.java   Source Code and License 6 votes vote down vote up
@Override
public GlyphMetrics getGlyphMetrics(){
    if (glMetrics == null) {
        float[] metrics = getGlyphMetrics(glyphPointer);
        
        this.glMetrics = new GlyphMetrics(
                true, 
                Math.round(metrics[0]),//metrics[0], 
                Math.round(metrics[1]),//metrics[1],
                //new Rectangle2D.Double(initOutline().getBounds2D().getMinX(), initOutline().getBounds2D().getMinY(), initOutline().getBounds2D().getMaxX() + 5, initOutline().getBounds2D().getMaxY()),                    
                initOutline().getBounds2D(),//new Rectangle2D.Float(metrics[2], -metrics[5]-1,metrics[4]- metrics[2] + 1, metrics[5] - metrics[3] + 1),
                GlyphMetrics.STANDARD);
    }
    
    return glMetrics;
}
 
Example 31
Project: openjdk-icedtea7   File: StandardGlyphVector.java   Source Code and License 6 votes vote down vote up
public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }

    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(),
               vb.getMinY() - pt.getY(),
               vb.getWidth(),
               vb.getHeight());
    Point2D.Float adv =
        getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y,
                                       vb,
                                       GlyphMetrics.STANDARD);
    return gm;
}
 
Example 32
Project: touhou-java   File: Glyph.java   Source Code and License 6 votes vote down vote up
Glyph (int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 33
Project: trashjam2017   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new glyph
 * 
 * @param codePoint The code point in which this glyph can be found
 * @param bounds The bounds that this glrph can fill
 * @param vector The vector this glyph is part of
 * @param index The index of this glyph within the vector
 * @param unicodeFont The font this glyph forms part of
 */
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 34
Project: trashjam2017   File: BMFontUtil.java   Source Code and License 5 votes vote down vote up
private int[] getGlyphMetrics (Font font, int codePoint) {
	// xOffset and xAdvance will be incorrect for unicode characters such as combining marks or non-spacing characters
	// (eg Pnujabi's "\u0A1C\u0A47") that require the context of surrounding glyphs to determine spacing, but thisis the
	// best we can do with the BMFont format.
	char[] chars = Character.toChars(codePoint);
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	GlyphMetrics metrics = vector.getGlyphMetrics(0);
	int xOffset = vector.getGlyphPixelBounds(0, null, 0, 0).x - unicodeFont.getPaddingLeft();
	int xAdvance = (int)(metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont
		.getPaddingRight());
	return new int[] {xOffset, xAdvance};
}
 
Example 35
Project: Progetto-C   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new glyph
 * 
 * @param codePoint The code point in which this glyph can be found
 * @param bounds The bounds that this glrph can fill
 * @param vector The vector this glyph is part of
 * @param index The index of this glyph within the vector
 * @param unicodeFont The font this glyph forms part of
 */
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 36
Project: Progetto-C   File: BMFontUtil.java   Source Code and License 5 votes vote down vote up
private int[] getGlyphMetrics (Font font, int codePoint) {
	// xOffset and xAdvance will be incorrect for unicode characters such as combining marks or non-spacing characters
	// (eg Pnujabi's "\u0A1C\u0A47") that require the context of surrounding glyphs to determine spacing, but thisis the
	// best we can do with the BMFont format.
	char[] chars = Character.toChars(codePoint);
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	GlyphMetrics metrics = vector.getGlyphMetrics(0);
	int xOffset = vector.getGlyphPixelBounds(0, null, 0, 0).x - unicodeFont.getPaddingLeft();
	int xAdvance = (int)(metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont
		.getPaddingRight());
	return new int[] {xOffset, xAdvance};
}
 
Example 37
Project: BaseClient   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new glyph
 * 
 * @param codePoint The code point in which this glyph can be found
 * @param bounds The bounds that this glrph can fill
 * @param vector The vector this glyph is part of
 * @param index The index of this glyph within the vector
 * @param unicodeFont The font this glyph forms part of
 */
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 38
Project: OpenJSharp   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 39
Project: jdk8u-jdk   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 40
Project: openjdk-jdk10   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 41
Project: openjdk9   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 42
Project: Push2Display   File: AWTGVTGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of the glyph at the specified index into this
 * GVTGlyphVector.
 */
public GVTGlyphMetrics getGlyphMetrics(int glyphIndex) {
    if (glyphMetrics[glyphIndex] != null)
        return glyphMetrics[glyphIndex];

    // -- start glyph cache code --
    Point2D glyphPos = defaultGlyphPositions[glyphIndex];
    char c = ci.setIndex(ci.getBeginIndex()+glyphIndex);
    ci.setIndex(ci.getBeginIndex());
    AWTGlyphGeometryCache.Value v = AWTGVTFont.getGlyphGeometry
        (gvtFont, c, awtGlyphVector, glyphIndex, glyphPos);
    Rectangle2D gmB = v.getBounds2D();
    // -- end glyph cache code --

    Rectangle2D bounds = new Rectangle2D.Double
        (gmB.getX()     * scaleFactor, gmB.getY()      * scaleFactor,
         gmB.getWidth() * scaleFactor, gmB.getHeight() * scaleFactor);

    // defaultGlyphPositions has one more entry than glyphs
    // the last entry stores the total advance for the
    // glyphVector.
    float adv = (float)(defaultGlyphPositions[glyphIndex+1].getX()-
                        defaultGlyphPositions[glyphIndex]  .getX());
    glyphMetrics[glyphIndex] =  new GVTGlyphMetrics
        ((float)(adv*scaleFactor), (ascent+descent),
         bounds, GlyphMetrics.STANDARD);

    return glyphMetrics[glyphIndex];
}
 
Example 43
Project: Push2Display   File: AWTGVTFont.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the geometry of the specified character. This method also put
 * the in cache the geometry associated to the specified character if
 * needed.
 */
public static
    AWTGlyphGeometryCache.Value getGlyphGeometry(AWTGVTFont font,
                                                 char c,
                                                 GlyphVector gv,
                                                 int glyphIndex,
                                                 Point2D glyphPos) {

    AWTGlyphGeometryCache glyphCache =
        (AWTGlyphGeometryCache)fontCache.get(font.awtFont);

    AWTGlyphGeometryCache.Value v = glyphCache.get(c);
    if (v == null) {
        Shape outline = gv.getGlyphOutline(glyphIndex);
        GlyphMetrics metrics = gv.getGlyphMetrics(glyphIndex);
        Rectangle2D gmB = metrics.getBounds2D();
        if (AWTGVTGlyphVector.outlinesPositioned()) {
            AffineTransform tr = AffineTransform.getTranslateInstance
                (-glyphPos.getX(), -glyphPos.getY());
            outline = tr.createTransformedShape(outline);
        }
        v = new AWTGlyphGeometryCache.Value(outline, gmB);
        //System.out.println("put "+font.awtFont+" "+c);
        glyphCache.put(c, v);
    }
    return v;
}
 
Example 44
Project: Push2Display   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of this Glyph if it is used in a horizontal layout.
 *
 * @return The glyph metrics.
 */
public GVTGlyphMetrics getGlyphMetrics() {
    if (metrics == null) {
        Rectangle2D gb = getGeometryBounds();

        metrics = new GVTGlyphMetrics
            (getHorizAdvX(), getVertAdvY(),
             new Rectangle2D.Double(gb.getX()-position.getX(),
                                    gb.getY()-position.getY(),
                                    gb.getWidth(),gb.getHeight()),
             GlyphMetrics.COMPONENT);
    }
    return metrics;
}
 
Example 45
Project: jdk8u_jdk   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 46
Project: lookaside_java-1.8.0-openjdk   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 47
Project: javify   File: FreetypeGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Cloning constructor
 */
private FreetypeGlyphVector( FreetypeGlyphVector gv )
{
  font = gv.font;
  peer = gv.peer;
  frc = gv.frc;
  s = gv.s;
  nGlyphs = gv.nGlyphs;
  logicalBounds = gv.logicalBounds.getBounds2D();

  if( gv.metricsCache != null )
    {
      metricsCache = new GlyphMetrics[ nGlyphs ];
      System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
    }

  glyphCodes = new int[ nGlyphs ];
  fontSet = new long[nGlyphs];
  glyphPositions = new float[(nGlyphs + 1) * 2];
  glyphTransforms = new AffineTransform[ nGlyphs ];
  Arrays.fill(glyphTransforms, null);

  for(int i = 0; i < nGlyphs; i++ )
    {
      if (gv.glyphTransforms[i] != null)
        glyphTransforms[ i ] = new AffineTransform(gv.glyphTransforms[i]);
      glyphCodes[i] = gv.glyphCodes[ i ];
    }
  System.arraycopy(gv.glyphPositions, 0, glyphPositions, 0,
                   glyphPositions.length);
  System.arraycopy(gv.glyphCodes, 0, glyphCodes, 0, nGlyphs);
  System.arraycopy(gv.fontSet, 0, fontSet, 0, nGlyphs);
}
 
Example 48
Project: javify   File: FreetypeGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of a single glyph.
 */
public GlyphMetrics getGlyphMetrics(int glyphIndex)
{
  if( metricsCache == null )
    setupGlyphMetrics();

  return metricsCache[ glyphIndex ];
}
 
Example 49
Project: javify   File: GdkFontPeer.java   Source Code and License 5 votes vote down vote up
public GdkFontPeer (String name, int style, int size)
{
  super(name, style, size);
  initState ();
  setFont (this.familyName, this.style, (int)this.size);
  metricsCache = new HashMap<Integer,GlyphMetrics>();
  setupMetrics();
}
 
Example 50
Project: javify   File: GdkFontPeer.java   Source Code and License 5 votes vote down vote up
public GdkFontPeer (String name, Map attributes)
{
  super(name, attributes);
  initState ();
  setFont (this.familyName, this.style, (int)this.size);
  metricsCache = new HashMap<Integer,GlyphMetrics>();
  setupMetrics();
}
 
Example 51
Project: jvm-stm   File: FreetypeGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Cloning constructor
 */  
private FreetypeGlyphVector( FreetypeGlyphVector gv )
{
  font = gv.font;
  peer = gv.peer;
  frc = gv.frc;
  s = gv.s;
  nGlyphs = gv.nGlyphs;
  logicalBounds = gv.logicalBounds.getBounds2D();

  if( gv.metricsCache != null )
    {
      metricsCache = new GlyphMetrics[ nGlyphs ];
      System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
    }

  glyphCodes = new int[ nGlyphs ];
  fontSet = new long[nGlyphs];
  glyphPositions = new float[(nGlyphs + 1) * 2];
  glyphTransforms = new AffineTransform[ nGlyphs ];
  Arrays.fill(glyphTransforms, null);
  
  for(int i = 0; i < nGlyphs; i++ )
    {
      if (gv.glyphTransforms[i] != null)
        glyphTransforms[ i ] = new AffineTransform(gv.glyphTransforms[i]);
      glyphCodes[i] = gv.glyphCodes[ i ];
    }
  System.arraycopy(gv.glyphPositions, 0, glyphPositions, 0,
                   glyphPositions.length);
  System.arraycopy(gv.glyphCodes, 0, glyphCodes, 0, nGlyphs);
  System.arraycopy(gv.fontSet, 0, fontSet, 0, nGlyphs);
}
 
Example 52
Project: jvm-stm   File: FreetypeGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of a single glyph.
 */
public GlyphMetrics getGlyphMetrics(int glyphIndex)
{
  if( metricsCache == null )
    setupGlyphMetrics();

  return metricsCache[ glyphIndex ];
}
 
Example 53
Project: jvm-stm   File: GdkFontPeer.java   Source Code and License 5 votes vote down vote up
public GdkFontPeer (String name, int style, int size)
{  
  super(name, style, size);    
  initState ();
  setFont (this.familyName, this.style, (int)this.size);
  metricsCache = new HashMap<Integer,GlyphMetrics>();
  setupMetrics();
}
 
Example 54
Project: jvm-stm   File: GdkFontPeer.java   Source Code and License 5 votes vote down vote up
public GdkFontPeer (String name, Map attributes)
{
  super(name, attributes);
  initState ();
  setFont (this.familyName, this.style, (int)this.size);
  metricsCache = new HashMap<Integer,GlyphMetrics>();
  setupMetrics();
}
 
Example 55
Project: code404   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Create a new glyph
 * 
 * @param codePoint The code point in which this glyph can be found
 * @param bounds The bounds that this glrph can fill
 * @param vector The vector this glyph is part of
 * @param index The index of this glyph within the vector
 * @param unicodeFont The font this glyph forms part of
 */
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
Example 56
Project: Push2Display   File: AWTGVTGlyphVector.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of the glyph at the specified index into this
 * GVTGlyphVector.
 */
public GVTGlyphMetrics getGlyphMetrics(int glyphIndex) {
    if (glyphMetrics[glyphIndex] != null)
        return glyphMetrics[glyphIndex];

    // -- start glyph cache code --
    Point2D glyphPos = defaultGlyphPositions[glyphIndex];
    char c = ci.setIndex(ci.getBeginIndex()+glyphIndex);
    ci.setIndex(ci.getBeginIndex());
    AWTGlyphGeometryCache.Value v = AWTGVTFont.getGlyphGeometry
        (gvtFont, c, awtGlyphVector, glyphIndex, glyphPos);
    Rectangle2D gmB = v.getBounds2D();
    // -- end glyph cache code --

    Rectangle2D bounds = new Rectangle2D.Double
        (gmB.getX()     * scaleFactor, gmB.getY()      * scaleFactor,
         gmB.getWidth() * scaleFactor, gmB.getHeight() * scaleFactor);

    // defaultGlyphPositions has one more entry than glyphs
    // the last entry stores the total advance for the
    // glyphVector.
    float adv = (float)(defaultGlyphPositions[glyphIndex+1].getX()-
                        defaultGlyphPositions[glyphIndex]  .getX());
    glyphMetrics[glyphIndex] =  new GVTGlyphMetrics
        ((float)(adv*scaleFactor), (ascent+descent),
         bounds, GlyphMetrics.STANDARD);

    return glyphMetrics[glyphIndex];
}
 
Example 57
Project: Push2Display   File: AWTGVTFont.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the geometry of the specified character. This method also put
 * the in cache the geometry associated to the specified character if
 * needed.
 */
public static
    AWTGlyphGeometryCache.Value getGlyphGeometry(AWTGVTFont font,
                                                 char c,
                                                 GlyphVector gv,
                                                 int glyphIndex,
                                                 Point2D glyphPos) {

    AWTGlyphGeometryCache glyphCache =
        (AWTGlyphGeometryCache)fontCache.get(font.awtFont);

    AWTGlyphGeometryCache.Value v = glyphCache.get(c);
    if (v == null) {
        Shape outline = gv.getGlyphOutline(glyphIndex);
        GlyphMetrics metrics = gv.getGlyphMetrics(glyphIndex);
        Rectangle2D gmB = metrics.getBounds2D();
        if (AWTGVTGlyphVector.outlinesPositioned()) {
            AffineTransform tr = AffineTransform.getTranslateInstance
                (-glyphPos.getX(), -glyphPos.getY());
            outline = tr.createTransformedShape(outline);
        }
        v = new AWTGlyphGeometryCache.Value(outline, gmB);
        //System.out.println("put "+font.awtFont+" "+c);
        glyphCache.put(c, v);
    }
    return v;
}
 
Example 58
Project: Push2Display   File: Glyph.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the metrics of this Glyph if it is used in a horizontal layout.
 *
 * @return The glyph metrics.
 */
public GVTGlyphMetrics getGlyphMetrics() {
    if (metrics == null) {
        Rectangle2D gb = getGeometryBounds();

        metrics = new GVTGlyphMetrics
            (getHorizAdvX(), getVertAdvY(),
             new Rectangle2D.Double(gb.getX()-position.getX(),
                                    gb.getY()-position.getY(),
                                    gb.getWidth(),gb.getHeight()),
             GlyphMetrics.COMPONENT);
    }
    return metrics;
}
 
Example 59
Project: infobip-open-jdk-8   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
Example 60
Project: jdk8u-dev-jdk   File: TextMeasureTests.java   Source Code and License 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}