xref: /aoo41x/main/vcl/source/gdi/metric.cxx (revision 43ad51ff)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <impfont.hxx>
28 #include <vcl/metric.hxx>
29 
30 #include <vector>
31 #include <set>
32 
33 #include <cstdio>
34 
35 // =======================================================================
36 
ImplFontMetric()37 ImplFontMetric::ImplFontMetric()
38 :   mnAscent( 0 ),
39     mnDescent( 0 ),
40     mnIntLeading( 0 ),
41     mnExtLeading( 0 ),
42     mnLineHeight( 0 ),
43     mnSlant( 0 ),
44     mnMiscFlags( 0 ),
45     mnRefCount( 1 )
46 {}
47 
48 // -----------------------------------------------------------------------
49 
AddReference()50 inline void ImplFontMetric::AddReference()
51 {
52     // TODO: disable refcounting on the default maps?
53     ++mnRefCount;
54 }
55 
56 // -----------------------------------------------------------------------
57 
DeReference()58 inline void ImplFontMetric::DeReference()
59 {
60     // TODO: disable refcounting on the default maps?
61     if( --mnRefCount <= 0 )
62         delete this;
63 }
64 
65 // -----------------------------------------------------------------------
66 
operator ==(const ImplFontMetric & r) const67 bool ImplFontMetric::operator==( const ImplFontMetric& r ) const
68 {
69     if( mnMiscFlags  != r.mnMiscFlags )
70         return false;
71     if( mnAscent     != r.mnAscent )
72         return false;
73     if( mnDescent    != r.mnDescent )
74         return false;
75     if( mnIntLeading != r.mnIntLeading )
76         return false;
77     if( mnExtLeading != r.mnExtLeading )
78         return false;
79     if( mnSlant      != r.mnSlant )
80         return false;
81 
82     return true;
83 }
84 
85 // =======================================================================
86 
FontInfo()87 FontInfo::FontInfo()
88 :   mpImplMetric( new ImplFontMetric )
89 {}
90 
91 // -----------------------------------------------------------------------
92 
FontInfo(const FontInfo & rInfo)93 FontInfo::FontInfo( const FontInfo& rInfo )
94 :  Font( rInfo )
95 {
96     mpImplMetric = rInfo.mpImplMetric;
97     mpImplMetric->AddReference();
98 }
99 
100 // -----------------------------------------------------------------------
101 
~FontInfo()102 FontInfo::~FontInfo()
103 {
104     mpImplMetric->DeReference();
105 }
106 
107 // -----------------------------------------------------------------------
108 
operator =(const FontInfo & rInfo)109 FontInfo& FontInfo::operator=( const FontInfo& rInfo )
110 {
111     Font::operator=( rInfo );
112 
113     if( mpImplMetric != rInfo.mpImplMetric )
114     {
115         mpImplMetric->DeReference();
116         mpImplMetric = rInfo.mpImplMetric;
117         mpImplMetric->AddReference();
118     }
119 
120     return *this;
121 }
122 
123 // -----------------------------------------------------------------------
124 
operator ==(const FontInfo & rInfo) const125 sal_Bool FontInfo::operator==( const FontInfo& rInfo ) const
126 {
127     if( !Font::operator==( rInfo ) )
128         return sal_False;
129     if( mpImplMetric == rInfo.mpImplMetric )
130         return sal_True;
131     if( *mpImplMetric == *rInfo.mpImplMetric  )
132         return sal_True;
133     return sal_False;
134 }
135 
136 // -----------------------------------------------------------------------
137 
GetType() const138 FontType FontInfo::GetType() const
139 {
140     return (mpImplMetric->IsScalable() ? TYPE_SCALABLE : TYPE_RASTER);
141 }
142 
143 // -----------------------------------------------------------------------
144 
IsDeviceFont() const145 sal_Bool FontInfo::IsDeviceFont() const
146 {
147     return mpImplMetric->IsDeviceFont();
148 }
149 
150 // -----------------------------------------------------------------------
151 
SupportsLatin() const152 sal_Bool FontInfo::SupportsLatin() const
153 {
154     return mpImplMetric->SupportsLatin();
155 }
156 
157 // -----------------------------------------------------------------------
158 
SupportsCJK() const159 sal_Bool FontInfo::SupportsCJK() const
160 {
161     return mpImplMetric->SupportsCJK();
162 }
163 
164 // -----------------------------------------------------------------------
165 
SupportsCTL() const166 sal_Bool FontInfo::SupportsCTL() const
167 {
168     return mpImplMetric->SupportsCTL();
169 }
170 
171 // =======================================================================
172 
FontMetric(const FontMetric & rMetric)173 FontMetric::FontMetric( const FontMetric& rMetric )
174 :    FontInfo( rMetric )
175 {}
176 
177 // -----------------------------------------------------------------------
178 
GetAscent() const179 long FontMetric::GetAscent() const
180 {
181     return mpImplMetric->GetAscent();
182 }
183 
184 // -----------------------------------------------------------------------
185 
GetDescent() const186 long FontMetric::GetDescent() const
187 {
188     return mpImplMetric->GetDescent();
189 }
190 
191 // -----------------------------------------------------------------------
192 
GetIntLeading() const193 long FontMetric::GetIntLeading() const
194 {
195     return mpImplMetric->GetIntLeading();
196 }
197 
198 // -----------------------------------------------------------------------
199 
GetExtLeading() const200 long FontMetric::GetExtLeading() const
201 {
202     return mpImplMetric->GetExtLeading();
203 }
204 
205 // -----------------------------------------------------------------------
206 
GetLineHeight() const207 long FontMetric::GetLineHeight() const
208 {
209     return mpImplMetric->GetLineHeight();
210 }
211 
212 // -----------------------------------------------------------------------
213 
GetSlant() const214 long FontMetric::GetSlant() const
215 {
216     return mpImplMetric->GetSlant();
217 }
218 
219 // -----------------------------------------------------------------------
220 
operator =(const FontMetric & rMetric)221 FontMetric& FontMetric::operator =( const FontMetric& rMetric )
222 {
223     FontInfo::operator=( rMetric );
224     return *this;
225 }
226 
227 // -----------------------------------------------------------------------
228 
operator ==(const FontMetric & rMetric) const229 sal_Bool FontMetric::operator==( const FontMetric& rMetric ) const
230 {
231     return FontInfo::operator==( rMetric );
232 }
233 
234 // =======================================================================
235 
236