/** * Returns the glyph for the specified codePoint. If the glyph does not exist yet, * it is created and queued to be loaded. * * @param glyphCode The code of the glyph to locate * @param codePoint The code point associated with the glyph * @param bounds The bounds of the glyph on the page * @param vector The vector the glyph is part of * @param index The index of the glyph within the vector * @return The glyph requested */ private Glyph getGlyph (int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index) { if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) { // GlyphVector#getGlyphCode sometimes returns negative numbers on OS X. return new Glyph(codePoint, bounds, vector, index, this) { public boolean isMissing () { return true; } }; } int pageIndex = glyphCode / PAGE_SIZE; int glyphIndex = glyphCode & (PAGE_SIZE - 1); Glyph glyph = null; Glyph[] page = glyphs[pageIndex]; if (page != null) { glyph = page[glyphIndex]; if (glyph != null) return glyph; } else page = glyphs[pageIndex] = new Glyph[PAGE_SIZE]; // Add glyph so size information is available and queue it so its image can be loaded later. glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, this); queuedGlyphs.add(glyph); return glyph; }
/** * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph) */ public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { g = (Graphics2D)g.create(); g.translate(xDistance, yDistance); g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255))); g.fill(glyph.getShape()); // Also shadow the outline, if one exists. for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) { Effect effect = (Effect)iter.next(); if (effect instanceof OutlineEffect) { Composite composite = g.getComposite(); g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining. g.setStroke(((OutlineEffect)effect).getStroke()); g.draw(glyph.getShape()); g.setComposite(composite); break; } } g.dispose(); if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image); }
/** * Returns the glyph for the specified codePoint. If the glyph does not exist yet, * it is created and queued to be loaded. * * @param glyphCode The code of the glyph to locate * @param codePoint The code point associated with the glyph * @param bounds The bounds of the glyph on the page * @param vector The vector the glyph is part of * @param index The index of the glyph within the vector * @return The glyph requested */ private Glyph getGlyph (int glyphCode, int codePoint, @Nonnull Rectangle bounds, @Nonnull GlyphVector vector, int index) { if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) { // GlyphVector#getGlyphCode sometimes returns negative numbers on OS X. return new Glyph(codePoint, bounds, vector, index, this) { public boolean isMissing () { return true; } }; } int pageIndex = glyphCode / PAGE_SIZE; int glyphIndex = glyphCode & (PAGE_SIZE - 1); Glyph glyph; Glyph[] page = glyphs[pageIndex]; if (page != null) { glyph = page[glyphIndex]; if (glyph != null) return glyph; } else page = glyphs[pageIndex] = new Glyph[PAGE_SIZE]; // Add glyph so size information is available and queue it so its image can be loaded later. glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, this); queuedGlyphs.add(glyph); return glyph; }
/** * Returns the glyph for the specified codePoint. If the glyph does not exist yet, * it is created and queued to be loaded. * * @param glyphCode The code of the glyph to locate * @param codePoint The code point associated with the glyph * @param bounds The bounds of the glyph on the page * @param vector The vector the glyph is part of * @param index The index of the glyph within the vector * @param f The font to use * @return The glyph requested */ private Glyph getGlyph(int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont f) { if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) { // GlyphVector#getGlyphCode sometimes returns negative numbers on OS X. return new Glyph(codePoint, bounds, vector, index, this) { @Override public boolean isMissing () { return true; } }; } int pageIndex = glyphCode / PAGE_SIZE; int glyphIndex = glyphCode & (PAGE_SIZE - 1); Glyph glyph = null; Glyph[] page = glyphs[pageIndex]; if (page != null) { glyph = page[glyphIndex]; if (glyph != null) return glyph; } else page = glyphs[pageIndex] = new Glyph[PAGE_SIZE]; // Add glyph so size information is available and queue it so its image can be loaded later. glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, f); queuedGlyphs.add(glyph); return glyph; }
/** * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph) */ public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { int ascent = unicodeFont.getAscent(); float height = (ascent) * scale; float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2; g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic)); g.fill(glyph.getShape()); }
/** * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph) */ public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { g = (Graphics2D)g.create(); if (stroke != null) g.setStroke(stroke); else g.setStroke(getStroke()); g.setColor(color); g.draw(glyph.getShape()); g.dispose(); }
/** * Queues the backup glyphs in the specified text to be loaded. Note that * the glyphs are not actually loaded until {@link #loadGlyphs()} is called. * * @param text The text containing the glyphs to be added */ private void addBackupGlyphs(String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (backup == null) return; char[] chars = text.toCharArray(); GlyphVector vector = backup.getFont().layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) { int codePoint = text.codePointAt(vector.getGlyphCharIndex(i)); Rectangle bounds = getGlyphBounds(vector, i, codePoint); Glyph glyph = getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i, backup); } }
public int compare (Object o1, Object o2) { return ((Glyph)o1).getHeight() - ((Glyph)o2).getHeight(); }
/** * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph) */ public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { BufferedImage scratchImage = EffectUtil.getScratchImage(); filter.filter(image, scratchImage); image.getGraphics().drawImage(scratchImage, 0, 0, null); }
/** * @see org.newdawn.slick.font.effects.Effect#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, org.newdawn.slick.UnicodeFont, org.newdawn.slick.font.Glyph) */ public void draw(BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { g.setColor(color); g.fill(glyph.getShape()); }