[
https://issues.apache.org/jira/browse/PDFBOX-4909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17164200#comment-17164200
]
Tilman Hausherr edited comment on PDFBOX-4909 at 7/24/20, 7:17 AM:
-------------------------------------------------------------------
So I tried this: remove the "CapturingSetFontAndSize" change, and instead use
this code:
{noformat}
+ private final Map<COSDictionary, Float> fontHeightMap = new
WeakHashMap<>();
(...)
- float dyDisplay = currentFontHeight *
textRenderingMatrix.getScalingFactorY();
+ Float fontHeight = fontHeightMap.get(font.getCOSObject());
+ if (fontHeight == null)
+ {
+ fontHeight = computeFontHeight(font);
+ fontHeightMap.put(font.getCOSObject(), fontHeight);
+ }
+ float dyDisplay = fontHeight * textRenderingMatrix.getScalingFactorY();
{noformat}
[~Faltiska] how is this for speed on your machine?
was (Author: tilman):
So I tried this: remove the "CapturingSetFontAndSize" change, and instead use
this code:
{noformat}
+ private final WeakHashMap<COSDictionary, Float> fontHeightMap = new
WeakHashMap<>();
(...)
- float dyDisplay = currentFontHeight *
textRenderingMatrix.getScalingFactorY();
+ Float fontHeight = fontHeightMap.get(font.getCOSObject());
+ if (fontHeight == null)
+ {
+ fontHeight = computeFontHeight(font);
+ fontHeightMap.put(font.getCOSObject(), fontHeight);
+ }
+ float dyDisplay = fontHeight * textRenderingMatrix.getScalingFactorY();
{noformat}
[~Faltiska] how is this for speed on your machine?
> Don't calculate font height for every glyph
> -------------------------------------------
>
> Key: PDFBOX-4909
> URL: https://issues.apache.org/jira/browse/PDFBOX-4909
> Project: PDFBox
> Issue Type: Improvement
> Components: Text extraction
> Affects Versions: 2.0.0, 3.0.0 PDFBox
> Reporter: Alfred
> Assignee: Tilman Hausherr
> Priority: Major
> Labels: Optimization
> Fix For: 2.0.21, 3.0.0 PDFBox
>
> Attachments: PDFBOX-4909.patch
>
>
> LegacyPDFStreamEngine computes font height for every glyph and the
> computation is rather heavy, to work around all known problems.
> Instead of computing for every glyph, we can recompute only when the font
> changes. The SetFontAndSize operator will be invoked when the font changes so
> we can use that to compute and store the height to have it ready when needed
> in showGlyph.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]