7 #ifndef PDF_FONT_METRICS_H
8 #define PDF_FONT_METRICS_H
12 #include "PdfString.h"
13 #include "PdfCMapEncoding.h"
14 #include "PdfCIDToGIDMap.h"
16 FORWARD_DECLARE_FREETYPE();
36 friend class PdfFontMetricsBase;
37 friend class PdfFontMetricsFreetype;
45 static std::unique_ptr<const PdfFontMetrics>
Create(
const std::string_view& filepath,
unsigned faceIndex = 0);
47 static std::unique_ptr<const PdfFontMetrics> CreateFromBuffer(
const bufferview& buffer,
unsigned faceIndex = 0);
49 virtual unsigned GetGlyphCount()
const = 0;
56 double GetGlyphWidth(
unsigned gid)
const;
57 virtual bool TryGetGlyphWidth(
unsigned gid,
double& width)
const = 0;
67 virtual void SubstituteGIDs(std::vector<unsigned>& gids,
68 std::vector<unsigned char>& backwardMap)
const;
79 virtual bool TryGetGID(char32_t codePoint,
unsigned& gid)
const = 0;
112 bool HasFontFileData()
const;
127 virtual const PdfObject* GetFontFileObject()
const;
151 virtual std::string_view GetFontNameRaw()
const;
162 std::string_view GeFontFamilyNameSafe()
const;
169 virtual std::string_view GetPostScriptNameApprox()
const;
171 virtual PdfFontStretch GetFontStretch()
const = 0;
176 unsigned GetWeight()
const;
177 virtual int GetWeightRaw()
const = 0;
214 double GetLeading()
const;
215 virtual double GetLeadingRaw()
const = 0;
225 double GetXHeight()
const;
226 virtual double GetXHeightRaw()
const = 0;
235 double GetStemH()
const;
236 virtual double GetStemHRaw()
const = 0;
240 double GetAvgWidth()
const;
241 virtual double GetAvgWidthRaw()
const = 0;
245 double GetMaxWidth()
const;
246 virtual double GetMaxWidthRaw()
const = 0;
250 double GetDefaultWidth()
const;
251 virtual double GetDefaultWidthRaw()
const = 0;
260 virtual bool IsObjectLoaded()
const;
262 bool IsStandard14FontMetrics()
const;
264 virtual bool IsStandard14FontMetrics(PdfStandard14FontType& std14Font)
const;
268 virtual const Matrix2D& GetMatrix()
const;
272 bool IsType1Kind()
const;
276 bool IsTrueTypeKind()
const;
282 bool IsPdfSymbolic()
const;
288 bool IsPdfNonSymbolic()
const;
298 virtual std::unique_ptr<PdfCMapEncoding> CreateToUnicodeMap(
const PdfEncodingLimits& limitHints)
const;
305 PdfCIDToGIDMapConstPtr GetCIDToGIDMap()
const;
308 const std::string& GetFilePath()
const {
return m_FilePath; }
309 unsigned GetFaceIndex()
const {
return m_FaceIndex; }
319 virtual const PdfCIDToGIDMapConstPtr& getCIDToGIDMap()
const;
320 virtual bool getIsBoldHint()
const = 0;
321 virtual bool getIsItalicHint()
const = 0;
322 virtual const datahandle& GetFontFileDataHandle()
const = 0;
323 virtual FT_Face GetFaceHandle()
const = 0;
326 void initFamilyFontNameSafe();
334 std::string m_FilePath;
336 std::string m_FamilyFontNameSafe;
337 unsigned m_FaceIndex;
343 friend class PdfFontMetricsObject;
346 PdfFontMetricsBase();
349 ~PdfFontMetricsBase();
352 const datahandle& GetFontFileDataHandle() const override final;
353 FT_Face GetFaceHandle() const override final;
354 virtual
datahandle getFontFileDataHandle() const = 0;
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
This class assists PdfDocument with caching font information.
Definition: PdfFontManager.h:54
This is the main class to handle the Standard14 metric data.
Definition: PdfFontMetricsStandard14.h:23
This abstract class provides access to font metrics information.
Definition: PdfFontMetrics.h:33
virtual double GetItalicAngle() const =0
Get the italic angle of this font.
virtual unsigned GetFontFileLength3() const =0
Get /Length3 value for the font file, if available.
virtual double GetDescent() const =0
Get the descent of this font in PDF units for the current font size.
virtual double GetUnderlinePosition() const =0
Return the position of the underline for the current font size in PDF units.
virtual bool HasUnicodeMapping() const =0
Determines if the metrics has a valid Unicode code point to gid map.
virtual double GetStrikeThroughPosition() const =0
Return the position of the strikethrough for the current font size in PDF units.
virtual double GetAscent() const =0
Get the ascent of this font in PDF units for the current font size.
virtual double GetUnderlineThickness() const =0
Get the width of the underline for the current font size in PDF units.
virtual bool TryGetGID(char32_t codePoint, unsigned &gid) const =0
Try to retrieve the mapped gid from Unicode code point.
virtual unsigned GetFontFileLength2() const =0
Get /Length2 value for the font file, if available.
virtual std::string_view GetBaseFontName() const =0
Get a semantical base name for the font that can be used to compose the final name,...
virtual double GetLineSpacing() const =0
Retrieve the line spacing for this font.
virtual double GetCapHeight() const =0
The vertical coordinate of the top of flat capital letters, measured from the baseline.
virtual unsigned GetFontFileLength1() const =0
Get /Length1 value for the font file, if available.
virtual double GetStrikeThroughThickness() const =0
Get the width of the strikethrough for the current font size in PDF units.
virtual std::string_view GetFontName() const =0
Get the actual /FontName, eg.
virtual double GetStemV() const =0
The thickness, measured horizontally, of the dominant vertical stems of glyphs in the font.
virtual void GetBoundingBox(std::vector< double > &bbox) const =0
Create the bounding box vector in PDF units.
virtual std::string_view GetFontFamilyName() const =0
Get the actual /FontFamily, eg.
Before you can draw text on a PDF document, you have to create a font object first.
Definition: PdfFont.h:49
This class represents a PDF indirect Object in memory.
Definition: PdfObject.h:35
A const data provider that can hold a view to a static segments or a shared buffer.
Definition: basetypes.h:144
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition: basetypes.h:16
PdfFontFileType
Definition: PdfDeclarations.h:267
@ Create
Create a new file or truncate existing one for writing/reading.
cspan< char > bufferview
Convenient read-only char buffer span.
Definition: basetypes.h:19
std::shared_ptr< const PdfFontMetrics > PdfFontMetricsConstPtr
Convenience typedef for a const PdfEncoding shared ptr.
Definition: PdfFontMetrics.h:24
PdfFontStyle
Font style flags used during searches.
Definition: PdfDeclarations.h:281
PdfFontDescriptorFlags
Enum for the font descriptor flags.
Definition: PdfDeclarations.h:223
std::shared_ptr< const PdfEncodingMap > PdfEncodingMapConstPtr
Convenience typedef for a const /Encoding map entry shared ptr.
Definition: PdfEncodingMap.h:343