Repository navigation
Expand file tree
/
Copy pathastextrun.cpp
More file actions
564 lines (473 loc) · 15.2 KB
/
Copy pathastextrun.cpp
File metadata and controls
564 lines (473 loc) · 15.2 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/** @file astextrun.cpp
* Responsible for maintaining text items.
* Copyright (C) 2006-2010 Promethean Limited. All Rights Reserved.
*/
#include "astextrun.h"
#include <QByteArray>
AsTextRun::AsTextRun( AsFactory *pAsFactory )
: AsObject( pAsFactory ),
m_bMisspelltWord(false),
m_bTextRunDirty(false),
m_bulletStyle(AsTextRun::AS_TEXT_LISTUNKNOWN)
{
// Set the type property.
asSetType( AsObject::AS_OBJECT_TEXTRUN );
m_polygonList.clear();
}
AsTextRun::AsTextRun()
: AsObject( NULL ),
m_bMisspelltWord(false),
m_bTextRunDirty(false),
m_bulletStyle(AsTextRun::AS_TEXT_LISTUNKNOWN)
{
// Set the type property.
asSetType( AsObject::AS_OBJECT_TEXTRUN );
m_polygonList.clear();
}
AsTextRun::~AsTextRun()
{
}
QHash<QString, quint16>& AsTextRun::m_lProperties( void )
{
static QHash<QString, quint16> HashProperties;
if ( HashProperties.isEmpty() )
{
// From AsObject...
// HashProperties.insert( "asDateTimeCreated", ( quint16 )AsTextRun::AS_PROPERTY_DATETIMECREATED );
// From AsTextRun...
HashProperties.insert( "asBoundingRect", ( quint16 )AsTextRun::AS_PROPERTY_BOUNDING_RECT );
HashProperties.insert( "asTextPos", ( quint16 )AsTextRun::AS_PROPERTY_TEXTPOS );
HashProperties.insert( "asTextColor", ( quint16 )AsTextRun::AS_PROPERTY_TEXTCOLOR );
HashProperties.insert( "asText", ( quint16 )AsTextRun::AS_PROPERTY_TEXT );
HashProperties.insert( "asFontFamily", ( quint16 )AsTextRun::AS_PROPERTY_FONTFAMILY );
HashProperties.insert( "asFontSize", ( quint16 )AsTextRun::AS_PROPERTY_FONTSIZE );
HashProperties.insert( "asFontWeight", ( quint16 )AsTextRun::AS_PROPERTY_FONTWEIGHT );
HashProperties.insert( "asFontItalic", ( quint16 )AsTextRun::AS_PROPERTY_FONTITALIC );
HashProperties.insert( "asFontUnderline", ( quint16 )AsTextRun::AS_PROPERTY_FONTUNDERLINE );
HashProperties.insert( "asFontStrikeout", ( quint16 )AsTextRun::AS_PROPERTY_FONTSTRIKEOUT );
HashProperties.insert( "asPolygonList", ( quint16 )AsTextRun::AS_PROPERTY_POLYGONLIST );
HashProperties.insert( "asBulletType", ( quint16 )AsTextRun::AS_PROPERTY_BULLETTYPE );
HashProperties.insert( "asBulletPosition", ( quint16 )AsTextRun::AS_PROPERTY_BULLETPOSITION );
HashProperties.insert( "asBulletText", ( quint16 )AsTextRun::AS_PROPERTY_BULLETTEXT );
HashProperties.insert( "asMisspelltWord", ( quint16 )AsTextRun::AS_PROPERTY_MISSPELLTWORD );
}
return HashProperties;
}
void AsTextRun::asSetTextRun( const QPointF & TextPos,
const QString & Text ,
const QString & FontFamily ,
const qreal & FontSize ,
const int & FontWeight ,
const bool & Italic,
const bool & UnderLine,
const bool & Strikeout ,
const QColor & TextColor,
AsTextRun::AsEnumTextListFormat bulletStyle,
QRectF bulletPosition)
{
this->m_textPos = TextPos;
this->m_sText = Text;
this->m_sFontFamily = FontFamily;
this->m_nFontSize = FontSize;
this->m_nFontWeight = FontWeight;
this->m_bFontItalic = Italic;
this->m_bFontUnderline = UnderLine;
this->m_bFontStrikeOut = Strikeout;
// this->m_cTextColor = TextColor;
this->m_bulletStyle = bulletStyle;
this->m_bulletPosition = bulletPosition;
m_bTextRunDirty = true;
}
AsTextRun::AsTextRun( const AsTextRun& textrun ) : AsObject( textrun )
{
this->asCopy( textrun );
}
void AsTextRun::operator= ( const AsTextRun& textrun )
{
AsObject::operator = ( textrun );
this->asCopy( textrun );
}
bool AsTextRun::operator== ( const AsTextRun& txtRun )
{
bool bRetVal = true;
if( this->asGetTextPos().x() != txtRun.asGetTextPos().x() )
bRetVal = false;
else if( this->m_sText != txtRun.m_sText )
bRetVal = false;
// else if( this->m_fCachedFont != txtRun.m_fCachedFont )
// bRetVal = false;
return bRetVal;
}
void AsTextRun::asCopy( const AsTextRun& textrun )
{
m_sText = textrun.m_sText;
m_sFontFamily = textrun.m_sFontFamily;
m_nLineNumber = textrun.m_nLineNumber;
m_eAlignment = textrun.m_eAlignment;
m_textPos = textrun.m_textPos;
m_nFontSize = textrun.m_nFontSize;
m_nFontWeight = textrun.m_nFontWeight;
m_bFontItalic = textrun.m_bFontItalic;
m_bFontUnderline = textrun.m_bFontUnderline;
m_bFontStrikeOut = textrun.m_bFontStrikeOut;
// m_eValign = textrun.m_eValign;
// m_cTextColor = textrun.m_cTextColor;
m_boundingRect = textrun.m_boundingRect;
m_bulletStyle = textrun.m_bulletStyle;
m_bulletText = textrun.m_bulletText;
m_bulletPosition = textrun.m_bulletPosition;
m_bMisspelltWord = textrun.m_bMisspelltWord;
// this->m_fCachedFont.setFamily( this->m_sFontFamily );
// this->m_fCachedFont.setPointSizeF( this->m_nFontSize );
// this->m_fCachedFont.setWeight( this->m_nFontWeight );
// this->m_fCachedFont.setItalic( this->m_bFontItalic );
// this->m_fCachedFont.setUnderline( this->m_bFontUnderline );
// this->m_fCachedFont.setStrikeOut( this->m_bFontStrikeOut );
// this->m_painterPath = textrun.m_painterPath;
}
//const QFont & AsTextRun::asGetCachedFont ( void ) const
//{
// if( m_bTextRunDirty )
// {
//// m_fCachedFont.setFamily( m_sFontFamily );
//// m_fCachedFont.setPointSizeF( m_nFontSize );
//// m_fCachedFont.setWeight( m_nFontWeight );
//// m_fCachedFont.setItalic( m_bFontItalic );
//// m_fCachedFont.setUnderline( m_bFontUnderline );
//// m_fCachedFont.setStrikeOut( m_bFontStrikeOut );
// m_bTextRunDirty = false;
// }
// // return m_fCachedFont;
//}
void AsTextRun::asSetCachedFont( const QFont &font )
{
// m_sFontFamily = font.family();
// m_nFontSize = font.pointSizeF();
// m_nFontWeight = font.weight();
// m_bFontItalic = font.italic();
// m_bFontUnderline = font.underline();
// m_bFontStrikeOut = font.strikeOut();
// m_fCachedFont = font;
//
// m_bTextRunDirty = true;
}
//const QColor & AsTextRun::asGetTextColor( void ) const
//{
// // return this->m_cTextColor;
//}
const QPointF & AsTextRun::asGetTextPos( void ) const
{
return this->m_textPos;
}
const QString & AsTextRun::asGetText( void ) const
{
return this->m_sText;
}
const QString& AsTextRun::asGetFontFamily( void ) const
{
return m_sFontFamily;
}
double AsTextRun::asGetFontSize( void ) const
{
return (double)m_nFontSize;
}
int AsTextRun::asGetFontWeight( void ) const
{
return m_nFontWeight;
}
bool AsTextRun::asIsItalic( void ) const
{
return m_bFontItalic;
}
bool AsTextRun::asIsUnderline( void ) const
{
return m_bFontUnderline;
}
bool AsTextRun::asIsStrikeout( void ) const
{
return m_bFontStrikeOut;
}
void AsTextRun::asSetTextColor( QColor &colour )
{
// m_cTextColor = colour;
}
void AsTextRun::asSetTextPos( const QPointF &pos )
{
m_textPos = pos;
m_bTextRunDirty = true;
}
void AsTextRun::asSetText( QString &text )
{
m_sText = text;
m_bTextRunDirty = true;
}
void AsTextRun::asSetFontFamily( QString &fontFamily )
{
m_sFontFamily = fontFamily;
m_bTextRunDirty = true;
}
void AsTextRun::asSetFontSize( double fontSize )
{
m_nFontSize = (qreal)fontSize;
m_bTextRunDirty = true;
}
void AsTextRun::asSetFontWeight( int fontWeight )
{
m_nFontWeight = fontWeight;
m_bTextRunDirty = true;
}
void AsTextRun::asSetItalic( bool italic )
{
m_bFontItalic = italic;
m_bTextRunDirty = true;
}
void AsTextRun::asSetUnderline( bool underline )
{
m_bFontUnderline = underline;
m_bTextRunDirty = true;
}
void AsTextRun::asSetStrikeout( bool strikeout )
{
m_bFontStrikeOut = strikeout;
m_bTextRunDirty = true;
}
void AsTextRun::asResetPropertyIndex( void )
{
// AsObject::asSetPropertyIterator( &m_lProperties );
}
int AsTextRun::asGetLineNumber()
{
return m_nLineNumber;
}
void AsTextRun::asSetLineNumber( int nLineNumber )
{
m_nLineNumber = nLineNumber;
}
bool AsTextRun::asBuildPainterPath() const
{
bool bRetVal = true;
// //if( m_bTextRunDirty ) // (BRS removed this check - else painterpath never generated. Then, text fill breaks)
// {
// // rebuild font first
// m_fCachedFont.setFamily( m_sFontFamily );
// m_fCachedFont.setPointSizeF( m_nFontSize );
// m_fCachedFont.setWeight( m_nFontWeight );
// m_fCachedFont.setItalic( m_bFontItalic );
// m_fCachedFont.setUnderline( m_bFontUnderline );
// m_fCachedFont.setStrikeOut( m_bFontStrikeOut );
//
// // check for empty string or if text is not glyphable i.e a bitmap font.
// if( (m_sText.isEmpty()) || (m_fCachedFont.styleStrategy() == QFont::PreferBitmap))
// bRetVal = false;
// else
// {
// m_painterPath.addText(m_textPos, m_fCachedFont, m_sText);
//
// QVector<QPolygonF> polygons = m_painterPath.toSubpathPolygons().toVector();
//
// // FIXME : have to do an element by element copy because there is currently not way
// // to downcast from QPolygonF to an AsPointFArray
// int nSize = polygons.size();
//
// for( int i = 0; i < nSize; i++ )
// {
// QVector<QPointF> polygon = polygons[i];
// AsPointFArray arr;
// for( int j = 0; j < polygon.size(); j++ )
// {
// arr.append(polygon[j]);
// }
//
// m_polygonList.append(arr);
// }
// }
//
// m_bTextRunDirty = false;
// }
return bRetVal;
}
//const QPainterPath & AsTextRun::asGetPainterPath() const
//{
// // if( m_bTextRunDirty ) // (BRS removed this check - else painterpath never generated. Then, text fill breaks)
// {
// asBuildPainterPath();
// m_bTextRunDirty = false;
// }
//
// return m_painterPath;
//}
const AsPointFArrayArray & AsTextRun::asGetPolygonList() const
{
// ensure we don't attempt to build the initial painter path here
// as we are not guaranteed to have all the required properties set at this point of the
// serialissation process
// if( m_bTextRunDirty && !m_painterPath.isEmpty())
// {
// asBuildPainterPath();
// }
return m_polygonList;
}
void AsTextRun::asSetPolygonList(AsPointFArrayArray & polygons)
{
m_polygonList = polygons;
// build painter path from polygon list
asBuildPathFromPolygons();
}
void AsTextRun::asBuildPathFromPolygons()
{
for( int i = 0; i < m_polygonList.size(); i++ )
{
// m_painterPath.addPolygon(m_polygonList[i]);
}
}
AsTextRun::AsEnumTextListFormat AsTextRun::asGetBulletType()const
{
return m_bulletStyle;
}
void AsTextRun::asSetBulletType(AsTextRun::AsEnumTextListFormat type)
{
m_bulletStyle = type;
m_bTextRunDirty = true;
}
void AsTextRun::asSetBulletText(const QString& bulletText)
{
m_bulletText = bulletText;
}
const QString& AsTextRun::asGetBulletText()const
{
return m_bulletText;
}
const QRectF & AsTextRun::asGetBulletPosition() const
{
return m_bulletPosition;
}
void AsTextRun::asSetBulletPosition( QRectF & rect)
{
m_bulletPosition = rect;
}
//void AsTextRun::asCalculateBulletPosition(const QSizeF&, const QFont& bulletFont, bool rightToLeft)
//{
// // calculate the bounding rect
// // QFontMetricsF metrics( m_fCachedFont );
// qreal xPos = 0.0;
// if( rightToLeft )
// {
// asCalculateBoundingRect();
// // The magic number in the following line should be replaced with the right end offset when the right to left text edit lays out
// // indents properly, check AsPaintEngineCaptureText::drawTextItem if you change this value
// xPos = m_boundingRect.right() + 80;
// }
// else
// {
// xPos = m_textPos.x();
// }
// qreal yPos = m_textPos.y();
// // qreal yadjust = metrics.ascent();
//
// QSizeF size;
// if( m_bulletStyle == AsTextRun::AS_TEXT_LISTDECIMAL ||
// m_bulletStyle == AsTextRun::AS_TEXT_LISTLOWERALPHA ||
// m_bulletStyle == AsTextRun::AS_TEXT_LISTUPPERALPHA)
// {
//// QFontMetricsF bulletFontMetrics( bulletFont );
//// size.setWidth(bulletFontMetrics.width(m_bulletText));
//// size.setHeight(bulletFontMetrics.height());
////
//// xPos = xPos - (1.3 * size.width());
////
//// yPos = (yPos - yadjust);
// }
// else
// {
// // NN:remove this once we receive fix from Qt for averageCharWidth
////#ifdef Q_OS_WIN
//// size.setWidth(metrics.averageCharWidth() * 0.9);
////#else
//// size.setWidth(metrics.lineSpacing() / 3);
////#endif
//
//// size.setHeight(size.width());
////
//// xPos = xPos - (1.67 * size.width());
////
//// yPos = (yPos - yadjust + (metrics.height()-size.height())/2 );
// }
//
// QRectF rect(QPointF(xPos,yPos), size);
//
// asSetBulletPosition(rect);
//}
qreal AsTextRun::asGetSnapOffset()
{
// QFontMetricsF metrics(m_fCachedFont);
qreal dAscent=0.0f;
return dAscent;
}
const AsRectF & AsTextRun::asGetBoundingRect() const
{
return m_boundingRect;
}
void AsTextRun::asSetBoundingRect( AsRectF & rect)
{
m_boundingRect = rect;
}
void AsTextRun::asCalculateBoundingRect(const QSizeF& bounds)
{
Q_UNUSED(bounds);
// calculate the bounding rect
// QFontMetricsF metrics( m_fCachedFont );
qreal nWidth = 0.0f;
qreal nHeight = 0.0f;
// need to align to top
qreal yadjust = 0.0f;
qreal xPos = m_textPos.x();
//if(bounds.height() > 0 && !m_nLineNumber)
// nHeight = bounds.height();
AsRectF rect( xPos, m_textPos.y() - yadjust, nWidth, nHeight );
this->asSetBoundingRect(rect);
}
// A simple function.
static int __toInt__( bool v )
{
if( v ){ return 1; }
return 0;
}
// Gets the byte array for this text run.
QByteArray AsTextRun::asToByteArray() const
{
QByteArray ret;
ret.append( this->m_sText.toUtf8() );
ret.append( this->m_sFontFamily.toUtf8() );
ret.append( QByteArray::number( this->m_nLineNumber ) );
ret.append( QByteArray::number( this->m_nFontWeight ) );
ret.append( QByteArray::number( this->m_nFontSize ) );
ret.append( QByteArray::number( this->m_textPos.x() ) );
ret.append( QByteArray::number( this->m_textPos.y() ) );
// ret.append( QByteArray::number( this->m_cTextColor.value() ) );
ret.append( QByteArray::number( __toInt__( this->m_bFontItalic ) ) );
ret.append( QByteArray::number( __toInt__( this->m_bFontUnderline ) ) );
ret.append( QByteArray::number( __toInt__( this->m_bFontStrikeOut ) ) );
// ret.append( QByteArray::number( ( int )this->m_eValign ) );
ret.append( QByteArray::number( ( int )this->m_eAlignment ) );
return ret;
}
bool AsTextRun::asIsMisspelltWord(void) const
{
return m_bMisspelltWord;
}
void AsTextRun::asSetMisspelltWord(bool misspellt)
{
m_bMisspelltWord = misspellt;
}
QString AsTextRun::getPropertyNameById(int nID)
{
return m_lProperties().key(AsEnumProperty(nID));
}
int AsTextRun::getPropertyIdByName(QString name) const
{
return m_lProperties().value(name);
}
QString AsTextRun::typeName()
{
return "textRun";
}