org.apache.fontbox.ttf.OS2WindowsMetricsTable Java Examples
The following examples show how to use
org.apache.fontbox.ttf.OS2WindowsMetricsTable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrueTypeEmbedder.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Returns true if the fsType in the OS/2 table permits embedding. */ private boolean isEmbeddingPermitted(TrueTypeFont ttf) throws IOException { if (ttf.getOS2Windows() != null) { int fsType = ttf.getOS2Windows().getFsType(); int exclusive = fsType & 0x8; // bits 0-3 are a set of exclusive bits if ((exclusive & OS2WindowsMetricsTable.FSTYPE_RESTRICTED) == OS2WindowsMetricsTable.FSTYPE_RESTRICTED) { // restricted License embedding return false; } else if ((exclusive & OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY) == OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY) { // bitmap embedding only return false; } } return true; }
Example #2
Source File: FontUtils.java From sambox with Apache License 2.0 | 6 votes |
/** * @return true if the fsType in the OS/2 table permits embedding. */ public static boolean isEmbeddingPermitted(TrueTypeFont ttf) throws IOException { if (ttf.getOS2Windows() != null) { int fsType = ttf.getOS2Windows().getFsType(); int exclusive = fsType & 0x8; // bits 0-3 are a set of exclusive bits if ((exclusive & OS2WindowsMetricsTable.FSTYPE_RESTRICTED) == OS2WindowsMetricsTable.FSTYPE_RESTRICTED) { // restricted License embedding return false; } else if ((exclusive & OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY) == OS2WindowsMetricsTable.FSTYPE_BITMAP_ONLY) { // bitmap embedding only return false; } } return true; }
Example #3
Source File: TrueTypeEmbedder.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Returns true if the fsType in the OS/2 table permits subsetting. */ private boolean isSubsettingPermitted(TrueTypeFont ttf) throws IOException { if (ttf.getOS2Windows() != null) { int fsType = ttf.getOS2Windows().getFsType(); if ((fsType & OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING) == OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING) { return false; } } return true; }
Example #4
Source File: FontUtils.java From sambox with Apache License 2.0 | 5 votes |
/** * @return true if the fsType in the OS/2 table permits subsetting. */ public static boolean isSubsettingPermitted(TrueTypeFont ttf) throws IOException { if (ttf.getOS2Windows() != null) { int fsType = ttf.getOS2Windows().getFsType(); if ((fsType & OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING) == OS2WindowsMetricsTable.FSTYPE_NO_SUBSETTING) { return false; } } return true; }
Example #5
Source File: TrueTypeEmbedder.java From gcs with Mozilla Public License 2.0 | 4 votes |
/** * Creates a new font descriptor dictionary for the given TTF. */ private PDFontDescriptor createFontDescriptor(TrueTypeFont ttf) throws IOException { PDFontDescriptor fd = new PDFontDescriptor(); fd.setFontName(ttf.getName()); OS2WindowsMetricsTable os2 = ttf.getOS2Windows(); PostScriptTable post = ttf.getPostScript(); // Flags fd.setFixedPitch(post.getIsFixedPitch() > 0 || ttf.getHorizontalHeader().getNumberOfHMetrics() == 1); int fsSelection = os2.getFsSelection(); fd.setItalic(((fsSelection & (ITALIC | OBLIQUE)) != 0)); switch (os2.getFamilyClass()) { case OS2WindowsMetricsTable.FAMILY_CLASS_CLAREDON_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_FREEFORM_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_MODERN_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_OLDSTYLE_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_SLAB_SERIFS: fd.setSerif(true); break; case OS2WindowsMetricsTable.FAMILY_CLASS_SCRIPTS: fd.setScript(true); break; default: break; } fd.setFontWeight(os2.getWeightClass()); fd.setSymbolic(true); fd.setNonSymbolic(false); // ItalicAngle fd.setItalicAngle(post.getItalicAngle()); // FontBBox HeaderTable header = ttf.getHeader(); PDRectangle rect = new PDRectangle(); float scaling = 1000f / header.getUnitsPerEm(); rect.setLowerLeftX(header.getXMin() * scaling); rect.setLowerLeftY(header.getYMin() * scaling); rect.setUpperRightX(header.getXMax() * scaling); rect.setUpperRightY(header.getYMax() * scaling); fd.setFontBoundingBox(rect); // Ascent, Descent HorizontalHeaderTable hHeader = ttf.getHorizontalHeader(); fd.setAscent(hHeader.getAscender() * scaling); fd.setDescent(hHeader.getDescender() * scaling); // CapHeight, XHeight if (os2.getVersion() >= 1.2) { fd.setCapHeight(os2.getCapHeight() * scaling); fd.setXHeight(os2.getHeight() * scaling); } else { GeneralPath capHPath = ttf.getPath("H"); if (capHPath != null) { fd.setCapHeight(Math.round(capHPath.getBounds2D().getMaxY()) * scaling); } else { // estimate by summing the typographical +ve ascender and -ve descender fd.setCapHeight((os2.getTypoAscender() + os2.getTypoDescender()) * scaling); } GeneralPath xPath = ttf.getPath("x"); if (xPath != null) { fd.setXHeight(Math.round(xPath.getBounds2D().getMaxY()) * scaling); } else { // estimate by halving the typographical ascender fd.setXHeight(os2.getTypoAscender() / 2.0f * scaling); } } // StemV - there's no true TTF equivalent of this, so we estimate it fd.setStemV(fd.getFontBoundingBox().getWidth() * .13f); return fd; }
Example #6
Source File: TrueTypeEmbedder.java From sambox with Apache License 2.0 | 4 votes |
/** * Creates a new font descriptor dictionary for the given TTF. */ private PDFontDescriptor createFontDescriptor(TrueTypeFont ttf) throws IOException { PDFontDescriptor fd = new PDFontDescriptor(); fd.setFontName(ttf.getName()); OS2WindowsMetricsTable os2 = ttf.getOS2Windows(); PostScriptTable post = ttf.getPostScript(); // Flags fd.setFixedPitch( post.getIsFixedPitch() > 0 || ttf.getHorizontalHeader().getNumberOfHMetrics() == 1); int fsSelection = os2.getFsSelection(); fd.setItalic(((fsSelection & (ITALIC | OBLIQUE)) != 0)); switch (os2.getFamilyClass()) { case OS2WindowsMetricsTable.FAMILY_CLASS_CLAREDON_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_FREEFORM_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_MODERN_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_OLDSTYLE_SERIFS: case OS2WindowsMetricsTable.FAMILY_CLASS_SLAB_SERIFS: fd.setSerif(true); break; case OS2WindowsMetricsTable.FAMILY_CLASS_SCRIPTS: fd.setScript(true); break; default: break; } fd.setFontWeight(os2.getWeightClass()); fd.setSymbolic(true); fd.setNonSymbolic(false); // ItalicAngle fd.setItalicAngle(post.getItalicAngle()); // FontBBox HeaderTable header = ttf.getHeader(); PDRectangle rect = new PDRectangle(); float scaling = 1000f / header.getUnitsPerEm(); rect.setLowerLeftX(header.getXMin() * scaling); rect.setLowerLeftY(header.getYMin() * scaling); rect.setUpperRightX(header.getXMax() * scaling); rect.setUpperRightY(header.getYMax() * scaling); fd.setFontBoundingBox(rect); // Ascent, Descent HorizontalHeaderTable hHeader = ttf.getHorizontalHeader(); fd.setAscent(hHeader.getAscender() * scaling); fd.setDescent(hHeader.getDescender() * scaling); // CapHeight, XHeight if (os2.getVersion() >= 1.2) { fd.setCapHeight(os2.getCapHeight() * scaling); fd.setXHeight(os2.getHeight() * scaling); } else { GeneralPath capHPath = ttf.getPath("H"); if (capHPath != null) { fd.setCapHeight(Math.round(capHPath.getBounds2D().getMaxY()) * scaling); } else { // estimate by summing the typographical +ve ascender and -ve descender fd.setCapHeight((os2.getTypoAscender() + os2.getTypoDescender()) * scaling); } GeneralPath xPath = ttf.getPath("x"); if (xPath != null) { fd.setXHeight(Math.round(xPath.getBounds2D().getMaxY()) * scaling); } else { // estimate by halving the typographical ascender fd.setXHeight(os2.getTypoAscender() / 2.0f * scaling); } } // StemV - there's no true TTF equivalent of this, so we estimate it fd.setStemV(fd.getFontBoundingBox().getWidth() * .13f); return fd; }