privatestaticfinal FontRenderContext DEFAULT_FRC = new FontRenderContext(null, false, false);
public Font2DHandle handle; protected String familyName; /* Family font name (english) */ protected String fullName; /* Full font name (english) */ protectedint style = Font.PLAIN; protected FontFamily family; protectedint fontRank = DEFAULT_RANK;
/* Store the last Strike in a Reference object. *SimilarlytothestrikethatwasstoredonaC++fontobject, *thisisanoptimisationwhichhelpsifmultipleclients(ie *typicallySunGraphics2Dinstances)areusingthesamefont,then *asmaybetypicalofmanyUIs,theyareprobablyusingitinthe *samestyle,soitcanbeawintofirstquicklycheckifthelast *strikeobtainedfromthisFont2Dsatisfiestheneedsofthenext *clienttoo. *Thispre-supposesthataFontStrikeisashareableobject,which *itshould.
*/ protected Reference<FontStrike> lastFontStrike = new WeakReference<>(null);
/* Returns the "real" style of this Font2D. Eg the font face *LucidaSansBold"hasarealstyleofFont.BOLD,eventhough *itmaybeabletousedtosimulatebolditalic
*/ publicint getStyle() { return style;
} protectedvoid setStyle() {
String fName = fullName.toLowerCase();
for (int i=0; i < boldItalicNames.length; i++) { if (fName.contains(boldItalicNames[i])) {
style = Font.BOLD|Font.ITALIC; return;
}
}
for (int i=0; i < italicNames.length; i++) { if (fName.contains(italicNames[i])) {
style = Font.ITALIC; return;
}
}
for (int i=0; i < boldNames.length; i++) { if (fName.contains(boldNames[i])) {
style = Font.BOLD; return;
}
}
}
/* this may be useful for APIs like canDisplay where the answer *isdependentonthefontanditsscaler,butnotthestrike. *Ifnostrikehaseverbeenreturned,thencreateaonethatmatches *thisfontwiththedefaultFRC.ItwillbecomethelastStrikeand *there'sagoodchancethatthenextcallwillbetogetexactlythat *strike.
*/ public FontStrike getStrike(Font font) {
FontStrike strike = lastFontStrike.get(); if (strike != null) { return strike;
} else { return getStrike(font, DEFAULT_FRC);
}
}
/* SunGraphics2D has font, tx, aa and fm. From this info *cangetaStrikeobjectfromthecache,creatingitifnecessary. *Thiscodeisdesignedformulti-threadedaccess. *ForthatreasonitcreatesalocalFontStrikeDescratherthanfilling *inasharedone.UptotwoAffineTransformsandoneFontStrikeDescwill *becreatedbyeverylookup.Thisappearstoperformmorethan *adequately.ButitmaymakesensetoexposeFontStrikeDesc *asaparametersoacallercanuseitsown. *InsuchacaseifaFontStrikeDescisstoredasakeythen *wewouldneedtouseaprivatecopy. * *Notethatthiscodedoesn'tpreventtwothreadsfromcreating *twodifferentFontStrikeinstancesandhavingoneofthethreads *overwritetheotherinthemap.Thisislikelytobearare *occurrenceandtheonlyconsequenceisthatthesecallerswillhave *differentinstancesofthestrike,andthere'dbesomeduplicationof *populationofthestrikes.Howeversinceusersofthesestrikesare *transient,thentheonethatwasoverwrittenwouldsoonbefreed. *Ifthereisanyproblemthenasmallsynchronizedblockwouldbe *requiredwithitsattendantconsequencesforMPscalability.
*/ public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm) {
/* Create the descriptor which is used to identify a strike *inthestrikecache/map.Astrikeisfullydescribedby *theattributesofthisdescriptor.
*/ /* REMIND: generating garbage and doing computation here in order *toincludeptsizeinthetxjustforalookup!Figureouta *betterway.
*/ double ptSize = font.getSize2D();
AffineTransform glyphTx = (AffineTransform)devTx.clone();
glyphTx.scale(ptSize, ptSize); if (font.isTransformed()) {
glyphTx.concatenate(font.getTransform());
} if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
glyphTx.setTransform(glyphTx.getScaleX(),
glyphTx.getShearY(),
glyphTx.getShearX(),
glyphTx.getScaleY(), 0.0, 0.0);
}
FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
font.getStyle(), aa, fm); return getStrike(desc, false);
}
public FontStrike getStrike(Font font, AffineTransform devTx,
AffineTransform glyphTx, int aa, int fm) {
/* Create the descriptor which is used to identify a strike *inthestrikecache/map.Astrikeisfullydescribedby *theattributesofthisdescriptor.
*/
FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
font.getStyle(), aa, fm); return getStrike(desc, false);
}
public FontStrike getStrike(Font font, FontRenderContext frc) {
AffineTransform at = frc.getTransform(); double ptSize = font.getSize2D();
at.scale(ptSize, ptSize); if (font.isTransformed()) {
at.concatenate(font.getTransform()); if (at.getTranslateX() != 0 || at.getTranslateY() != 0) {
at.setTransform(at.getScaleX(),
at.getShearY(),
at.getShearX(),
at.getScaleY(), 0.0, 0.0);
}
} int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc); int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint());
FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(),
at, font.getStyle(),
aa, fm); return getStrike(desc, false);
}
void updateLastStrikeRef(FontStrike strike) {
lastFontStrike.clear(); if (useWeak) {
lastFontStrike = new WeakReference<>(strike);
} else {
lastFontStrike = new SoftReference<>(strike);
}
}
/* Currently the layout code calls this. May be better for layout code *tocheckthefontclassbeforeattemptingtorun,ratherthanneeding *topromotethismethodupfromTrueTypeFont
*/ protectedbyte[] getTableBytes(int tag) { returnnull;
}
/* Used only on OS X.
*/ protectedlong getPlatformNativeFontPtr() { return0L;
}
/* for layout code */ protectedlong getUnitsPerEm() { return2048;
}
publicbyte getBaselineFor(char c) { return Font.ROMAN_BASELINE;
}
publicfloat getItalicAngle(Font font, AffineTransform at,
Object aaHint, Object fmHint) { /* hardwire psz=12 as that's typical and AA vs non-AA for 'gasp' mode *isn'timportantforthecaretslopeofthisrarelyusedAPI.
*/ int aa = FontStrikeDesc.getAAHintIntVal(aaHint, this, 12); int fm = FontStrikeDesc.getFMHintIntVal(fmHint);
FontStrike strike = getStrike(font, at, aa, fm);
StrikeMetrics metrics = strike.getFontMetrics(); if (metrics.ascentY == 0 || metrics.ascentX == 0) { return0f;
} else { /* ascent is "up" from the baseline so its typically *anegativevalue,soweneedtocompensate
*/ return metrics.ascentX/-metrics.ascentY;
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.