diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-09-23 07:23:33 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-09-23 12:28:49 +0200 |
commit | 2e2765ec4ab05ee4745125f56b907f74e7426eaf (patch) | |
tree | cc04047caf672e26484a53f6b0cf26ea296156f8 | |
parent | 77cce80bb56801acf22da2149bd597d0d7793e3b (diff) |
vcl: Use glyph names from the font in Type 3 fonts
Some PDF viewers might use glyph names to guess corresponding character,
and it also makes debugging the PDF output a little bit easier.
Change-Id: Ibe7f28d10814a9deb467129c85fed914fb7b3f9f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140465
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/inc/font/PhysicalFontFace.hxx | 2 | ||||
-rw-r--r-- | vcl/source/font/PhysicalFontFace.cxx | 19 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 6 |
3 files changed, 25 insertions, 2 deletions
diff --git a/vcl/inc/font/PhysicalFontFace.hxx b/vcl/inc/font/PhysicalFontFace.hxx index 3297feff87dc..3d7fa0cba71d 100644 --- a/vcl/inc/font/PhysicalFontFace.hxx +++ b/vcl/inc/font/PhysicalFontFace.hxx @@ -180,6 +180,8 @@ public: bool HasColorBitmaps() const; RawFontData GetGlyphColorBitmap(sal_GlyphId, tools::Rectangle&) const; + OString GetGlyphName(sal_GlyphId, bool = false) const; + uint32_t UnitsPerEm() const { return hb_face_get_upem(GetHbFace()); } OUString GetName(NameID, const LanguageTag&) const; diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx index 337995964389..70738bbad06b 100644 --- a/vcl/source/font/PhysicalFontFace.cxx +++ b/vcl/source/font/PhysicalFontFace.cxx @@ -399,6 +399,25 @@ RawFontData PhysicalFontFace::GetGlyphColorBitmap(sal_GlyphId nGlyphIndex, return aData; } +OString PhysicalFontFace::GetGlyphName(sal_GlyphId nGlyphIndex, bool bValidate) const +{ + char aBuffer[256]; + hb_font_glyph_to_string(GetHbUnscaledFont(), nGlyphIndex, aBuffer, 256); + if (bValidate) + { + // https://learn.microsoft.com/en-us/typography/opentype/spec/post#version-20 + // Valid characters are limited to A–Z, a–z, 0–9, “.” (FULL STOP), and “_” (LOW LINE). + const char* p = aBuffer; + while ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') + || *p == '.' || *p == '_') + ++p; + if (*p != '\0') + return "g" + OString::number(nGlyphIndex); + } + + return OString(aBuffer); +} + OUString PhysicalFontFace::GetName(NameID aNameID, const LanguageTag& rLanguageTag) const { auto pHbFace = GetHbFace(); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 83887db1a4dc..a381d9287c4e 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -2500,7 +2500,9 @@ bool PDFWriterImpl::emitType3Font(const vcl::font::PhysicalFontFace* pFace, for (auto i = 1u; i < nGlyphs; i++) { auto nStream = createObject(); - aLine.append("/g" + OString::number(i) + " "); + aLine.append("/"); + aLine.append(pFace->GetGlyphName(pGlyphIds[i], true)); + aLine.append(" "); aLine.append(nStream); aLine.append(" 0 R\n"); pGlyphStreams[i] = nStream; @@ -2509,7 +2511,7 @@ bool PDFWriterImpl::emitType3Font(const vcl::font::PhysicalFontFace* pFace, aLine.append("/Encoding<</Type/Encoding/Differences[1"); for (auto i = 1u; i < nGlyphs; i++) - aLine.append(" /g" + OString::number(i)); + aLine.append(" /" + pFace->GetGlyphName(pGlyphIds[i], true)); aLine.append("]>>\n"); aLine.append("/FirstChar 0\n" |