/** * Combine pitch and family to native id * * @see <a href="https://msdn.microsoft.com/en-us/library/dd145037.aspx">LOGFONT structure</a> * * @param pitch The pitch-value, cannot be null * @param family The family-value, cannot be null * * @return The resulting combined byte-value with pitch and family encoded into one byte */ public static byte getNativeId(FontPitch pitch, FontFamily family) { return (byte)(pitch.getNativeId() | (family.getFlag() << 4)); }
/** * Get FontPitch from native id * * @param pitchAndFamily The combined byte value for pitch and family * * @return The resulting FontPitch enumeration value */ public static FontPitch valueOfPitchFamily(byte pitchAndFamily) { return valueOf(pitchAndFamily & 0x3); } }
@Override public void setFamily(FontFamily family) { CTTextFont tf = getXmlObject(true); if (tf == null || (family == null && !tf.isSetPitchFamily())) { return; } FontPitch pitch = (tf.isSetPitchFamily()) ? FontPitch.valueOfPitchFamily(tf.getPitchFamily()) : FontPitch.VARIABLE; byte pitchFamily = FontPitch.getNativeId(pitch, family != null ? family : FontFamily.FF_SWISS); tf.setPitchFamily(pitchFamily); }
@Override public FontPitch getPitch() { CTTextFont tf = getXmlObject(false); return (tf != null && tf.isSetPitchFamily()) ? FontPitch.valueOfPitchFamily(tf.getPitchFamily()) : null; }
public static FontPitch valueOf(int flag) { for (FontPitch fp : values()) { if (fp.nativeId == flag) return fp; } return null; }
@Override public FontPitch getPitch() { CTTextFont tf = getXmlObject(false); return (tf != null && tf.isSetPitchFamily()) ? FontPitch.valueOfPitchFamily(tf.getPitchFamily()) : null; }
public static FontPitch valueOf(int flag) { for (FontPitch fp : values()) { if (fp.nativeId == flag) return fp; } return null; }
@Override public byte getPitchAndFamily(){ FontGroup fg = FontGroup.getFontGroupFirst(getRawText()); XSLFFontInfo fontInfo = new XSLFFontInfo(fg); FontPitch pitch = fontInfo.getPitch(); if (pitch == null) { pitch = FontPitch.VARIABLE; } FontFamily family = fontInfo.getFamily(); if (family == null) { family = FontFamily.FF_SWISS; } return FontPitch.getNativeId(pitch, family); }
@Override public void setFamily(FontFamily family) { CTTextFont tf = getXmlObject(true); if (tf == null || (family == null && !tf.isSetPitchFamily())) { return; } FontPitch pitch = (tf.isSetPitchFamily()) ? FontPitch.valueOfPitchFamily(tf.getPitchFamily()) : FontPitch.VARIABLE; byte pitchFamily = FontPitch.getNativeId(pitch, family != null ? family : FontFamily.FF_SWISS); tf.setPitchFamily(pitchFamily); }
/** * Creates a new instance of HSLFFontInfo and initialize it from the supplied font atom */ public HSLFFontInfo(FontEntityAtom fontAtom){ setIndex(fontAtom.getFontIndex()); setTypeface(fontAtom.getFontName()); setCharset(FontCharset.valueOf(fontAtom.getCharSet())); // assumption: the render type is exclusive switch (FLAGS_RENDER_FONTTYPE.getValue(fontAtom.getFontType())) { case 1: setRenderType(FontRenderType.raster); break; case 2: setRenderType(FontRenderType.device); break; default: case 4: setRenderType(FontRenderType.truetype); break; } byte pitchAndFamily = (byte)fontAtom.getPitchAndFamily(); setPitch(FontPitch.valueOfPitchFamily(pitchAndFamily)); setFamily(FontFamily.valueOfPitchFamily(pitchAndFamily)); setEmbedSubsetted(FLAGS_EMBED_SUBSETTED.isSet(fontAtom.getFontFlags())); setFontSubstitutable(!FLAGS_NO_FONT_SUBSTITUTION.isSet(fontAtom.getFontType())); }
/** * Get FontPitch from native id * * @param pitchAndFamily The combined byte value for pitch and family * * @return The resulting FontPitch enumeration value */ public static FontPitch valueOfPitchFamily(byte pitchAndFamily) { return valueOf(pitchAndFamily & 0x3); } }
@Override public void setPitch(FontPitch pitch) { CTTextFont tf = getXmlObject(true); if (tf == null || (pitch == null && !tf.isSetPitchFamily())) { return; } FontFamily family = (tf.isSetPitchFamily()) ? FontFamily.valueOfPitchFamily(tf.getPitchFamily()) : FontFamily.FF_SWISS; byte pitchFamily = FontPitch.getNativeId(pitch != null ? pitch : FontPitch.VARIABLE, family); tf.setPitchFamily(pitchFamily); }
@Override public FontPitch getPitch() { return FontPitch.valueOf((pitchAndFamily >>> 6) & 3); }
/** * Combine pitch and family to native id * * @see <a href="https://msdn.microsoft.com/en-us/library/dd145037.aspx">LOGFONT structure</a> * * @param pitch The pitch-value, cannot be null * @param family The family-value, cannot be null * * @return The resulting combined byte-value with pitch and family encoded into one byte */ public static byte getNativeId(FontPitch pitch, FontFamily family) { return (byte)(pitch.getNativeId() | (family.getFlag() << 4)); }
@Override public byte getPitchAndFamily(){ FontGroup fg = FontGroup.getFontGroupFirst(getRawText()); XSLFFontInfo fontInfo = new XSLFFontInfo(fg); FontPitch pitch = fontInfo.getPitch(); if (pitch == null) { pitch = FontPitch.VARIABLE; } FontFamily family = fontInfo.getFamily(); if (family == null) { family = FontFamily.FF_SWISS; } return FontPitch.getNativeId(pitch, family); }
@Override public void setPitch(FontPitch pitch) { CTTextFont tf = getXmlObject(true); if (tf == null || (pitch == null && !tf.isSetPitchFamily())) { return; } FontFamily family = (tf.isSetPitchFamily()) ? FontFamily.valueOfPitchFamily(tf.getPitchFamily()) : FontFamily.FF_SWISS; byte pitchFamily = FontPitch.getNativeId(pitch != null ? pitch : FontPitch.VARIABLE, family); tf.setPitchFamily(pitchFamily); }
public FontEntityAtom createRecord() { FontEntityAtom fnt = new FontEntityAtom(); fnt.setFontIndex(getIndex() << 4); fnt.setFontName(getTypeface()); fnt.setCharSet(getCharset().getNativeId()); fnt.setFontFlags((byte)(isEmbedSubsetted() ? 1 : 0)); int typeFlag; switch (renderType) { case device: typeFlag = FLAGS_RENDER_FONTTYPE.setValue(0, 1); break; case raster: typeFlag = FLAGS_RENDER_FONTTYPE.setValue(0, 2); break; default: case truetype: typeFlag = FLAGS_RENDER_FONTTYPE.setValue(0, 4); break; } typeFlag = FLAGS_NO_FONT_SUBSTITUTION.setBoolean(typeFlag, isFontSubstitutable()); fnt.setFontType(typeFlag); fnt.setPitchAndFamily(FontPitch.getNativeId(pitch, family)); return fnt; } }