private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
public boolean process(GlyphVector glyphVector, int g, AffineTransform tx, char c) { Rectangle2D labelEnvelope = tx.createTransformedShape(glyphVector.getGlyphLogicalBounds(g)).getBounds2D(); // try to paint the label, the condition under which this happens are complex // white space character does not conflict with other labels if (Character.isWhitespace(c)) return false; else if ((displayArea.contains(labelEnvelope) || labelItem.isPartialsEnabled()) && !(labelItem.isConflictResolutionEnabled() && paintedBounds.labelsWithinDistance(labelEnvelope, extraSpace)) && !groupLabels.labelsWithinDistance(labelEnvelope, minDistance)) return false; else return true; // collision = true } }
@Override public Shape getGlyphLogicalBounds(int arg0) { return this.vec.getGlyphLogicalBounds(arg0); }
@Override public Bounds getCharacterBounds(int offset) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); return new Bounds((int)Math.floor(glyphBounds2D.getX()), 0, (int)Math.ceil(glyphBounds2D.getWidth()), getHeight()); }
@Override public Bounds getCharacterBounds(int offset) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(offset); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); return new Bounds((int)Math.floor(glyphBounds2D.getX()), 0, (int)Math.ceil(glyphBounds2D.getWidth()), getHeight()); }
@Override public int getNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction) { int offset = -1; if (from == -1) { int n = glyphVector.getNumGlyphs(); int i = 0; while (i < n) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); float glyphX = (float)glyphBounds2D.getX(); float glyphWidth = (float)glyphBounds2D.getWidth(); if (x >= glyphX && x < glyphX + glyphWidth) { if (x - glyphX > glyphWidth / 2 && i < n - 1) { // The x position falls within the right half of the character; // select the next character i++; } offset = i; break; } i++; } } return offset; }
@Override public int getNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction) { int offset = -1; if (from == -1) { int n = glyphVector.getNumGlyphs(); int i = 0; while (i < n) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); float glyphX = (float)glyphBounds2D.getX(); float glyphWidth = (float)glyphBounds2D.getWidth(); if (x >= glyphX && x < glyphX + glyphWidth) { if (x - glyphX > glyphWidth / 2 && i < n - 1) { // The x position falls within the right half of the character; // select the next character i++; } offset = i; break; } i++; } } return offset; }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
/** * Initialise the font to be used based on configuration * * @param baseFont The AWT font to render * @param size The point size of the font to generated * @param bold True if the font should be rendered in bold typeface * @param italic True if the font should be rendered in bold typeface */ private void initializeFont(Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField( "KERNING_ON").get(null)); } catch (Exception ignored) { } font = baseFont.deriveFont(attributes); FontMetrics metrics = GlyphPage.getScratchGraphics().getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
Shape glyphBounds = row.glyphVector.getGlyphLogicalBounds(index); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
Shape glyphBounds = row.glyphVector.getGlyphLogicalBounds(index); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
@Override public int getInsertionPoint(int x, int y) { FontRenderContext fontRenderContext = Platform.getFontRenderContext(); LineMetrics lm = getEffectiveFont().getLineMetrics("", fontRenderContext); float ascent = lm.getAscent(); int n = glyphVector.getNumGlyphs(); int i = 0; while (i < n) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i); if (glyphBounds.contains(x, y - ascent)) { Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); if (x - glyphBounds2D.getX() > glyphBounds2D.getWidth() / 2 && i < n - 1) { // The user clicked on the right half of the character; select // the next character i++; } break; } i++; } return i; }
@Override public int getInsertionPoint(int x, int y) { FontRenderContext fontRenderContext = Platform.getFontRenderContext(); LineMetrics lm = getEffectiveFont().getLineMetrics("", fontRenderContext); float ascent = lm.getAscent(); int n = glyphVector.getNumGlyphs(); int i = 0; while (i < n) { Shape glyphBounds = glyphVector.getGlyphLogicalBounds(i); if (glyphBounds.contains(x, y - ascent)) { Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); if (x - glyphBounds2D.getX() > glyphBounds2D.getWidth() / 2 && i < n - 1) { // The user clicked on the right half of the character; select // the next character i++; } break; } i++; } return i; }
public Bounds getCharacterBounds(int index) { Bounds characterBounds = null; CharSequence characters = paragraph.getCharacters(); int characterCount = characters.length(); int rowIndex, x, width; if (index == characterCount) { // This is the terminator character rowIndex = rows.getLength() - 1; Row row = rows.get(rowIndex); Rectangle2D glyphVectorBounds = row.glyphVector.getLogicalBounds(); x = (int)Math.floor(glyphVectorBounds.getWidth()); width = PARAGRAPH_TERMINATOR_WIDTH; } else { // This is a visible character rowIndex = getRowAt(index); Row row = rows.get(rowIndex); Shape glyphBounds = row.glyphVector.getGlyphLogicalBounds(index - row.offset); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); x = (int)Math.floor(glyphBounds2D.getX()); width = (int)Math.ceil(glyphBounds2D.getWidth()); } Font font = textAreaSkin.getFont(); FontRenderContext fontRenderContext = Platform.getFontRenderContext(); LineMetrics lm = font.getLineMetrics("", fontRenderContext); float rowHeight = lm.getAscent() + lm.getDescent(); characterBounds = new Bounds(x, (int)Math.floor(rowIndex * rowHeight), width, (int)Math.ceil(rowHeight)); return characterBounds; }
public Bounds getCharacterBounds(int index) { Bounds characterBounds = null; CharSequence characters = paragraph.getCharacters(); int characterCount = characters.length(); int rowIndex, xLocal, widthLocal; if (index == characterCount) { // This is the terminator character rowIndex = rows.getLength() - 1; Row row = rows.get(rowIndex); Rectangle2D glyphVectorBounds = row.glyphVector.getLogicalBounds(); xLocal = (int)Math.floor(glyphVectorBounds.getWidth()); widthLocal = PARAGRAPH_TERMINATOR_WIDTH; } else { // This is a visible character rowIndex = getRowAt(index); Row row = rows.get(rowIndex); Shape glyphBounds = row.glyphVector.getGlyphLogicalBounds(index - row.offset); Rectangle2D glyphBounds2D = glyphBounds.getBounds2D(); xLocal = (int)Math.floor(glyphBounds2D.getX()); widthLocal = (int)Math.ceil(glyphBounds2D.getWidth()); } Font font = textAreaSkin.getFont(); FontRenderContext fontRenderContext = Platform.getFontRenderContext(); LineMetrics lm = font.getLineMetrics("", fontRenderContext); float rowHeight = lm.getAscent() + lm.getDescent(); characterBounds = new Bounds(xLocal, (int)Math.floor(rowIndex * rowHeight), widthLocal, (int)Math.ceil(rowHeight)); return characterBounds; }
glyphGraphics.drawString(chrd, 0, fontMetrics.getHeight() - fontMetrics.getDescent()); Rectangle2D bounds = glyphVector.getGlyphLogicalBounds(0).getBounds();
Shape logicalBounds = curGVector.getGlyphLogicalBounds(i); Shape visualBounds = curGVector.getGlyphVisualBounds(i); outline = matrix.createTransformedShape(outline);
glyphList.add(qlyph); qlyph.glyphShape = shape; mxRectangle size = new mxRectangle(gv.getGlyphLogicalBounds(j).getBounds2D()); qlyph.labelGlyphBounds = size; labelSize += size.getWidth();
glyphList.add(qlyph); qlyph.glyphShape = shape; mxRectangle size = new mxRectangle(gv.getGlyphLogicalBounds(j).getBounds2D()); qlyph.labelGlyphBounds = size; labelSize += size.getWidth();