@Override public Font createAWTFont(Graphics2D graphics, FontInfo fontInfo, double fontSize, boolean bold, boolean italic) { int style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0); Font font = new Font(fontInfo.getTypeface(), style, 12); if (Font.DIALOG.equals(font.getFamily())) { // SansSerif is a better choice than Dialog font = new Font(Font.SANS_SERIF, style, 12); } return font.deriveFont((float)fontSize); }
public String mapFontCharset(Graphics2D graphics, FontInfo fontInfo, String text) { // TODO: find a real charset mapping solution instead of hard coding for Wingdings String attStr = text; if (fontInfo != null && "Wingdings".equalsIgnoreCase(fontInfo.getTypeface())) { // wingdings doesn't contain high-surrogates, so chars are ok boolean changed = false; char chrs[] = attStr.toCharArray(); for (int i=0; i<chrs.length; i++) { // only change valid chars if ((0x20 <= chrs[i] && chrs[i] <= 0x7f) || (0xa0 <= chrs[i] && chrs[i] <= 0xff)) { chrs[i] |= 0xf000; changed = true; } } if (changed) { attStr = new String(chrs); } } return attStr; }
private FontInfo getFontWithFallback(Graphics2D graphics, DrawableHint hint, FontInfo fontInfo) { @SuppressWarnings("unchecked") Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(hint); if (fontMap == null) { return fontInfo; } String f = (fontInfo != null) ? fontInfo.getTypeface() : null; String mappedTypeface = null; if (fontMap.containsKey(f)) { mappedTypeface = fontMap.get(f); } else if (fontMap.containsKey("*")) { mappedTypeface = fontMap.get("*"); } return (mappedTypeface != null) ? new DrawFontInfo(mappedTypeface) : fontInfo; } }
void copyFrom(FontInfo fontInfo) { CTTextFont tf = getXmlObject(true); if (tf == null) { return; } setTypeface(fontInfo.getTypeface()); setCharset(fontInfo.getCharset()); FontPitch pitch = fontInfo.getPitch(); FontFamily family = fontInfo.getFamily(); if (pitch == null && family == null) { if (tf.isSetPitchFamily()) { tf.unsetPitchFamily(); } } else { setPitch(pitch); setFamily(family); } }
str.addAttribute(TextAttribute.FAMILY, buFont.getTypeface()); str.addAttribute(TextAttribute.SIZE, fontSize);
@Override public Font createAWTFont(Graphics2D graphics, FontInfo fontInfo, double fontSize, boolean bold, boolean italic) { int style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0); Font font = new Font(fontInfo.getTypeface(), style, 12); if (Font.DIALOG.equals(font.getFamily())) { // SansSerif is a better choice than Dialog font = new Font(Font.SANS_SERIF, style, 12); } return font.deriveFont((float)fontSize); }
public String mapFontCharset(Graphics2D graphics, FontInfo fontInfo, String text) { // TODO: find a real charset mapping solution instead of hard coding for Wingdings String attStr = text; if (fontInfo != null && "Wingdings".equalsIgnoreCase(fontInfo.getTypeface())) { // wingdings doesn't contain high-surrogates, so chars are ok boolean changed = false; char chrs[] = attStr.toCharArray(); for (int i=0; i<chrs.length; i++) { // only change valid chars if ((0x20 <= chrs[i] && chrs[i] <= 0x7f) || (0xa0 <= chrs[i] && chrs[i] <= 0xff)) { chrs[i] |= 0xf000; changed = true; } } if (changed) { attStr = new String(chrs); } } return attStr; }
private FontInfo getFontWithFallback(Graphics2D graphics, DrawableHint hint, FontInfo fontInfo) { @SuppressWarnings("unchecked") Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(hint); if (fontMap == null) { return fontInfo; } String f = (fontInfo != null) ? fontInfo.getTypeface() : null; String mappedTypeface = null; if (fontMap.containsKey(f)) { mappedTypeface = fontMap.get(f); } else if (fontMap.containsKey("*")) { mappedTypeface = fontMap.get("*"); } return (mappedTypeface != null) ? new DrawFontInfo(mappedTypeface) : fontInfo; } }
@Override public String getDefaultFontFamily() { FontInfo fontInfo = null; if (!_runs.isEmpty()) { HSLFTextRun tr = _runs.get(0); fontInfo = tr.getFontInfo(null); // fallback to LATIN if the font for the font group wasn't defined if (fontInfo == null) { fontInfo = tr.getFontInfo(FontGroup.LATIN); } } if (fontInfo == null) { fontInfo = HSLFFontInfoPredefined.ARIAL; } return fontInfo.getTypeface(); }
/** * Add font with the given FontInfo configuration to the font collection. * The returned FontInfo contains the HSLF specific details and the collection * uniquely contains fonts based on their typeface, i.e. calling the method with FontInfo * objects having the same name results in the same HSLFFontInfo reference. * * @param fontInfo the FontInfo configuration, can be a instance of {@link HSLFFontInfo}, * {@link HSLFFontInfoPredefined} or a custom implementation * @return the register HSLFFontInfo object */ public HSLFFontInfo addFont(FontInfo fontInfo) { HSLFFontInfo fi = getFontInfo(fontInfo.getTypeface()); if (fi != null) { return fi; } fi = new HSLFFontInfo(fontInfo); fi.setIndex(fonts.size()); fonts.put(fi.getTypeface(), fi); FontEntityAtom fnt = fi.createRecord(); // Append new child to the end appendChildRecord(fnt); // the added font is the last in the list return fi; }
void copyFrom(FontInfo fontInfo) { CTTextFont tf = getXmlObject(true); if (tf == null) { return; } setTypeface(fontInfo.getTypeface()); setCharset(fontInfo.getCharset()); FontPitch pitch = fontInfo.getPitch(); FontFamily family = fontInfo.getFamily(); if (pitch == null && family == null) { if (tf.isSetPitchFamily()) { tf.unsetPitchFamily(); } } else { setPitch(pitch); setFamily(family); } }
public HSLFFontInfo(FontInfo fontInfo) { // don't copy font index on copy constructor - it depends on the FontCollection this record is in setTypeface(fontInfo.getTypeface()); setCharset(fontInfo.getCharset()); setFamily(fontInfo.getFamily()); setPitch(fontInfo.getPitch()); if (fontInfo instanceof HSLFFontInfo) { HSLFFontInfo hFontInfo = (HSLFFontInfo)fontInfo; setRenderType(hFontInfo.getRenderType()); setEmbedSubsetted(hFontInfo.isEmbedSubsetted()); setFontSubstitutable(hFontInfo.isFontSubstitutable()); } }
private void addAttributes(AttributedString as, HwmfFont font) { DrawFontManager fontHandler = DrawFactory.getInstance(graphicsCtx).getFontManager(graphicsCtx); FontInfo fontInfo = fontHandler.getMappedFont(graphicsCtx, font); as.addAttribute(TextAttribute.FAMILY, fontInfo.getTypeface()); as.addAttribute(TextAttribute.SIZE, getFontHeight(font)); as.addAttribute(TextAttribute.STRIKETHROUGH, font.isStrikeOut()); if (font.isUnderline()) { as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); } if (font.isItalic()) { as.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); } as.addAttribute(TextAttribute.WEIGHT, font.getWeight()); }
str.addAttribute(TextAttribute.FAMILY, buFont.getTypeface()); str.addAttribute(TextAttribute.SIZE, fontSize);