1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "i18nlangtag/mslangid.hxx"
#include <unotools/configmgr.hxx>
#include <vcl/virdev.hxx>
#include <vcl/print.hxx>
#include <vcl/outdev.hxx>
#include <vcl/edit.hxx>
#include <vcl/settings.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/fontcharmap.hxx>
#include "sallayout.hxx"
#include "svdata.hxx"
#include "impfont.hxx"
#include "outdata.hxx"
#include "fontinstance.hxx"
#include "fontattributes.hxx"
#include "outdev.h"
#include "window.h"
#include "PhysicalFontCollection.hxx"
#include "PhysicalFontFace.hxx"
#include "PhysicalFontFamily.hxx"
#include "svids.hrc"
#include <config_graphite.h>
#if ENABLE_GRAPHITE
#include "graphite_features.hxx"
#endif
#include "../gdi/pdfwriter_impl.hxx"
#include <boost/functional/hash.hpp>
#include <cmath>
#include <cstring>
#include <memory>
#include <algorithm>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::rtl;
using namespace ::utl;
bool FontAttributes::CompareDeviceIndependentFontAttributes(const FontAttributes& rOther) const
{
if (maFamilyName != rOther.maFamilyName)
return false;
if (maStyleName != rOther.maStyleName)
return false;
if (meWeight != rOther.meWeight)
return false;
if (meItalic != rOther.meItalic)
return false;
if (meFamily != rOther.meFamily)
return false;
if (mePitch != rOther.mePitch)
return false;
if (meWidthType != rOther.meWidthType)
return false;
if (mbSymbolFlag != rOther.mbSymbolFlag)
return false;
return true;
}
FontAttributes::FontAttributes()
: mnWidth ( 0 )
, mnOrientation( 0 )
, mnAscent( 0 )
, mnDescent( 0 )
, mnIntLeading( 0 )
, mnExtLeading( 0 )
, mnSlant( 0 )
, mnMinKashida( 0 )
, mbScalableFont( false )
, mbTrueTypeFont( false )
, mbKernableFont( false )
, mbFullstopCentered( false )
, mnBulletOffset( 0 )
, mnUnderlineSize( 0 )
, mnUnderlineOffset( 0 )
, mnBUnderlineSize( 0 )
, mnBUnderlineOffset( 0 )
, mnDUnderlineSize( 0 )
, mnDUnderlineOffset1( 0 )
, mnDUnderlineOffset2( 0 )
, mnWUnderlineSize( 0 )
, mnWUnderlineOffset( 0 )
, mnAboveUnderlineSize( 0 )
, mnAboveUnderlineOffset( 0 )
, mnAboveBUnderlineSize( 0 )
, mnAboveBUnderlineOffset( 0 )
, mnAboveDUnderlineSize( 0 )
, mnAboveDUnderlineOffset1( 0 )
, mnAboveDUnderlineOffset2( 0 )
, mnAboveWUnderlineSize( 0 )
, mnAboveWUnderlineOffset( 0 )
, mnStrikeoutSize( 0 )
, mnStrikeoutOffset( 0 )
, mnBStrikeoutSize( 0 )
, mnBStrikeoutOffset( 0 )
, mnDStrikeoutSize( 0 )
, mnDStrikeoutOffset1( 0 )
, mnDStrikeoutOffset2( 0 )
{
// empty
}
FontAttributes::FontAttributes( const FontSelectPattern& rFontSelData )
: mnWidth ( rFontSelData.mnWidth )
, mnOrientation( (short)(rFontSelData.mnOrientation) )
, mnAscent( 0 )
, mnDescent( 0 )
, mnIntLeading( 0 )
, mnExtLeading( 0 )
, mnSlant( 0 )
, mnMinKashida( 0 )
, mbScalableFont( false )
, mbTrueTypeFont( false )
, mbKernableFont( false )
, mbFullstopCentered( false )
, mnBulletOffset( 0 )
, mnUnderlineSize( 0 )
, mnUnderlineOffset( 0 )
, mnBUnderlineSize( 0 )
, mnBUnderlineOffset( 0 )
, mnDUnderlineSize( 0 )
, mnDUnderlineOffset1( 0 )
, mnDUnderlineOffset2( 0 )
, mnWUnderlineSize( 0 )
, mnWUnderlineOffset( 0 )
, mnAboveUnderlineSize( 0 )
, mnAboveUnderlineOffset( 0 )
, mnAboveBUnderlineSize( 0 )
, mnAboveBUnderlineOffset( 0 )
, mnAboveDUnderlineSize( 0 )
, mnAboveDUnderlineOffset1( 0 )
, mnAboveDUnderlineOffset2( 0 )
, mnAboveWUnderlineSize( 0 )
, mnAboveWUnderlineOffset( 0 )
, mnStrikeoutSize( 0 )
, mnStrikeoutOffset( 0 )
, mnBStrikeoutSize( 0 )
, mnBStrikeoutOffset( 0 )
, mnDStrikeoutSize( 0 )
, mnDStrikeoutOffset1( 0 )
, mnDStrikeoutOffset2( 0 )
{
// intialize the used font name
if( rFontSelData.mpFontData )
{
SetFamilyName( rFontSelData.mpFontData->GetFamilyName() );
SetStyleName( rFontSelData.mpFontData->GetStyleName() );
SetBuiltInFontFlag( rFontSelData.mpFontData->IsBuiltInFont() );
SetKernableFlag( true );
}
else
{
sal_Int32 nTokenPos = 0;
SetFamilyName( GetNextFontToken( rFontSelData.GetFamilyName(), nTokenPos ) );
SetStyleName( rFontSelData.GetStyleName() );
SetBuiltInFontFlag( false );
SetKernableFlag( false );
}
}
void FontAttributes::ImplInitTextLineSize( const OutputDevice* pDev )
{
long nDescent = mnDescent;
if ( nDescent <= 0 )
{
nDescent = mnAscent / 10;
if ( !nDescent )
nDescent = 1;
}
// #i55341# for some fonts it is not a good idea to calculate
// their text line metrics from the real font descent
// => work around this problem just for these fonts
if( 3*nDescent > mnAscent )
nDescent = mnAscent / 3;
long nLineHeight = ((nDescent*25)+50) / 100;
if ( !nLineHeight )
nLineHeight = 1;
long nLineHeight2 = nLineHeight / 2;
if ( !nLineHeight2 )
nLineHeight2 = 1;
long nBLineHeight = ((nDescent*50)+50) / 100;
if ( nBLineHeight == nLineHeight )
nBLineHeight++;
long nBLineHeight2 = nBLineHeight/2;
if ( !nBLineHeight2 )
nBLineHeight2 = 1;
long n2LineHeight = ((nDescent*16)+50) / 100;
if ( !n2LineHeight )
n2LineHeight = 1;
long n2LineDY = n2LineHeight;
/* #117909#
* add some pixels to minimum double line distance on higher resolution devices
*/
long nMin2LineDY = 1 + pDev->GetDPIY()/150;
if ( n2LineDY < nMin2LineDY )
n2LineDY = nMin2LineDY;
long n2LineDY2 = n2LineDY/2;
if ( !n2LineDY2 )
n2LineDY2 = 1;
long nUnderlineOffset = mnDescent/2 + 1;
long nStrikeoutOffset = -((mnAscent - mnIntLeading) / 3);
mnUnderlineSize = nLineHeight;
mnUnderlineOffset = nUnderlineOffset - nLineHeight2;
mnBUnderlineSize = nBLineHeight;
mnBUnderlineOffset = nUnderlineOffset - nBLineHeight2;
mnDUnderlineSize = n2LineHeight;
mnDUnderlineOffset1 = nUnderlineOffset - n2LineDY2 - n2LineHeight;
mnDUnderlineOffset2 = mnDUnderlineOffset1 + n2LineDY + n2LineHeight;
long nWCalcSize = mnDescent;
if ( nWCalcSize < 6 )
{
if ( (nWCalcSize == 1) || (nWCalcSize == 2) )
mnWUnderlineSize = nWCalcSize;
else
mnWUnderlineSize = 3;
}
else
mnWUnderlineSize = ((nWCalcSize*50)+50) / 100;
// Don't assume that wavelines are never placed below the descent, because for most fonts the waveline
// is drawn into the text
mnWUnderlineOffset = nUnderlineOffset;
mnStrikeoutSize = nLineHeight;
mnStrikeoutOffset = nStrikeoutOffset - nLineHeight2;
mnBStrikeoutSize = nBLineHeight;
mnBStrikeoutOffset = nStrikeoutOffset - nBLineHeight2;
mnDStrikeoutSize = n2LineHeight;
mnDStrikeoutOffset1 = nStrikeoutOffset - n2LineDY2 - n2LineHeight;
mnDStrikeoutOffset2 = mnDStrikeoutOffset1 + n2LineDY + n2LineHeight;
const vcl::Font& rFont ( pDev->GetFont() );
bool bCentered = true;
if (MsLangId::isCJK(rFont.GetLanguage()))
{
const OUString sFullstop( sal_Unicode( 0x3001 ) ); // Fullwidth fullstop
Rectangle aRect;
pDev->GetTextBoundRect( aRect, sFullstop );
const sal_uInt16 nH = rFont.GetSize().Height();
const sal_uInt16 nB = aRect.Left();
// Use 18.75% as a threshold to define a centered fullwidth fullstop.
// In general, nB/nH < 5% for most Japanese fonts.
bCentered = nB > (((nH >> 1)+nH)>>3);
}
SetFullstopCenteredFlag( bCentered );
mnBulletOffset = ( pDev->GetTextWidth( OUString( sal_Unicode( 0x20 ) ) ) - pDev->GetTextWidth( OUString( sal_Unicode( 0xb7 ) ) ) ) >> 1 ;
}
void FontAttributes::ImplInitAboveTextLineSize()
{
long nIntLeading = mnIntLeading;
// TODO: assess usage of nLeading below (changed in extleading CWS)
// if no leading is available, we assume 15% of the ascent
if ( nIntLeading <= 0 )
{
nIntLeading = mnAscent*15/100;
if ( !nIntLeading )
nIntLeading = 1;
}
long nLineHeight = ((nIntLeading*25)+50) / 100;
if ( !nLineHeight )
nLineHeight = 1;
long nBLineHeight = ((nIntLeading*50)+50) / 100;
if ( nBLineHeight == nLineHeight )
nBLineHeight++;
long n2LineHeight = ((nIntLeading*16)+50) / 100;
if ( !n2LineHeight )
n2LineHeight = 1;
long nCeiling = -mnAscent;
mnAboveUnderlineSize = nLineHeight;
mnAboveUnderlineOffset = nCeiling + (nIntLeading - nLineHeight + 1) / 2;
mnAboveBUnderlineSize = nBLineHeight;
mnAboveBUnderlineOffset = nCeiling + (nIntLeading - nBLineHeight + 1) / 2;
mnAboveDUnderlineSize = n2LineHeight;
mnAboveDUnderlineOffset1 = nCeiling + (nIntLeading - 3*n2LineHeight + 1) / 2;
mnAboveDUnderlineOffset2 = nCeiling + (nIntLeading + n2LineHeight + 1) / 2;
long nWCalcSize = nIntLeading;
if ( nWCalcSize < 6 )
{
if ( (nWCalcSize == 1) || (nWCalcSize == 2) )
mnAboveWUnderlineSize = nWCalcSize;
else
mnAboveWUnderlineSize = 3;
}
else
mnAboveWUnderlineSize = ((nWCalcSize*50)+50) / 100;
mnAboveWUnderlineOffset = nCeiling + (nIntLeading + 1) / 2;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|