KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pdf_outline_font.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <map>
24#include <memory>
25#include <string>
26#include <vector>
27
28#include <wx/string.h>
29
30#include <font/outline_font.h>
31
33
35{
36 uint16_t cid;
37 double xAdvance;
38 double yAdvance;
39 double xOffset;
40 double yOffset;
41};
42
44{
46 std::string m_bytes;
47 std::vector<PDF_OUTLINE_FONT_GLYPH> m_glyphs;
48};
49
51{
52public:
53 PDF_OUTLINE_FONT_SUBSET( KIFONT::OUTLINE_FONT* aFont, unsigned aSubsetIndex );
54
55 uint16_t EnsureGlyph( uint32_t aGlyphIndex, const std::u32string& aUnicode );
56
57 bool HasGlyphs() const;
58
59 const std::string& ResourceName() const { return m_resourceName; }
60 const std::string& BaseFontName() const { return m_baseFontName; }
61
62 const std::vector<double>& Widths() const { return m_widths; }
63 const std::vector<uint16_t>& CIDToGID() const { return m_cidToGid; }
64 const std::vector<std::u32string>& CIDToUnicode() const { return m_cidToUnicode; }
65
66 double UnitsPerEm() const { return m_unitsPerEm; }
67 double Ascent() const { return m_ascent; }
68 double Descent() const { return m_descent; }
69 double CapHeight() const { return m_capHeight; }
70 double ItalicAngle() const { return m_italicAngle; }
71 double StemV() const { return m_stemV; }
72 double BBoxMinX() const { return m_bboxMinX; }
73 double BBoxMinY() const { return m_bboxMinY; }
74 double BBoxMaxX() const { return m_bboxMaxX; }
75 double BBoxMaxY() const { return m_bboxMaxY; }
76 int Flags() const { return m_flags; }
77
78 const std::vector<uint8_t>& FontFileData();
79
80 std::string BuildWidthsArray() const;
81 std::string BuildToUnicodeCMap() const;
82 std::string BuildCIDToGIDStream() const;
83
84 void SetFontFileHandle( int aHandle ) { m_fontFileHandle = aHandle; }
85 int FontFileHandle() const { return m_fontFileHandle; }
86
87 void SetFontDescriptorHandle( int aHandle ) { m_fontDescriptorHandle = aHandle; }
89
90 void SetCIDFontHandle( int aHandle ) { m_cidFontHandle = aHandle; }
91 int CIDFontHandle() const { return m_cidFontHandle; }
92
93 void SetCIDMapHandle( int aHandle ) { m_cidMapHandle = aHandle; }
94 int CIDMapHandle() const { return m_cidMapHandle; }
95
96 void SetToUnicodeHandle( int aHandle ) { m_toUnicodeHandle = aHandle; }
97 int ToUnicodeHandle() const { return m_toUnicodeHandle; }
98
99 void SetFontHandle( int aHandle ) { m_fontHandle = aHandle; }
100 int FontHandle() const { return m_fontHandle; }
101
102 KIFONT::OUTLINE_FONT* Font() const { return m_font; }
103
104 void ForceSyntheticStyle( bool aBold, bool aItalic, double aItalicAngleDeg )
105 {
106 if( aBold )
107 m_flags |= 1; // force bold flag
108 if( aItalic )
109 m_flags |= 64; // force italic flag
110 if( aItalic )
111 m_italicAngle = aItalicAngleDeg; // negative for right-leaning
112 if( aBold && m_stemV < 140.0 )
113 m_stemV = 140.0; // boost stem weight heuristic
114 }
115
116private:
118 {
119 uint32_t m_glyphIndex;
120 std::u32string m_unicode;
121
122 bool operator<( const GLYPH_KEY& aOther ) const;
123 };
124
125 void ensureNotdef();
126
127 static std::string makeResourceName( unsigned aSubsetIndex );
128 static std::string makeSubsetName( KIFONT::OUTLINE_FONT* aFont, unsigned aSubsetIndex );
129 static std::string sanitizeFontName( const wxString& aName );
130
131private:
133 std::string m_resourceName;
134 std::string m_baseFontName;
135 std::vector<double> m_widths;
136 std::vector<uint16_t> m_cidToGid;
137 std::vector<std::u32string> m_cidToUnicode;
138 std::map<GLYPH_KEY, uint16_t> m_glyphMap;
140 double m_ascent;
141 double m_descent;
144 double m_stemV;
150 std::vector<uint8_t> m_fontData;
152 uint16_t m_nextCID;
153
160};
161
163{
164public:
166
167 void Reset();
168
169 void EncodeString( const wxString& aText, KIFONT::OUTLINE_FONT* aFont,
170 bool aItalicRequested, bool aBoldRequested,
171 std::vector<PDF_OUTLINE_FONT_RUN>* aRuns );
172
173 std::vector<PDF_OUTLINE_FONT_SUBSET*> AllSubsets() const;
174
175private:
176 PDF_OUTLINE_FONT_SUBSET* ensureSubset( KIFONT::OUTLINE_FONT* aFont, bool aItalic, bool aBold );
177
178private:
180 {
182 bool italic;
183 bool bold;
184 bool operator<( const SUBSET_KEY& o ) const
185 {
186 if( font < o.font ) return true;
187 if( font > o.font ) return false;
188 if( italic < o.italic ) return true;
189 if( italic > o.italic ) return false;
190 return bold < o.bold;
191 }
192 };
193
194 std::map<SUBSET_KEY, std::unique_ptr<PDF_OUTLINE_FONT_SUBSET>> m_subsets;
196};
Class OUTLINE_FONT implements outline font drawing.
std::map< SUBSET_KEY, std::unique_ptr< PDF_OUTLINE_FONT_SUBSET > > m_subsets
void EncodeString(const wxString &aText, KIFONT::OUTLINE_FONT *aFont, bool aItalicRequested, bool aBoldRequested, std::vector< PDF_OUTLINE_FONT_RUN > *aRuns)
PDF_OUTLINE_FONT_SUBSET * ensureSubset(KIFONT::OUTLINE_FONT *aFont, bool aItalic, bool aBold)
std::vector< PDF_OUTLINE_FONT_SUBSET * > AllSubsets() const
const std::string & ResourceName() const
std::vector< std::u32string > m_cidToUnicode
std::string BuildToUnicodeCMap() const
const std::string & BaseFontName() const
uint16_t EnsureGlyph(uint32_t aGlyphIndex, const std::u32string &aUnicode)
std::vector< double > m_widths
KIFONT::OUTLINE_FONT * m_font
std::vector< uint8_t > m_fontData
std::vector< uint16_t > m_cidToGid
void SetFontDescriptorHandle(int aHandle)
void SetFontHandle(int aHandle)
void SetCIDFontHandle(int aHandle)
static std::string makeSubsetName(KIFONT::OUTLINE_FONT *aFont, unsigned aSubsetIndex)
const std::vector< double > & Widths() const
static std::string sanitizeFontName(const wxString &aName)
const std::vector< uint8_t > & FontFileData()
PDF_OUTLINE_FONT_SUBSET(KIFONT::OUTLINE_FONT *aFont, unsigned aSubsetIndex)
const std::vector< std::u32string > & CIDToUnicode() const
std::string BuildWidthsArray() const
void SetFontFileHandle(int aHandle)
void SetCIDMapHandle(int aHandle)
KIFONT::OUTLINE_FONT * Font() const
void SetToUnicodeHandle(int aHandle)
static std::string makeResourceName(unsigned aSubsetIndex)
const std::vector< uint16_t > & CIDToGID() const
std::map< GLYPH_KEY, uint16_t > m_glyphMap
void ForceSyntheticStyle(bool aBold, bool aItalic, double aItalicAngleDeg)
std::string BuildCIDToGIDStream() const
bool operator<(const SUBSET_KEY &o) const
PDF_OUTLINE_FONT_SUBSET * m_subset
std::vector< PDF_OUTLINE_FONT_GLYPH > m_glyphs
bool operator<(const GLYPH_KEY &aOther) const