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