[
https://issues.apache.org/jira/browse/PDFBOX-2012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13959681#comment-13959681
]
Philip Helger commented on PDFBOX-2012:
---------------------------------------
When working with TrueType font, always the WinAnsiEncoding is used, which
leads to a FirstChar of 32 and a LastChar of 2?? (<256)
With this methods I want to have an easy way to determine the min and max
character supported by this CMap table. There are other ways to determine it
(trial and error) but that would be very bogus. This issue is related to
PDFBOX-2013 where the respective CMAPEncodingEntry is made available in the
PDTrueTypeFont
> Extend CMAPEncodingEntry API
> ----------------------------
>
> Key: PDFBOX-2012
> URL: https://issues.apache.org/jira/browse/PDFBOX-2012
> Project: PDFBox
> Issue Type: Wish
> Components: FontBox
> Affects Versions: 1.8.4, 2.0.0
> Reporter: Philip Helger
>
> Please extend the API with the following 2 methods (incl. a minor performance
> improvement):
> ### Eclipse Workspace Patch 1.0
> #P fontbox
> Index: src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java
> ===================================================================
> --- src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java
> (revision 1583927)
> +++ src/main/java/org/apache/fontbox/ttf/CMAPEncodingEntry.java
> (working copy)
> @@ -436,7 +436,7 @@
> for (int i = 0; i < 256; i++)
> {
> subHeaderKeys[i] = data.readUnsignedShort();
> - maxSubHeaderIndex = Math.max(maxSubHeaderIndex, (int)
> (subHeaderKeys[i] / 8));
> + maxSubHeaderIndex = Math.max(maxSubHeaderIndex, subHeaderKeys[i]
> / 8);
> }
>
> // ---- Read all SubHeaders to avoid useless seek on DataSource
> @@ -556,18 +556,32 @@
> */
> public int getGlyphId(int characterCode)
> {
> - if (characterCodeToGlyphId.containsKey(characterCode))
> - {
> - return characterCodeToGlyphId.get(characterCode);
> - }
> - else
> - {
> - return 0;
> - }
> + Integer glyphId = characterCodeToGlyphId.get(characterCode);
> + return glyphId == null ? 0 : glyphId.intValue ();
> }
> +
> + /**
> + * Get the minimum character code for which a glyph id is present
> + *
> + * @return The minimum character code for which a glyph id is present or
> -1 if no character code is present.
> + */
> + public int getMinimumCharacterCode()
> + {
> + return characterCodeToGlyphId.isEmpty () ? -1 : Collections.min
> (characterCodeToGlyphId.keySet ()).intValue ();
> + }
>
> /**
> + * Get the maximum character code for which a glyph id is present
> *
> + * @return The maximum character code for which a glyph id is present or
> -1 if no character code is present.
> + */
> + public int getMaximumCharacterCode()
> + {
> + return characterCodeToGlyphId.isEmpty () ? -1 : Collections.max
> (characterCodeToGlyphId.keySet ()).intValue ();
> + }
> +
> + /**
> + *
> * Class used to manage CMap - Format 2.
> *
> */
--
This message was sent by Atlassian JIRA
(v6.2#6252)