[
https://issues.apache.org/jira/browse/PDFBOX-6288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144891#comment-18144891
]
Tilman Hausherr edited comment on PDFBOX-6288 at 11/14/26, 4:32 PM:
--------------------------------------------------------------------
If it's identity and the font is not embedded and the OS font has the same name
(or mostly the same), then do CID = GID. My proposed change:
below String name = getBaseFont(); add this:
{code:java}
if (cid2gid == null && parent.getCMap() != null &&
"Identity".equals(parent.getCMap().getOrdering()) && name != null &&
fontNameEquals(name,ttf.getName()))
{
return codeToCID(code, parent);
}
{code}
and this:
{code:java}
private boolean fontNameEquals(String name, String ttfName)
{
// should be cached
if (name.equals(ttfName))
{
return true;
}
if (ttfName.startsWith(name) || name.startsWith(ttfName)) // e.g.
Arial/ArialMT, Tahoma,Italic/Tahoma
{
return true;
}
if ("Tahoma,Bold".equals(name) && "Tahoma-Bold".equals(ttfName))
{
return true;
}
// maybe table or map
return false;
}
{code}
The fontNameEquals() result should be cached at some early moment.
No regressions. (The tika regression test wasn't done)
was (Author: tilman):
If it's identity and the font is not embedded and the OS font has the same name
(or mostly the same), then do CID = GID. My proposed change:
below String name = getBaseFont(); add this:
{code:java}
if (cid2gid == null && parent.getCMap() != null &&
"Identity".equals(parent.getCMap().getOrdering()) && name != null &&
fontNameEquals(name,ttf.getName()))
{
return codeToCID(code, parent);
}
{code}
and this:
{code:java}
private boolean fontNameEquals(String name, String ttfName)
{
// should be cached
if (name.equals(ttfName))
{
return true;
}
if (ttfName.startsWith(name) || name.startsWith(ttfName)) // e.g.
Arial/ArialMT, Tahoma,Italic/Tahoma
{
return true;
}
if ("Tahoma,Bold".equals(name) && "Tahoma-Bold".equals(ttfName))
{
return true;
}
// maybe table or map
return false;
}
{code}
The fontNameEquals() result should be cached at some early moment.
No regressions.
> Invalid ToUnicode CMap
> ----------------------
>
> Key: PDFBOX-6288
> URL: https://issues.apache.org/jira/browse/PDFBOX-6288
> Project: PDFBox
> Issue Type: Bug
> Reporter: Oliver Schmidtmer
> Priority: Major
> Attachments: MalformedToUnicodeCMap.pdf,
> image-2026-11-12-12-51-25-119.png, image-2026-11-12-12-53-07-456.png,
> image-2026-11-12-12-55-54-029.png, toUnicode-CMAP.patch
>
>
> A problematic PDF file contains a "ToUnicode CMap" that uses "begincidrange"
> instead of "beginbfchar" or "beginbfrange".
> Since the CMap is ignored in this case, the wrong glyphs are used during
> rendering. Because the file displays correctly in Acrobat, a workaround might
> be justified.
> The attached PDF file is a generated example, as the original contains
> sensitive data. I used Copilot for the analysis and to create a potential
> patch:
> https://github.com/Schmidor/pdfbox/commit/425e83caaa28c66e6e4438c7818f0eb0a448fae9
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]