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 <tuple>
26#include <vector>
27
28#include <wx/string.h>
29
30#include <font/stroke_font.h>
31
33
35{
37 std::string m_bytes;
38 bool m_bold = false;
39 bool m_italic = false;
40};
41
43{
44public:
45 struct GLYPH
46 {
47 wxUniChar m_unicode;
48 int m_code;
50 std::string m_name;
51 std::string m_stream;
52 double m_width;
53 double m_minX;
54 double m_minY;
55 double m_maxX;
56 double m_maxY;
58 };
59
60public:
61 PDF_STROKE_FONT_SUBSET( const KIFONT::STROKE_FONT* aFont, double aUnitsPerEm,
62 unsigned aSubsetIndex, bool aBold, bool aItalic,
63 double aStrokeWidthFactor, double aAspectRatio );
64
65 bool Contains( wxUniChar aCode ) const;
66
67 int EnsureGlyph( wxUniChar aCode );
68
69 int CodeForGlyph( wxUniChar aCode ) const;
70
71 bool IsFull() const;
72
73 int GlyphCount() const;
74
75 int FirstChar() const;
76
77 int LastChar() const;
78
79 double UnitsPerEm() const { return m_unitsPerEm; }
80
81 double FontBBoxMinX() const { return m_bboxMinX; }
82 double FontBBoxMinY() const { return m_bboxMinY; }
83 double FontBBoxMaxX() const { return m_bboxMaxX; }
84 double FontBBoxMaxY() const { return m_bboxMaxY; }
85
86 const std::string& ResourceName() const { return m_resourceName; }
87 const std::string& CMapName() const { return m_cmapName; }
88 bool IsBold() const { return m_isBold; }
89 bool IsItalic() const { return m_isItalic; }
90
91 std::vector<GLYPH>& Glyphs() { return m_glyphs; }
92 const std::vector<GLYPH>& Glyphs() const { return m_glyphs; }
93
94 const std::vector<double>& Widths() const { return m_widths; }
95
96 std::string BuildDifferencesArray() const;
97 std::string BuildWidthsArray() const;
98 std::string BuildToUnicodeCMap() const;
99
100 void SetCharProcsHandle( int aHandle ) { m_charProcsHandle = aHandle; }
101 int CharProcsHandle() const { return m_charProcsHandle; }
102
103 void SetFontHandle( int aHandle ) { m_fontHandle = aHandle; }
104 int FontHandle() const { return m_fontHandle; }
105
106 void SetToUnicodeHandle( int aHandle ) { m_toUnicodeHandle = aHandle; }
107 int ToUnicodeHandle() const { return m_toUnicodeHandle; }
108
109private:
110 int glyphIndexForUnicode( wxUniChar aCode ) const;
111
112 std::string makeGlyphName( int aCode ) const;
113
114 const GLYPH* glyphForCode( int aCode ) const;
115
116 std::string buildGlyphStream( const KIFONT::STROKE_GLYPH* aGlyph ) 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;
139};
140
142{
143public:
145
146 void Reset();
147
148 void EncodeString( const wxString& aText, std::vector<PDF_STROKE_FONT_RUN>* aRuns, int aStrokeWidth, int aFontWidth,
149 int aFontHeight, bool aBold = false, bool aItalic = false );
150
151 // Collect all subsets including style-group (bold/italic) subsets. Returned pointers are
152 // owned by the manager; vector is a temporary snapshot.
153 std::vector<PDF_STROKE_FONT_SUBSET*> AllSubsets() const;
154
155private:
156 PDF_STROKE_FONT_SUBSET* ensureSubsetForGlyph( wxUniChar aCode, int aStrokeWidth, int aFontWidth, int aFontHeight,
157 bool aBold, bool aItalic );
158
159 using STYLE_KEY = std::tuple<bool, bool, int, int, int>;
160
161 static STYLE_KEY styleKey( bool aBold, bool aItalic, int aStrokeWidth, int aFontWidth, int aFontHeight );
162
164 {
165 std::vector<std::unique_ptr<PDF_STROKE_FONT_SUBSET>> subsets; // may overflow 256 glyph limit
166 };
167
168private:
169 std::unique_ptr<KIFONT::STROKE_FONT> m_font;
171 unsigned m_nextSubsetIndex; // global counter for unique resource names
172 std::map<STYLE_KEY, STYLE_GROUP> m_styleGroups; // all style groups including default
173};
174
Implement a stroke font drawing.
Definition stroke_font.h:50
std::unique_ptr< KIFONT::STROKE_FONT > m_font
std::map< STYLE_KEY, STYLE_GROUP > m_styleGroups
void EncodeString(const wxString &aText, std::vector< PDF_STROKE_FONT_RUN > *aRuns, int aStrokeWidth, int aFontWidth, int aFontHeight, bool aBold=false, bool aItalic=false)
std::tuple< bool, bool, int, int, int > STYLE_KEY
PDF_STROKE_FONT_SUBSET * ensureSubsetForGlyph(wxUniChar aCode, int aStrokeWidth, int aFontWidth, int aFontHeight, bool aBold, bool aItalic)
std::vector< PDF_STROKE_FONT_SUBSET * > AllSubsets() const
static STYLE_KEY styleKey(bool aBold, bool aItalic, int aStrokeWidth, int aFontWidth, int aFontHeight)
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
PDF_STROKE_FONT_SUBSET(const KIFONT::STROKE_FONT *aFont, double aUnitsPerEm, unsigned aSubsetIndex, bool aBold, bool aItalic, double aStrokeWidthFactor, double aAspectRatio)
std::vector< GLYPH > m_glyphs
const std::string & CMapName() const
const GLYPH * glyphForCode(int aCode) const
std::vector< GLYPH > & Glyphs()
std::string buildGlyphStream(const KIFONT::STROKE_GLYPH *aGlyph) const
int glyphIndexForUnicode(wxUniChar aCode) const
std::vector< std::unique_ptr< PDF_STROKE_FONT_SUBSET > > subsets
PDF_STROKE_FONT_SUBSET * m_subset