@Override public void textFont(PFont which) { super.textFont(which); fillPaint.setTypeface((Typeface) which.getNative()); }
@Override protected float textWidthImpl(char buffer[], int start, int stop) { // Font font = textFont.getFont(); Typeface font = (Typeface) textFont.getNative(); if (font == null) { return super.textWidthImpl(buffer, start, stop); } // maybe should use one of the newer/fancier functions for this? int length = stop - start; // FontMetrics metrics = canvas.getFontMetrics(font); // return metrics.charsWidth(buffer, start, length); return fillPaint.measureText(buffer, start, length); }
@Override public float textAscent() { if (textFont == null) { defaultFontOrDeath("textAscent"); } Font font = (Font) textFont.getNative(); if (font != null) { //return getFontMetrics(font).getAscent(); return g2.getFontMetrics(font).getAscent(); } return super.textAscent(); }
@Override public float textDescent() { if (textFont == null) { defaultFontOrDeath("textDescent"); } Font font = (Font) textFont.getNative(); if (font != null) { //return getFontMetrics(font).getDescent(); return g2.getFontMetrics(font).getDescent(); } return super.textDescent(); }
@Override protected float textWidthImpl(char buffer[], int start, int stop) { Object font = textFont.getNative(); float twidth = 0; if (font != null) twidth = pgl.getTextWidth(font, buffer, start, stop); if (twidth == 0) twidth = super.textWidthImpl(buffer, start, stop); return twidth; }
@Override public float textAscent() { if (textFont == null) defaultFontOrDeath("textAscent"); Object font = textFont.getNative(); float ascent = 0; if (font != null) ascent = pgl.getFontAscent(font); if (ascent == 0) ascent = super.textAscent(); return ascent; }
Font font = (Font) textFont.getNative();
protected void handleTextSize(float size) { Font font = (Font) textFont.getNative();
@Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { Typeface font = (Typeface) textFont.getNative(); if (font == null) { showWarning("Inefficient font rendering: use createFont() with a TTF/OTF instead of loadFont().");
@Override public float textDescent() { if (textFont == null) defaultFontOrDeath("textDescent"); Object font = textFont.getNative(); float descent = 0; if (font != null) descent = pgl.getFontDescent(font); if (descent == 0) descent = super.textDescent(); return descent; }
@Override protected void handleTextSize(float size) { Object font = textFont.getNative(); if (font != null) { Object dfont = pgl.getDerivedFont(font, size); textFont.setNative(dfont); } super.handleTextSize(size); }
@Override protected float textWidthImpl(char buffer[], int start, int stop) { if (textFont == null) defaultFontOrDeath("textWidth"); Object font = textFont.getNative(); float twidth = 0; if (font != null) twidth = pgl.getTextWidth(font, buffer, start, stop); if (twidth == 0) twidth = super.textWidthImpl(buffer, start, stop); return twidth; }
@Override public float textAscent() { if (textFont == null) defaultFontOrDeath("textAscent"); Object font = textFont.getNative(); float ascent = 0; if (font != null) ascent = pgl.getFontAscent(font); if (ascent == 0) ascent = super.textAscent(); return ascent; }
@Override public float textDescent() { if (textFont == null) defaultFontOrDeath("textDescent"); Object font = textFont.getNative(); float descent = 0; if (font != null) descent = pgl.getFontDescent(font); if (descent == 0) descent = super.textDescent(); return descent; }
@Override protected void handleTextSize(float size) { Object font = textFont.getNative(); if (font != null) { Object dfont = pgl.getDerivedFont(font, size); textFont.setNative(dfont); } super.handleTextSize(size); }
/** * Same as parent, but override for native version of the font. * <p/> * Also gets called by textFont, so the metrics * will get recorded properly. */ @Override public void textSize(float size) { if (textFont == null) { defaultFontOrDeath("textSize", size); } Typeface font = (Typeface) textFont.getNative(); if (font != null) { fillPaint.setTextSize(size); } // take care of setting the textSize and textLeading vars // this has to happen second, because it calls textAscent() // (which requires the native font metrics to be set) textSize = size; // PApplet.println("P2D textSize textAscent -> " + textAscent()); // PApplet.println("P2D textSize textDescent -> " + textDescent()); textLeading = (textAscent() + textDescent()) * 1.275f; // PApplet.println("P2D textSize textLeading = " + textLeading); }
@Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { Font font = (Font) textFont.getNative();
if (font == null && which.getNative() != null) {
public PShape getShape(char ch, float detail) { Font font = (Font) getNative(); if (font == null) { throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
float x, float y) { if (textMode == SHAPE && textFont.getNative() == null) { showWarning("textMode(SHAPE) not available for .vlw fonts, " + "use an .otf or .ttf instead.");