Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_METRIC_HXX
21 : #define INCLUDED_VCL_METRIC_HXX
22 :
23 : #include <vcl/dllapi.h>
24 : #include <vcl/font.hxx>
25 : #include <vcl/outdev.hxx>
26 :
27 : #include <boost/intrusive_ptr.hpp>
28 :
29 : class ImplFontMetric;
30 : class ImplFontCharMap;
31 : class CmapResult;
32 :
33 : typedef sal_uInt32 sal_UCS4;
34 : typedef boost::intrusive_ptr< ImplFontCharMap > ImplFontCharMapPtr;
35 : typedef boost::intrusive_ptr< FontCharMap > FontCharMapPtr;
36 :
37 : namespace vcl {
38 :
39 : // avoid problems where poppler's FontInfo is picked up
40 : class VCL_DLLPUBLIC FontInfo : public vcl::Font
41 : {
42 : friend class ::OutputDevice;
43 :
44 : protected:
45 : ImplFontMetric* mpImplMetric; // Implementation
46 :
47 : public:
48 : FontInfo();
49 : FontInfo( const FontInfo& );
50 : ~FontInfo();
51 :
52 : FontType GetType() const;
53 :
54 : FontInfo& operator=( const FontInfo& );
55 : bool operator==( const FontInfo& ) const;
56 : bool operator!=( const FontInfo& rInfo ) const
57 : { return !operator==( rInfo ); }
58 : };
59 :
60 : }
61 :
62 : class VCL_DLLPUBLIC FontMetric : public vcl::FontInfo
63 : {
64 : public:
65 572171 : FontMetric() {}
66 : FontMetric( const FontMetric& );
67 572171 : ~FontMetric() {}
68 :
69 : long GetAscent() const;
70 : long GetDescent() const;
71 : long GetIntLeading() const;
72 : long GetExtLeading() const;
73 : long GetLineHeight() const;
74 : long GetSlant() const;
75 :
76 : FontMetric& operator=( const FontMetric& rMetric );
77 : bool operator==( const FontMetric& rMetric ) const;
78 : bool operator!=( const FontMetric& rMetric ) const
79 : { return !operator==( rMetric ); }
80 : };
81 :
82 : template< typename charT, typename traits >
83 : inline std::basic_ostream<charT, traits> & operator <<(
84 : std::basic_ostream<charT, traits> & stream, const FontMetric& rMetric )
85 : {
86 : stream << "{"
87 : << "name=" << "\"" << rMetric.GetName() << "\""
88 : << ",size=(" << rMetric.GetSize().Width() << "," << rMetric.GetSize().Height() << ")"
89 : << ",ascent=" << rMetric.GetAscent()
90 : << ",descent=" << rMetric.GetDescent()
91 : << ",intLeading=" << rMetric.GetIntLeading()
92 : << ",extLeading=" << rMetric.GetExtLeading()
93 : << ",lineHeight=" << rMetric.GetLineHeight()
94 : << ",slant=" << rMetric.GetSlant()
95 : << "}";
96 : return stream;
97 : }
98 :
99 : class VCL_DLLPUBLIC FontCharMap
100 : {
101 : public:
102 : /** A new FontCharMap is created based on a "default" map, which includes
103 : all codepoints in the Unicode BMP range, including surrogates.
104 : **/
105 : FontCharMap();
106 : FontCharMap( const CmapResult& rCR );
107 : ~FontCharMap();
108 :
109 : /** Get the default font character map
110 :
111 : @returns the default font character map.
112 : */
113 : static FontCharMapPtr GetDefaultMap( bool bSymbols=false );
114 :
115 : /** Determines if the font character map is the "default". The default map
116 : includes all codepoints in the Unicode BMP range, including surrogates.
117 :
118 : @returns true if default map, false if not default map.
119 : */
120 : bool IsDefaultMap() const;
121 :
122 : /** Does the font character map include the UCS4 character?
123 :
124 : @returns true if character exists in font character map, false is not.
125 : */
126 : bool HasChar( sal_UCS4 ) const;
127 :
128 : /** Returns the number of chars supported by the font, which
129 : are inside the unicode range from cMin to cMax (inclusive).
130 :
131 : @param cMin Lowest codepoint in range to be counted
132 : @param cMax Highest codepoitn in range to be counted
133 :
134 : @returns number of characters in the font charmap between the two
135 : codepoints.
136 : */
137 : int CountCharsInRange( sal_UCS4 cMin, sal_UCS4 cMax ) const;
138 :
139 : /** Get the number of characters in the font character map.
140 :
141 : @returns number of characters in the font character map.
142 : */
143 : int GetCharCount() const;
144 :
145 : /** Get the first character in the font character map.
146 :
147 : @returns first character in the font character map.
148 : */
149 : sal_UCS4 GetFirstChar() const;
150 :
151 : /** Get the last character in the font character map.
152 :
153 : @returns last character in the font character map.
154 : */
155 : sal_UCS4 GetLastChar() const;
156 :
157 : /** Get the next character in the font character map. This is important
158 : because character maps (e.g. the default map which holds the characters
159 : in the BMP plane) can have discontiguous ranges.
160 :
161 : @param cChar Character from which to find next character
162 :
163 : @returns next character in the font character map.
164 : */
165 : sal_UCS4 GetNextChar( sal_UCS4 cChar ) const;
166 :
167 : /** Get the previous character in the font character map. This is important
168 : because character maps (e.g. the default map which holds the characters
169 : in the BMP plane) can have discontiguous ranges.
170 :
171 : @param cChar Character from which to find previous character
172 :
173 : @returns previous character in the font character map.
174 : */
175 : sal_UCS4 GetPrevChar( sal_UCS4 cChar ) const;
176 :
177 : /** Get the index of a particular character in the font character map. The
178 : index is different from the codepoint, because font character maps can
179 :
180 : determine the index.
181 :
182 : @param cChar Character used to find index number
183 :
184 : @returns Index of character in font character map.
185 : */
186 : int GetIndexFromChar( sal_UCS4 cChar ) const;
187 :
188 : /** Get the character at a particular index in the font character map. The
189 : index is different from the codepoint, because font character maps can
190 :
191 : determine the character.
192 :
193 : @param nCharIndex Index used to find the character
194 :
195 : @returns Character in font character map.
196 : */
197 : sal_UCS4 GetCharFromIndex( int nCharIndex ) const;
198 :
199 : int GetGlyphIndex( sal_UCS4 ) const;
200 :
201 : private:
202 : ImplFontCharMapPtr mpImplFontCharMap;
203 :
204 : friend class ::OutputDevice;
205 : friend void intrusive_ptr_release(FontCharMap* pFontCharMap);
206 : friend void intrusive_ptr_add_ref(FontCharMap* pFontCharMap);
207 :
208 : int findRangeIndex( sal_uInt32 ) const;
209 :
210 : FontCharMap( ImplFontCharMapPtr pIFCMap );
211 :
212 : sal_uInt32 mnRefCount;
213 :
214 : // prevent assignment and copy construction
215 : FontCharMap( const FontCharMap& ) SAL_DELETED_FUNCTION;
216 : void operator=( const FontCharMap& ) SAL_DELETED_FUNCTION;
217 : };
218 :
219 38598 : inline void intrusive_ptr_add_ref(FontCharMap* pFontCharMap)
220 : {
221 38598 : ++pFontCharMap->mnRefCount;
222 38598 : }
223 :
224 38598 : inline void intrusive_ptr_release(FontCharMap* pFontCharMap)
225 : {
226 38598 : if (--pFontCharMap->mnRefCount == 0)
227 8522 : delete pFontCharMap;
228 38598 : }
229 :
230 : class VCL_DLLPUBLIC TextRectInfo
231 : {
232 : friend class ::OutputDevice;
233 :
234 : private:
235 : long mnMaxWidth;
236 : sal_uInt16 mnLineCount;
237 : bool mbEllipsis;
238 :
239 : public:
240 : TextRectInfo();
241 :
242 : sal_uInt16 GetLineCount() const { return mnLineCount; }
243 0 : long GetMaxLineWidth() const { return mnMaxWidth; }
244 0 : bool IsEllipses() const { return mbEllipsis; }
245 :
246 : bool operator ==( const TextRectInfo& rInfo ) const
247 : { return ((mnMaxWidth == rInfo.mnMaxWidth) &&
248 : (mnLineCount == rInfo.mnLineCount) &&
249 : (mbEllipsis == rInfo.mbEllipsis)); }
250 : bool operator !=( const TextRectInfo& rInfo ) const
251 : { return !(TextRectInfo::operator==( rInfo )); }
252 : };
253 :
254 0 : inline TextRectInfo::TextRectInfo()
255 : {
256 0 : mnMaxWidth = 0;
257 0 : mnLineCount = 0;
258 0 : mbEllipsis = false;
259 0 : }
260 :
261 : #endif // INCLUDED_VCL_METRIC_HXX
262 :
263 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|