KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pdf_stroke_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 2
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/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <map>
27#include <memory>
28#include <string>
29#include <vector>
30
31#include <wx/string.h>
32
33#include <font/stroke_font.h>
34
36
38{
40 std::string m_bytes;
41 bool m_bold = false;
42 bool m_italic = false;
43};
44
46{
47public:
48 struct GLYPH
49 {
50 wxUniChar m_unicode;
51 int m_code;
53 std::string m_name;
54 std::string m_stream;
55 double m_width;
56 double m_minX;
57 double m_minY;
58 double m_maxX;
59 double m_maxY;
61 };
62
63public:
64 PDF_STROKE_FONT_SUBSET( const KIFONT::STROKE_FONT* aFont, double aUnitsPerEm,
65 unsigned aSubsetIndex, bool aBold, bool aItalic );
66
67 bool Contains( wxUniChar aCode ) const;
68
69 int EnsureGlyph( wxUniChar aCode );
70
71 int CodeForGlyph( wxUniChar aCode ) const;
72
73 bool IsFull() const;
74
75 int GlyphCount() const;
76
77 int FirstChar() const;
78
79 int LastChar() const;
80
81 double UnitsPerEm() const { return m_unitsPerEm; }
82
83 double FontBBoxMinX() const { return m_bboxMinX; }
84 double FontBBoxMinY() const { return m_bboxMinY; }
85 double FontBBoxMaxX() const { return m_bboxMaxX; }
86 double FontBBoxMaxY() const { return m_bboxMaxY; }
87
88 const std::string& ResourceName() const { return m_resourceName; }
89 const std::string& CMapName() const { return m_cmapName; }
90 bool IsBold() const { return m_isBold; }
91 bool IsItalic() const { return m_isItalic; }
92
93 std::vector<GLYPH>& Glyphs() { return m_glyphs; }
94 const std::vector<GLYPH>& Glyphs() const { return m_glyphs; }
95
96 const std::vector<double>& Widths() const { return m_widths; }
97
98 std::string BuildDifferencesArray() const;
99 std::string BuildWidthsArray() const;
100 std::string BuildToUnicodeCMap() const;
101
102 void SetCharProcsHandle( int aHandle ) { m_charProcsHandle = aHandle; }
103 int CharProcsHandle() const { return m_charProcsHandle; }
104
105 void SetFontHandle( int aHandle ) { m_fontHandle = aHandle; }
106 int FontHandle() const { return m_fontHandle; }
107
108 void SetToUnicodeHandle( int aHandle ) { m_toUnicodeHandle = aHandle; }
109 int ToUnicodeHandle() const { return m_toUnicodeHandle; }
110
111private:
112 int glyphIndexForUnicode( wxUniChar aCode ) const;
113
114 std::string makeGlyphName( int aCode ) const;
115
116 const GLYPH* glyphForCode( int aCode ) const;
117
118private:
121 std::string m_resourceName;
122 std::string m_cmapName;
123 std::map<wxUniChar, int> m_unicodeToCode;
124 std::vector<GLYPH> m_glyphs;
125 std::vector<double> m_widths;
137};
138
140{
141public:
143
144 void Reset();
145
146 void EncodeString( const wxString& aText, std::vector<PDF_STROKE_FONT_RUN>* aRuns,
147 bool aBold = false, bool aItalic = false );
148
149 // Collect all subsets including style-group (bold/italic) subsets. Returned pointers are
150 // owned by the manager; vector is a temporary snapshot.
151 std::vector<PDF_STROKE_FONT_SUBSET*> AllSubsets() const;
152
153private:
154 PDF_STROKE_FONT_SUBSET* ensureSubsetForGlyph( wxUniChar aCode, bool aBold, bool aItalic );
155
156 // style key packing: bit0 = bold, bit1 = italic
157 static unsigned styleKey( bool aBold, bool aItalic ) { return ( aBold ? 1u : 0u ) | ( aItalic ? 2u : 0u ); }
158
160 {
161 std::vector<std::unique_ptr<PDF_STROKE_FONT_SUBSET>> subsets; // may overflow 256 glyph limit
162 };
163
164 STYLE_GROUP& groupFor( bool aBold, bool aItalic );
165
166private:
167 std::unique_ptr<KIFONT::STROKE_FONT> m_font;
169 unsigned m_nextSubsetIndex; // global counter for unique resource names
170 std::map<unsigned, STYLE_GROUP> m_styleGroups; // all style groups including default
171};
172
Implement a stroke font drawing.
Definition stroke_font.h:54
std::unique_ptr< KIFONT::STROKE_FONT > m_font
std::map< unsigned, STYLE_GROUP > m_styleGroups
STYLE_GROUP & groupFor(bool aBold, bool aItalic)
PDF_STROKE_FONT_SUBSET * ensureSubsetForGlyph(wxUniChar aCode, bool aBold, bool aItalic)
std::vector< PDF_STROKE_FONT_SUBSET * > AllSubsets() const
void EncodeString(const wxString &aText, std::vector< PDF_STROKE_FONT_RUN > *aRuns, bool aBold=false, bool aItalic=false)
static unsigned styleKey(bool aBold, bool aItalic)
const std::string & ResourceName() const
const std::vector< GLYPH > & Glyphs() const
std::string BuildDifferencesArray() const
double FontBBoxMaxY() const
double FontBBoxMinY() const
const KIFONT::STROKE_FONT * m_font
int EnsureGlyph(wxUniChar aCode)
double UnitsPerEm() const
double FontBBoxMinX() const
int CodeForGlyph(wxUniChar aCode) const
void SetToUnicodeHandle(int aHandle)
std::string BuildWidthsArray() const
double FontBBoxMaxX() const
std::map< wxUniChar, int > m_unicodeToCode
std::string makeGlyphName(int aCode) const
void SetFontHandle(int aHandle)
void SetCharProcsHandle(int aHandle)
std::vector< double > m_widths
const std::vector< double > & Widths() const
std::string BuildToUnicodeCMap() const
bool Contains(wxUniChar aCode) const
std::vector< GLYPH > m_glyphs
const std::string & CMapName() const
const GLYPH * glyphForCode(int aCode) const
PDF_STROKE_FONT_SUBSET(const KIFONT::STROKE_FONT *aFont, double aUnitsPerEm, unsigned aSubsetIndex, bool aBold, bool aItalic)
std::vector< GLYPH > & Glyphs()
int glyphIndexForUnicode(wxUniChar aCode) const
std::vector< std::unique_ptr< PDF_STROKE_FONT_SUBSET > > subsets
PDF_STROKE_FONT_SUBSET * m_subset