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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#pragma once
24
25#include <cstdint>
26#include <map>
27#include <memory>
28#include <string>
29#include <vector>
30
31#include <wx/string.h>
32
33#include <font/outline_font.h>
34
36
38{
39 uint16_t cid;
40 double xAdvance;
41 double yAdvance;
42 double xOffset;
43 double yOffset;
44};
45
47{
49 std::string m_bytes;
50 std::vector<PDF_OUTLINE_FONT_GLYPH> m_glyphs;
51};
52
54{
55public:
56 PDF_OUTLINE_FONT_SUBSET( KIFONT::OUTLINE_FONT* aFont, unsigned aSubsetIndex );
57
58 uint16_t EnsureGlyph( uint32_t aGlyphIndex, const std::u32string& aUnicode );
59
60 bool HasGlyphs() const;
61
62 const std::string& ResourceName() const { return m_resourceName; }
63 const std::string& BaseFontName() const { return m_baseFontName; }
64
65 const std::vector<double>& Widths() const { return m_widths; }
66 const std::vector<uint16_t>& CIDToGID() const { return m_cidToGid; }
67 const std::vector<std::u32string>& CIDToUnicode() const { return m_cidToUnicode; }
68
69 double UnitsPerEm() const { return m_unitsPerEm; }
70 double Ascent() const { return m_ascent; }
71 double Descent() const { return m_descent; }
72 double CapHeight() const { return m_capHeight; }
73 double ItalicAngle() const { return m_italicAngle; }
74 double StemV() const { return m_stemV; }
75 double BBoxMinX() const { return m_bboxMinX; }
76 double BBoxMinY() const { return m_bboxMinY; }
77 double BBoxMaxX() const { return m_bboxMaxX; }
78 double BBoxMaxY() const { return m_bboxMaxY; }
79 int Flags() const { return m_flags; }
80
81 const std::vector<uint8_t>& FontFileData();
82
83 std::string BuildWidthsArray() const;
84 std::string BuildToUnicodeCMap() const;
85 std::string BuildCIDToGIDStream() const;
86
87 void SetFontFileHandle( int aHandle ) { m_fontFileHandle = aHandle; }
88 int FontFileHandle() const { return m_fontFileHandle; }
89
90 void SetFontDescriptorHandle( int aHandle ) { m_fontDescriptorHandle = aHandle; }
92
93 void SetCIDFontHandle( int aHandle ) { m_cidFontHandle = aHandle; }
94 int CIDFontHandle() const { return m_cidFontHandle; }
95
96 void SetCIDMapHandle( int aHandle ) { m_cidMapHandle = aHandle; }
97 int CIDMapHandle() const { return m_cidMapHandle; }
98
99 void SetToUnicodeHandle( int aHandle ) { m_toUnicodeHandle = aHandle; }
100 int ToUnicodeHandle() const { return m_toUnicodeHandle; }
101
102 void SetFontHandle( int aHandle ) { m_fontHandle = aHandle; }
103 int FontHandle() const { return m_fontHandle; }
104
105 KIFONT::OUTLINE_FONT* Font() const { return m_font; }
106
107 void ForceSyntheticStyle( bool aBold, bool aItalic, double aItalicAngleDeg )
108 {
109 if( aBold )
110 m_flags |= 1; // force bold flag
111 if( aItalic )
112 m_flags |= 64; // force italic flag
113 if( aItalic )
114 m_italicAngle = aItalicAngleDeg; // negative for right-leaning
115 if( aBold && m_stemV < 140.0 )
116 m_stemV = 140.0; // boost stem weight heuristic
117 }
118
119private:
121 {
122 uint32_t m_glyphIndex;
123 std::u32string m_unicode;
124
125 bool operator<( const GLYPH_KEY& aOther ) const;
126 };
127
128 void ensureNotdef();
129
130 static std::string makeResourceName( unsigned aSubsetIndex );
131 static std::string makeSubsetName( KIFONT::OUTLINE_FONT* aFont, unsigned aSubsetIndex );
132 static std::string sanitizeFontName( const wxString& aName );
133
134private:
136 std::string m_resourceName;
137 std::string m_baseFontName;
138 std::vector<double> m_widths;
139 std::vector<uint16_t> m_cidToGid;
140 std::vector<std::u32string> m_cidToUnicode;
141 std::map<GLYPH_KEY, uint16_t> m_glyphMap;
143 double m_ascent;
144 double m_descent;
147 double m_stemV;
153 std::vector<uint8_t> m_fontData;
155 uint16_t m_nextCID;
156
163};
164
166{
167public:
169
170 void Reset();
171
172 void EncodeString( const wxString& aText, KIFONT::OUTLINE_FONT* aFont,
173 bool aItalicRequested, bool aBoldRequested,
174 std::vector<PDF_OUTLINE_FONT_RUN>* aRuns );
175
176 std::vector<PDF_OUTLINE_FONT_SUBSET*> AllSubsets() const;
177
178private:
179 PDF_OUTLINE_FONT_SUBSET* ensureSubset( KIFONT::OUTLINE_FONT* aFont, bool aItalic, bool aBold );
180
181private:
183 {
185 bool italic;
186 bool bold;
187 bool operator<( const SUBSET_KEY& o ) const
188 {
189 if( font < o.font ) return true;
190 if( font > o.font ) return false;
191 if( italic < o.italic ) return true;
192 if( italic > o.italic ) return false;
193 return bold < o.bold;
194 }
195 };
196
197 std::map<SUBSET_KEY, std::unique_ptr<PDF_OUTLINE_FONT_SUBSET>> m_subsets;
199};
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