[
https://issues.apache.org/jira/browse/PDFBOX-2784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Hewson resolved PDFBOX-2784.
---------------------------------
Resolution: Won't Fix
{quote}
First, in org.apache.fontbox.afm.CharMetric, a new ArrayList object is created
and assigned to the instance field "ligatures" upon creation of an instance.
During execution, elements are added into the array, but the ArrayList itself
is never read from. In fact, the getter for the field "ligatures" is never
invoked in the rest of the code. It seems like this ArrayList object is useless
since its data is never actually used. I removed this field and other
corresponding methods to avoid creating a useless object.
{quote}
FontBox is a standalone library which exposes APIs for downstream users who
want to work with fonts, or in this case AFM files. While PDFBox itself doesn't
make use of the ligatures API, it's a necessary part of having a comprehensive
font library. This functionality is far from "useless" and removing it from
FontBox is not what we're after.
{quote}
Second, in the same AFMParser class, a new BoundingBox object is created and
stored in the field "boundingBox" in an instance of CharMetirc. I looked at the
code and found out that the purpose of creating this object is merely for
calculating the height of the bounding box, as seen in
org.apache.fontbox.afm.FontMetrics. To avoid creating the object, I introduced
a field "boundingBoxHeight" in class CharMetric to store the information
instead of storing the BoundingBox object. I also introduced getter and setter
functions for this new field. I then modified the code in FontMetrics to invoke
this new getter for the height value. I found a similar "boundingBox" field in
org.apache.fontbox.ttf.GlyphData with the same characteristics (only being used
for its height) and added a function to obtain the BoundingBox's height.
Similary, I modified code in org.apache.pdfbox.pdmodel.font.PDTrueTypeFont to
use this height getter instead of getting the BoundingBox instance.
{quote}
Again, the purpose here is to provide an API for working with fonts. While
PDFBox itself doesn't make full use of BoundingBox metrics (mostly due to
widths being embedded in PDF files separately), a BoundingBox is a crucial
glyph metric and a necessary part of our font APIs for downstream consumers of
FontBox.
I think you've missed that FontBox is a standalone library, with it's own
public API separate from PDFBox. What you're suggesting is breaking changes to
the public API which would remove functionality. Thanks for taking the time to
create this issue and send us your code, but it's not something we're after.
> Removing unnecessary object creation
> ------------------------------------
>
> Key: PDFBOX-2784
> URL: https://issues.apache.org/jira/browse/PDFBOX-2784
> Project: PDFBox
> Issue Type: Improvement
> Components: FontBox, PDModel
> Affects Versions: 2.0.0
> Environment: Ubuntu
> Reporter: August Shi
> Priority: Minor
> Fix For: 2.0.0
>
> Attachments: AFMParser.java, CharMetric.java, FontMetrics.java,
> GlyphData.java, PDTrueTypeFont.java
>
>
> I discovered several performance inefficiencies in the current version of the
> code. I found these after using PDFReader to open a 10-page PDF and clicking
> all the menu items.
> First, in org.apache.fontbox.afm.CharMetric, a new ArrayList object is
> created and assigned to the instance field "ligatures" upon creation of an
> instance. During execution, elements are added into the array, but the
> ArrayList itself is never read from. In fact, the getter for the field
> "ligatures" is never invoked in the rest of the code. It seems like this
> ArrayList object is useless since its data is never actually used. I removed
> this field and other corresponding methods to avoid creating a useless
> object. I also removed calls to add elements to the "ligatures" field found
> in org.apache.fontbox.afm.AFMParser.
> Second, in the same AFMParser class, a new BoundingBox object is created and
> stored in the field "boundingBox" in an instance of CharMetirc. I looked at
> the code and found out that the purpose of creating this object is merely
> for calculating the height of the bounding box, as seen in
> org.apache.fontbox.afm.FontMetrics. To avoid creating the object, I
> introduced a field "boundingBoxHeight" in class CharMetric to store the
> information instead of storing the BoundingBox object. I also introduced
> getter and setter functions for this new field. I then modified the code in
> FontMetrics to invoke this new getter for the height value. I found a similar
> "boundingBox" field in org.apache.fontbox.ttf.GlyphData with the same
> characteristics (only being used for its height) and added a function to
> obtain the BoundingBox's height. Similary, I modified code in
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont to use this height getter
> instead of getting the BoundingBox instance.
> I will attach all the files that I changed.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]