Main Page
Namespaces
Classes
Files
File List
File Members
MWAWFont.hxx
Go to the documentation of this file.
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libmwaw
4
* Version: MPL 2.0 / LGPLv2+
5
*
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 2.0 (the "License"); you may not use this file except in compliance with
8
* the License or as specified alternatively below. You may obtain a copy of
9
* the License at http://www.mozilla.org/MPL/
10
*
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
14
* License.
15
*
16
* Major Contributor(s):
17
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22
*
23
*
24
* All Rights Reserved.
25
*
26
* For minor contributions see the git repository.
27
*
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30
* in which case the provisions of the LGPLv2+ are applicable
31
* instead of those above.
32
*/
33
34
#ifndef MWAW_FONT
35
# define MWAW_FONT
36
37
#include <assert.h>
38
#include <string>
39
#include <vector>
40
41
#include "
libmwaw_internal.hxx
"
42
43
class
WPXPropertyList;
44
46
class
MWAWFont
47
{
48
public
:
50
struct
Line
{
52
enum
Style
{
None
,
Simple
,
Dot
,
LargeDot
,
Dash
,
Wave
};
54
enum
Type
{
Single
,
Double
,
Triple
};
56
Line
(
Style
style=
None
,
Type
type=
Single
,
bool
wordFlag=
false
,
float
w=1.0) :
57
m_style
(style),
m_type
(type),
m_word
(wordFlag),
m_width
(w),
m_color
(
MWAWColor
::black()) { }
59
bool
isSet
()
const
{
60
return
m_style
!=
None
&&
m_width
>0;
61
}
63
void
addTo
(WPXPropertyList &propList, std::string
const
&type)
const
;
65
friend
std::ostream &
operator<<
(std::ostream &o,
Line
const
&line);
67
bool
operator==
(
Line
const
&oth)
const
{
68
return
cmp
(oth)==0;
69
}
71
bool
operator!=
(
Line
const
&oth)
const
{
72
return
cmp
(oth)!=0;
73
}
75
int
cmp
(
Line
const
&oth)
const
{
76
if
(
m_style
!= oth.
m_style
)
return
int(
m_style
)-int(oth.
m_style
);
77
if
(
m_type
!= oth.
m_type
)
return
int(
m_type
)-int(oth.
m_type
);
78
if
(
m_word
!= oth.
m_word
)
return
m_word
? -1 : 1;
79
if
(
m_width
< oth.
m_width
)
return
-1;
80
if
(
m_width
> oth.
m_width
)
return
1;
81
if
(
m_color
.
isSet
() != oth.
m_color
.
isSet
())
82
return
m_color
.
isSet
();
83
if
(
m_color
.
get
() < oth.
m_color
.
get
())
return
-1;
84
if
(
m_color
.
get
() > oth.
m_color
.
get
())
return
1;
85
return
0;
86
}
88
Style
m_style
;
90
Type
m_type
;
92
bool
m_word
;
94
float
m_width
;
96
Variable<MWAWColor>
m_color
;
97
};
99
struct
Script
{
101
Script
(
float
delta=0, WPXUnit deltaUnit=WPX_PERCENT,
int
scale=100) :
102
m_delta
(delta),
m_deltaUnit
(deltaUnit),
m_scale
(scale) {
103
}
105
bool
isSet
()
const
{
106
return
*
this
!=
Script
();
107
}
109
static
Script
sub
() {
110
return
Script
(-33,WPX_PERCENT,58);
111
}
113
static
Script
sub100
() {
114
return
Script
(-20);
115
}
117
static
Script
super
() {
118
return
Script
(33,WPX_PERCENT,58);
119
}
121
static
Script
super100
() {
122
return
Script
(20);
123
}
125
std::string
str
(
float
fSize)
const
;
126
128
bool
operator==
(
Script
const
&oth)
const
{
129
return
cmp
(oth)==0;
130
}
132
bool
operator!=
(
Script
const
&oth)
const
{
133
return
cmp
(oth)!=0;
134
}
136
bool
operator<
(
Script
const
&oth)
const
{
137
return
cmp
(oth)<0;
138
}
140
bool
operator<=
(
Script
const
&oth)
const
{
141
return
cmp
(oth)<=0;
142
}
144
bool
operator>
(
Script
const
&oth)
const
{
145
return
cmp
(oth)>0;
146
}
148
bool
operator>=
(
Script
const
&oth)
const
{
149
return
cmp
(oth)>=0;
150
}
152
int
cmp
(
Script
const
&oth)
const
{
153
if
(
m_delta
> oth.
m_delta
)
return
-1;
154
if
(
m_delta
< oth.
m_delta
)
return
1;
155
if
(
m_deltaUnit
!= oth.
m_deltaUnit
)
return
int(
m_deltaUnit
)-int(oth.
m_deltaUnit
);
156
if
(
m_scale
!= oth.
m_scale
)
return
m_scale
-oth.
m_scale
;
157
return
0;
158
}
160
float
m_delta
;
162
WPXUnit
m_deltaUnit
;
164
int
m_scale
;
165
};
166
168
enum
FontBits
{
boldBit
=1,
italicBit
=2,
blinkBit
=4,
embossBit
=8,
engraveBit
=0x10,
169
hiddenBit
=0x20,
outlineBit
=0x40,
shadowBit
=0x80,
170
reverseVideoBit
=0x100,
smallCapsBit
=0x200,
allCapsBit
=0x400,
171
lowercaseBit
=0x800,
boxedBit
=0x1000,
boxedRoundedBit
=0x2000,
172
reverseWritingBit
=0x4000
173
};
179
MWAWFont
(
int
newId=-1,
float
sz=12, uint32_t f = 0) :
m_id
(newId),
m_size
(sz),
m_deltaSpacing
(0),
m_texteWidthScaling
(1.0),
m_scriptPosition
(),
180
m_flags
(f),
m_overline
(
Line
::None),
m_strikeoutline
(
Line
::None),
m_underline
(
Line
::None),
181
m_color
(
MWAWColor
::black()),
m_backgroundColor
(
MWAWColor
::white()),
m_language
(
""
),
m_extra
(
""
) {
182
resetColor
();
183
};
185
bool
isSet
()
const
{
186
return
m_id
.
isSet
();
187
}
189
void
insert
(
MWAWFont
const
&ft) {
190
m_id
.
insert
(ft.
m_id
);
191
m_size
.
insert
(ft.
m_size
);
192
m_deltaSpacing
.
insert
(ft.
m_deltaSpacing
);
193
m_texteWidthScaling
.
insert
(ft.
m_texteWidthScaling
);
194
m_scriptPosition
.insert(ft.
m_scriptPosition
);
195
if
(ft.
m_flags
.
isSet
()) {
196
if
(
m_flags
.
isSet
())
197
setFlags
(
flags
()| ft.
flags
());
198
else
199
m_flags
= ft.
m_flags
;
200
}
201
m_overline
.insert(ft.
m_overline
);
202
m_strikeoutline
.insert(ft.
m_strikeoutline
);
203
m_underline
.insert(ft.
m_underline
);
204
m_color
.
insert
(ft.
m_color
);
205
m_extra
+= ft.
m_extra
;
206
}
208
void
setFont
(
int
newId) {
209
resetColor
();
210
m_id
=newId;
211
}
212
214
int
id
()
const
{
215
return
m_id
.
get
();
216
}
218
void
setId
(
int
newId) {
219
m_id
= newId;
220
}
221
223
float
size
()
const
{
224
return
m_size
.
get
();
225
}
227
void
setSize
(
float
sz) {
228
m_size
= sz;
229
}
230
232
float
deltaLetterSpacing
()
const
{
233
return
m_deltaSpacing
.
get
();
234
}
236
void
setDeltaLetterSpacing
(
float
d) {
237
m_deltaSpacing
=d;
238
}
240
float
texteWidthScaling
()
const
{
241
return
m_texteWidthScaling
.
get
();
242
}
244
void
setTexteWidthScaling
(
float
scale=1.0) {
245
m_texteWidthScaling
= scale;
246
}
248
Script
const
&
script
()
const
{
249
return
m_scriptPosition
.get();
250
}
251
253
void
set
(
Script
const
&newscript) {
254
m_scriptPosition
= newscript;
255
}
256
258
uint32_t
flags
()
const
{
259
return
m_flags
.
get
();
260
}
262
void
setFlags
(uint32_t fl) {
263
m_flags
= fl;
264
}
265
267
bool
hasColor
()
const
{
268
return
m_color
.
isSet
() && !
m_color
.
get
().isBlack();
269
}
271
void
getColor
(
MWAWColor
&c)
const
{
272
c =
m_color
.
get
();
273
}
275
void
setColor
(
MWAWColor
color) {
276
m_color
= color;
277
}
278
280
void
getBackgroundColor
(
MWAWColor
&c)
const
{
281
c =
m_backgroundColor
.
get
();
282
}
284
void
setBackgroundColor
(
MWAWColor
color) {
285
m_backgroundColor
= color;
286
}
288
void
resetColor
() {
289
m_color
=
MWAWColor::black
();
290
m_backgroundColor
=
MWAWColor::white
();
291
}
292
294
bool
hasDecorationLines
()
const
{
295
return
(
m_overline
.isSet() &&
m_overline
->isSet()) ||
296
(
m_strikeoutline
.isSet() &&
m_strikeoutline
->isSet()) ||
297
(
m_underline
.isSet() &&
m_underline
->isSet());
298
}
300
void
resetDecorationLines
() {
301
if
(
m_overline
.isSet())
m_overline
=
Line
(
Line::None
);
302
if
(
m_strikeoutline
.isSet())
m_strikeoutline
=
Line
(
Line::None
);
303
if
(
m_underline
.isSet())
m_underline
=
Line
(
Line::None
);
304
}
306
Line
const
&
getOverline
()
const
{
307
return
m_overline
.get();
308
}
310
void
setOverline
(
Line
const
&line) {
311
m_overline
= line;
312
}
314
void
setOverlineStyle
(
Line::Style
style=
Line::None
,
bool
doReset=
true
) {
315
if
(doReset)
316
m_overline
=
Line
(style);
317
else
318
m_overline
->m_style = style;
319
}
321
void
setOverlineType
(
Line::Type
type=
Line::Single
) {
322
m_overline
->m_type = type;
323
}
325
void
setOverlineWordFlag
(
bool
wordFlag=
false
) {
326
m_overline
->m_word = wordFlag;
327
}
329
void
setOverlineWidth
(
float
w) {
330
m_overline
->m_width = w;
331
}
333
void
setOverlineColor
(
MWAWColor
const
&color) {
334
m_overline
->m_color = color;
335
}
336
338
Line
const
&
getStrikeOut
()
const
{
339
return
m_strikeoutline
.get();
340
}
342
void
setStrikeOut
(
Line
const
&line) {
343
m_strikeoutline
= line;
344
}
346
void
setStrikeOutStyle
(
Line::Style
style=
Line::None
,
bool
doReset=
true
) {
347
if
(doReset)
348
m_strikeoutline
=
Line
(style);
349
else
350
m_strikeoutline
->m_style = style;
351
}
353
void
setStrikeOutType
(
Line::Type
type=
Line::Single
) {
354
m_strikeoutline
->m_type = type;
355
}
357
void
setStrikeOutWordFlag
(
bool
wordFlag=
false
) {
358
m_strikeoutline
->m_word = wordFlag;
359
}
361
void
setStrikeOutWidth
(
float
w) {
362
m_strikeoutline
->m_width = w;
363
}
365
void
setStrikeOutColor
(
MWAWColor
const
&color) {
366
m_strikeoutline
->m_color = color;
367
}
368
370
Line
const
&
getUnderline
()
const
{
371
return
m_underline
.get();
372
}
374
void
setUnderline
(
Line
const
&line) {
375
m_underline
= line;
376
}
378
void
setUnderlineStyle
(
Line::Style
style=
Line::None
,
bool
doReset=
true
) {
379
if
(doReset)
380
m_underline
=
Line
(style);
381
else
382
m_underline
->m_style = style;
383
}
385
void
setUnderlineType
(
Line::Type
type=
Line::Single
) {
386
m_underline
->m_type = type;
387
}
389
void
setUnderlineWordFlag
(
bool
wordFlag=
false
) {
390
m_underline
->m_word = wordFlag;
391
}
393
void
setUnderlineWidth
(
float
w) {
394
m_underline
->m_width = w;
395
}
397
void
setUnderlineColor
(
MWAWColor
const
&color) {
398
m_underline
->m_color = color;
399
}
400
402
std::string
const
&
language
()
const
{
403
return
m_language
.
get
();
404
}
406
void
setLanguage
(std::string
const
&lang) {
407
m_language
=lang;
408
}
410
void
addTo
(WPXPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter)
const
;
411
413
std::string
getDebugString
(shared_ptr<MWAWFontConverter> &converter)
const
;
414
416
bool
operator==
(
MWAWFont
const
&f)
const
{
417
return
cmp
(f) == 0;
418
}
420
bool
operator!=
(
MWAWFont
const
&f)
const
{
421
return
cmp
(f) != 0;
422
}
423
425
int
cmp
(
MWAWFont
const
&oth)
const
{
426
int
diff =
id
() - oth.
id
();
427
if
(diff != 0)
return
diff;
428
if
(
size
() < oth.
size
())
return
-1;
429
if
(
size
() > oth.
size
())
return
-1;
430
if
(
flags
() < oth.
flags
())
return
-1;
431
if
(
flags
() > oth.
flags
())
return
1;
432
if
(
m_deltaSpacing
.
get
() < oth.
m_deltaSpacing
.
get
())
return
-1;
433
if
(
m_deltaSpacing
.
get
() > oth.
m_deltaSpacing
.
get
())
return
1;
434
if
(
m_texteWidthScaling
.
get
() < oth.
m_texteWidthScaling
.
get
())
return
-1;
435
if
(
m_texteWidthScaling
.
get
() > oth.
m_texteWidthScaling
.
get
())
return
1;
436
diff =
script
().
cmp
(oth.
script
());
437
if
(diff != 0)
return
diff;
438
diff =
m_overline
.get().cmp(oth.
m_overline
.get());
439
if
(diff != 0)
return
diff;
440
diff =
m_strikeoutline
.get().cmp(oth.
m_strikeoutline
.get());
441
if
(diff != 0)
return
diff;
442
diff =
m_underline
.get().cmp(oth.
m_underline
.get());
443
if
(diff != 0)
return
diff;
444
if
(
m_color
.
get
() < oth.
m_color
.
get
())
return
-1;
445
if
(
m_color
.
get
() > oth.
m_color
.
get
())
return
1;
446
if
(
m_backgroundColor
.
get
() < oth.
m_backgroundColor
.
get
())
return
-1;
447
if
(
m_backgroundColor
.
get
() > oth.
m_backgroundColor
.
get
())
return
1;
448
if
(
m_language
.
get
() < oth.
m_language
.
get
())
return
-1;
449
if
(
m_language
.
get
() > oth.
m_language
.
get
())
return
1;
450
return
diff;
451
}
452
453
protected
:
454
Variable<int>
m_id
;
455
Variable<float>
m_size
;
456
Variable<float>
m_deltaSpacing
;
457
Variable<float>
m_texteWidthScaling
;
458
Variable<Script>
m_scriptPosition
;
459
Variable<uint32_t>
m_flags
;
460
Variable<Line>
m_overline
;
461
Variable<Line>
m_strikeoutline
;
462
Variable<Line>
m_underline
;
463
Variable<MWAWColor>
m_color
;
464
Variable<MWAWColor>
m_backgroundColor
;
465
Variable<std::string>
m_language
;
466
public
:
468
std::string
m_extra
;
469
};
470
471
472
#endif
473
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Generated on Wed Jul 10 2013 18:15:30 for libmwaw by
doxygen
1.8.4