You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2016/05/19 18:37:12 UTC
[jira] [Resolved] (PDFBOX-3354) PDCIDFont.getAverageFontWidth
always returns 0
[ https://issues.apache.org/jira/browse/PDFBOX-3354?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tilman Hausherr resolved PDFBOX-3354.
-------------------------------------
Resolution: Fixed
Assignee: Tilman Hausherr
Fix Version/s: 2.1.0
2.0.2
After looking at the 1.8 sources (where the local variable exists too but is returned), I suspect it was missed in refactoring. Thanks for reporting this.
> PDCIDFont.getAverageFontWidth always returns 0
> ----------------------------------------------
>
> Key: PDFBOX-3354
> URL: https://issues.apache.org/jira/browse/PDFBOX-3354
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.1, 2.0.2, 2.1.0
> Reporter: Gabriel Carabas
> Assignee: Tilman Hausherr
> Priority: Minor
> Fix For: 2.0.2, 2.1.0
>
>
> *PDCIDFont.getAverageFontWidth* method is using the field *averageWidth* as a cache, but fails to update its contents. Instead all the calculations go into a local variable with identical name,
> {code:title=PDCIDFont.java|borderStyle=solid}
> public float getAverageFontWidth()
> {
> if (averageWidth == 0)
> {
> float totalWidths = 0.0f;
> float characterCount = 0.0f;
> if (widths != null)
> {
> characterCount = widths.size();
> Collection<Float> widthsValues = widths.values();
> for (Float width : widthsValues)
> {
> totalWidths += width;
> }
> }
> float averageWidth = totalWidths / characterCount;
> if (averageWidth <= 0 || Float.isNaN(averageWidth))
> {
> averageWidth = getDefaultWidth();
> }
> }
> return averageWidth;
> }
> {code}
> A potential fix is the removal of the local variable declaration.
> {quote}
> -float- averageWidth = totalWidths / characterCount;
> {quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org