/** * Create a new GraphicComponent. start and limit are indices * into charLtoV and levels. charsLtoV and levels may be adopted. */ public GraphicComponent(GraphicAttribute graphic, Decoration decorator, int[] charsLtoV, byte[] levels, int start, int limit, AffineTransform baseTx) { if (limit <= start) { throw new IllegalArgumentException("0 or negative length in GraphicComponent"); } this.graphic = graphic; this.graphicAdvance = graphic.getAdvance(); this.decorator = decorator; this.cm = createCoreMetrics(graphic); this.baseTx = baseTx; initLocalOrdering(charsLtoV, levels, start, limit); }
/** * Constructs BasicMetrics from GraphicAttribute. * It gets ascent and descent from the graphic attribute and * computes reasonable defaults for other metrics. * @param ga - graphic attribute */ BasicMetrics(GraphicAttribute ga) { ascent = ga.getAscent(); descent = ga.getDescent(); leading = 2; baseLineIndex = ga.getAlignment(); italicAngle = 0; superScriptOffset = 0; underlineOffset = Math.max(descent/2, 1); // Just suggested, should be cap_stem_width or something like that underlineThickness = Math.max(ascent/13, 1); strikethroughOffset = -ascent/2; // Something like middle of the line strikethroughThickness = underlineThickness; }
public static AttributedString textIconReplace(final String text) { final String compacted = text.replaceAll("\\{[^}]+}", "M"); final AttributedString attrString = new AttributedString(compacted); for (int i = 0, j = 0; i < text.length(); i++, j++) { char c = text.charAt(i); if (c == '{') { final int endSymbol = text.indexOf('}', i); // get mana-string, substring returns at -1 value String iconString = text.substring(i, endSymbol + 1); // get related Icon as Image Image iconImage = MagicImages.getIcon(iconString).getImage(); // define replacement icon ImageGraphicAttribute icon = new ImageGraphicAttribute(iconImage, GraphicAttribute.BOTTOM_ALIGNMENT); // replace M with icon attrString.addAttribute( TextAttribute.CHAR_REPLACEMENT, icon, j, j + 1 ); // advance i to the end of symbol i = endSymbol; } } return attrString; }
public static CoreMetrics createCoreMetrics(GraphicAttribute graphic) { return new CoreMetrics(graphic.getAscent(), graphic.getDescent(), GRAPHIC_LEADING, graphic.getAscent() + graphic.getDescent() + GRAPHIC_LEADING, graphic.getAlignment(), new float[] { 0, -graphic.getAscent() / 2, -graphic.getAscent() }, -graphic.getAscent() / 2, graphic.getAscent() / 12, graphic.getDescent() / 3, graphic.getAscent() / 12, 0, // ss offset 0); // italic angle -- need api for this }
public final float effectiveBaselineOffset(float[] fullOffsets) { switch (baselineIndex) { case GraphicAttribute.TOP_ALIGNMENT: return fullOffsets[4] + ascent; case GraphicAttribute.BOTTOM_ALIGNMENT: return fullOffsets[3] - descent; default: return fullOffsets[baselineIndex]; } }
public float effectiveBaselineOffset(float[] fullOffsets) { switch (baselineIndex) { case GraphicAttribute.TOP_ALIGNMENT: return fullOffsets[4] + ascent; case GraphicAttribute.BOTTOM_ALIGNMENT: return fullOffsets[3] - descent; default: return fullOffsets[baselineIndex]; } }
/** * Returns either values cached by checkBaselines method or reasonable * values for the TOP and BOTTOM alignments. * @param baselineIndex - baseline index * @return baseline offset */ float getBaselineOffset(int baselineIndex) { if (baselineIndex >= 0) { return baselineOffsets[baselineIndex]; } else if (baselineIndex == GraphicAttribute.BOTTOM_ALIGNMENT) { return descent; } else if (baselineIndex == GraphicAttribute.TOP_ALIGNMENT) { return -ascent; } else { // awt.3F=Invalid baseline index throw new IllegalArgumentException(Messages.getString("awt.3F")); //$NON-NLS-1$ } }