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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
#include <lib/gdi/font.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
// use this for init Freetype...
#include <ft2build.h>
#include FT_FREETYPE_H
#include <lib/base/eerror.h>
#include <lib/gdi/lcd.h>
#include <lib/gdi/grc.h>
#include <lib/base/elock.h>
#include <lib/base/init.h>
#include <lib/base/init_num.h>
//#define HAVE_FRIBIDI
// until we have it in the cdk
#ifdef HAVE_FRIBIDI
#include <fribidi/fribidi.h>
#endif
#include <map>
fontRenderClass *fontRenderClass::instance;
static pthread_mutex_t ftlock=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
static pthread_mutex_t refcntlck=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
static FTC_Font cache_current_font=0;
struct fntColorCacheKey
{
gRGB start, end;
fntColorCacheKey(const gRGB &start, const gRGB &end)
: start(start), end(end)
{
}
bool operator <(const fntColorCacheKey &c) const
{
if (start < c.start)
return 1;
else if (start == c.start)
return end < c.end;
return 0;
}
};
std::map<fntColorCacheKey,gLookup> colorcache;
static gLookup &getColor(const gPalette &pal, const gRGB &start, const gRGB &end)
{
fntColorCacheKey key(start, end);
std::map<fntColorCacheKey,gLookup>::iterator i=colorcache.find(key);
if (i != colorcache.end())
return i->second;
gLookup &n=colorcache.insert(std::pair<fntColorCacheKey,gLookup>(key,gLookup())).first->second;
// eDebug("[FONT] creating new font color cache entry %02x%02x%02x%02x .. %02x%02x%02x%02x", start.a, start.r, start.g, start.b,
// end.a, end.r, end.g, end.b);
n.build(16, pal, start, end);
// for (int i=0; i<16; i++)
// eDebugNoNewLine("%02x|%02x%02x%02x%02x ", (int)n.lookup[i], pal.data[n.lookup[i]].a, pal.data[n.lookup[i]].r, pal.data[n.lookup[i]].g, pal.data[n.lookup[i]].b);
// eDebug("");
return n;
}
fontRenderClass *fontRenderClass::getInstance()
{
return instance;
}
FT_Error myFTC_Face_Requester(FTC_FaceID face_id,
FT_Library library,
FT_Pointer request_data,
FT_Face* aface)
{
return ((fontRenderClass*)request_data)->FTC_Face_Requester(face_id, aface);
}
FT_Error fontRenderClass::FTC_Face_Requester(FTC_FaceID face_id, FT_Face* aface)
{
fontListEntry *font=(fontListEntry *)face_id;
if (!font)
return -1;
// eDebug("[FONT] FTC_Face_Requester (%s)", font->face.c_str());
int error;
if ((error=FT_New_Face(library, font->filename.c_str(), 0, aface)))
{
eDebug(" failed: %s", strerror(error));
return error;
}
FT_Select_Charmap(*aface, ft_encoding_unicode);
return 0;
}
FTC_FaceID fontRenderClass::getFaceID(const std::string &face)
{
for (fontListEntry *f=font; f; f=f->next)
{
if (f->face == face)
return (FTC_FaceID)f;
}
return 0;
}
FT_Error fontRenderClass::getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit)
{
FT_Error res=FTC_SBit_Cache_Lookup(sbitsCache, font, glyph_index, sbit);
return res;
}
std::string fontRenderClass::AddFont(const std::string &filename, const std::string &name, int scale)
{
eDebugNoNewLine("[FONT] adding font %s...", filename.c_str());
fflush(stdout);
int error;
fontListEntry *n=new fontListEntry;
n->scale=scale;
FT_Face face;
singleLock s(ftlock);
if ((error=FT_New_Face(library, filename.c_str(), 0, &face)))
eFatal(" failed: %s", strerror(error));
n->filename=filename;
n->face=name;
FT_Done_Face(face);
n->next=font;
eDebug("OK (%s)", n->face.c_str());
font=n;
return n->face;
}
fontRenderClass::fontListEntry::~fontListEntry()
{
}
fontRenderClass::fontRenderClass(): fb(fbClass::getInstance())
{
instance=this;
eDebug("[FONT] initializing lib...");
{
if (FT_Init_FreeType(&library))
{
eDebug("[FONT] initializing failed.");
return;
}
}
eDebug("[FONT] loading fonts...");
fflush(stdout);
font=0;
int maxbytes=4*1024*1024;
eDebug("[FONT] Intializing font cache, using max. %dMB...", maxbytes/1024/1024);
fflush(stdout);
{
if (FTC_Manager_New(library, 8, 8, maxbytes, myFTC_Face_Requester, this, &cacheManager))
{
eDebug("[FONT] initializing font cache failed!");
return;
}
if (!cacheManager)
{
eDebug("[FONT] initializing font cache manager error.");
return;
}
if (FTC_SBit_Cache_New(cacheManager, &sbitsCache))
{
eDebug("[FONT] initializing font cache sbit failed!");
return;
}
if (FTC_Image_Cache_New(cacheManager, &imageCache))
{
eDebug("[FONT] initializing font cache imagecache failed!");
}
}
return;
}
float fontRenderClass::getLineHeight(const gFont& font)
{
if (!instance)
return 0;
ePtr<Font> fnt;
getFont(fnt, font.family.c_str(), font.pointSize);
if (!fnt)
return 0;
singleLock s(ftlock);
FT_Face current_face;
if (FTC_Manager_Lookup_Size(cacheManager, &fnt->font.font, ¤t_face, &fnt->size)<0)
{
delete fnt;
eDebug("FTC_Manager_Lookup_Size failed!");
return 0;
}
int linegap=current_face->size->metrics.height-(current_face->size->metrics.ascender+current_face->size->metrics.descender);
float height=(current_face->size->metrics.ascender+current_face->size->metrics.descender+linegap/2.0)/64;
delete fnt;
return height;
}
fontRenderClass::~fontRenderClass()
{
singleLock s(ftlock);
while(font)
{
fontListEntry *f=font;
font=font->next;
delete f;
}
// auskommentiert weil freetype und enigma die kritische masse des suckens ueberschreiten.
// FTC_Manager_Done(cacheManager);
// FT_Done_FreeType(library);
}
int fontRenderClass::getFont(ePtr<Font> &font, const std::string &face, int size, int tabwidth)
{
FTC_FaceID id=getFaceID(face);
if (!id)
{
font = 0;
return -1;
}
font = new Font(this, id, size * ((fontListEntry*)id)->scale / 100, tabwidth);
return 0;
}
DEFINE_REF(Font);
Font::Font(fontRenderClass *render, FTC_FaceID faceid, int isize, int tw): tabwidth(tw)
{
renderer=render;
font.font.face_id=faceid;
font.font.pix_width = isize;
font.font.pix_height = isize;
font.image_type = ftc_image_grays;
height=isize;
if (tabwidth==-1)
tabwidth=8*isize;
// font.image_type |= ftc_image_flag_autohinted;
}
FT_Error Font::getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit)
{
return renderer->getGlyphBitmap(&font, glyph_index, sbit);
}
Font::~Font()
{
}
DEFINE_REF(eTextPara);
int eTextPara::appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags)
{
FTC_SBit glyph;
if (current_font->getGlyphBitmap(glyphIndex, &glyph))
return 1;
int nx=cursor.x();
nx+=glyph->xadvance;
if (
(rflags&RS_WRAP) &&
(nx >= area.right())
)
{
int cnt = 0;
glyphString::reverse_iterator i(glyphs.rbegin());
while (i != glyphs.rend())
{
if (i->flags&(GS_ISSPACE|GS_ISFIRST))
break;
cnt++;
++i;
}
if (i != glyphs.rend()
&& ((i->flags&(GS_ISSPACE|GS_ISFIRST))==GS_ISSPACE)
&& cnt )
{
--i;
int linelength=cursor.x()-i->x;
i->flags|=GS_ISFIRST;
ePoint offset=ePoint(i->x, i->y);
newLine(rflags);
offset-=cursor;
do
{
i->x-=offset.x();
i->y-=offset.y();
i->bbox.moveBy(-offset.x(), -offset.y());
}
while (i-- != glyphs.rbegin()); // rearrange them into the next line
cursor+=ePoint(linelength, 0); // put the cursor after that line
}
else
{
if (cnt)
{
newLine(rflags);
flags|=GS_ISFIRST;
}
}
}
int xadvance=glyph->xadvance, kern=0;
if (previous && use_kerning)
{
FT_Vector delta;
FT_Get_Kerning(current_face, previous, glyphIndex, ft_kerning_default, &delta);
kern=delta.x>>6;
}
pGlyph ng;
ng.bbox.setLeft( (flags&GS_ISFIRST|cursor.x()-1)+glyph->left );
ng.bbox.setTop( cursor.y() - glyph->top );
ng.bbox.setWidth( glyph->width );
ng.bbox.setHeight( glyph->height );
xadvance+=kern;
ng.x=cursor.x()+kern;
ng.y=cursor.y();
ng.w=xadvance;
ng.font=current_font;
ng.glyph_index=glyphIndex;
ng.flags=flags;
glyphs.push_back(ng);
cursor+=ePoint(xadvance, 0);
previous=glyphIndex;
return 0;
}
void eTextPara::calc_bbox()
{
boundBox.setLeft( 32000 );
boundBox.setTop( 32000 );
boundBox.setRight( -32000 ); // for each glyph image, compute its bounding box, translate it,
boundBox.setBottom( -32000 );
// and grow the string bbox
for ( glyphString::iterator i(glyphs.begin()); i != glyphs.end(); ++i)
{
if ( i->flags & GS_ISSPACE )
continue;
if ( i->bbox.left() < boundBox.left() )
boundBox.setLeft( i->bbox.left() );
if ( i->bbox.top() < boundBox.top() )
boundBox.setTop( i->bbox.top() );
if ( i->bbox.right() > boundBox.right() )
boundBox.setRight( i->bbox.right() );
if ( i->bbox.bottom() > boundBox.bottom() )
boundBox.setBottom( i->bbox.bottom() );
}
// eDebug("boundBox left = %i, top = %i, right = %i, bottom = %i", boundBox.left(), boundBox.top(), boundBox.right(), boundBox.bottom() );
if ( glyphs.size() )
bboxValid=1;
}
void eTextPara::newLine(int flags)
{
if (maximum.width()<cursor.x())
maximum.setWidth(cursor.x());
cursor.setX(left);
previous=0;
int linegap=current_face->size->metrics.height-(current_face->size->metrics.ascender+current_face->size->metrics.descender);
cursor+=ePoint(0, (current_face->size->metrics.ascender+current_face->size->metrics.descender+linegap*1/2)>>6);
if (maximum.height()<cursor.y())
maximum.setHeight(cursor.y());
previous=0;
}
eTextPara::~eTextPara()
{
clear();
}
void eTextPara::setFont(const gFont *font)
{
ePtr<Font> fnt, replacement;
fontRenderClass::getInstance()->getFont(fnt, font->family.c_str(), font->pointSize);
if (!fnt)
eWarning("FONT '%s' MISSING!", font->family.c_str());
fontRenderClass::getInstance()->getFont(replacement, replacement_facename.c_str(), font->pointSize);
setFont(fnt, replacement);
}
std::string eTextPara::replacement_facename;
void eTextPara::setFont(Font *fnt, Font *replacement)
{
if (!fnt)
return;
current_font=fnt;
replacement_font=replacement;
singleLock s(ftlock);
// we ask for replacment_font first becauseof the cache
if (replacement_font)
{
if (FTC_Manager_Lookup_Size(fontRenderClass::instance->cacheManager,
&replacement_font->font.font, &replacement_face,
&replacement_font->size)<0)
{
eDebug("FTC_Manager_Lookup_Size failed!");
return;
}
}
if (current_font)
{
if (FTC_Manager_Lookup_Size(fontRenderClass::instance->cacheManager, ¤t_font->font.font, ¤t_face, ¤t_font->size)<0)
{
eDebug("FTC_Manager_Lookup_Size failed!");
return;
}
}
cache_current_font=¤t_font->font.font;
previous=0;
use_kerning=FT_HAS_KERNING(current_face);
}
void
shape (std::vector<unsigned long> &string, const std::vector<unsigned long> &text);
int eTextPara::renderString(const std::string &string, int rflags)
{
singleLock s(ftlock);
if (!current_font)
return -1;
if (cursor.y()==-1)
{
cursor=ePoint(area.x(), area.y()+(current_face->size->metrics.ascender>>6));
left=cursor.x();
}
if (¤t_font->font.font != cache_current_font)
{
if (FTC_Manager_Lookup_Size(fontRenderClass::instance->cacheManager, ¤t_font->font.font, ¤t_face, ¤t_font->size)<0)
{
eDebug("FTC_Manager_Lookup_Size failed!");
return -1;
}
cache_current_font=¤t_font->font.font;
}
std::vector<unsigned long> uc_string, uc_visual;
uc_string.reserve(string.length());
std::string::const_iterator p(string.begin());
while(p != string.end())
{
unsigned int unicode=(unsigned char)*p++;
if (unicode & 0x80) // we have (hopefully) UTF8 here, and we assume that the encoding is VALID
{
if ((unicode & 0xE0)==0xC0) // two bytes
{
unicode&=0x1F;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
} else if ((unicode & 0xF0)==0xE0) // three bytes
{
unicode&=0x0F;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
} else if ((unicode & 0xF8)==0xF0) // four bytes
{
unicode&=0x07;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
unicode<<=6;
if (p != string.end())
unicode|=(*p++)&0x3F;
}
}
uc_string.push_back(unicode);
}
std::vector<unsigned long> uc_shape;
// character -> glyph conversion
shape(uc_shape, uc_string);
// now do the usual logical->visual reordering
#ifdef HAVE_FRIBIDI
FriBidiCharType dir=FRIBIDI_TYPE_ON;
{
int size=uc_shape.size();
uc_visual.resize(size);
// gaaanz lahm, aber anders geht das leider nicht, sorry.
FriBidiChar array[size], target[size];
std::copy(uc_shape.begin(), uc_shape.end(), array);
fribidi_log2vis(array, size, &dir, target, 0, 0, 0);
uc_visual.assign(target, target+size);
}
#else
uc_visual=uc_shape;
#endif
glyphs.reserve(uc_visual.size());
int nextflags = 0;
for (std::vector<unsigned long>::const_iterator i(uc_visual.begin());
i != uc_visual.end(); ++i)
{
int isprintable=1;
int flags = nextflags;
nextflags = 0;
if (!(rflags&RS_DIRECT))
{
switch (*i)
{
case '\\':
{
unsigned long c = *(i+1);
switch (c)
{
case 'n':
i++;
goto newline;
case 't':
i++;
goto tab;
case 'r':
i++;
goto nprint;
default:
;
}
break;
}
case '\t':
tab: isprintable=0;
cursor+=ePoint(current_font->tabwidth, 0);
cursor-=ePoint(cursor.x()%current_font->tabwidth, 0);
break;
case 0x8A:
case 0xE08A:
case '\n':
newline:isprintable=0;
newLine(rflags);
nextflags|=GS_ISFIRST;
break;
case '\r':
case 0x86: case 0xE086:
case 0x87: case 0xE087:
nprint: isprintable=0;
break;
case ' ':
flags|=GS_ISSPACE;
default:
break;
}
}
if (isprintable)
{
FT_UInt index;
index=(rflags&RS_DIRECT)? *i : FT_Get_Char_Index(current_face, *i);
if (!index)
{
if (replacement_face)
index=(rflags&RS_DIRECT)? *i : FT_Get_Char_Index(replacement_face, *i);
if (!index)
eDebug("unicode %d ('%c') not present", *i, *i);
else
appendGlyph(replacement_font, replacement_face, index, flags, rflags);
} else
appendGlyph(current_font, current_face, index, flags, rflags);
}
}
bboxValid=false;
calc_bbox();
#ifdef HAVE_FRIBIDI
if (dir & FRIBIDI_MASK_RTL)
realign(dirRight);
#endif
return 0;
}
void eTextPara::blit(gDC &dc, const ePoint &offset, const gRGB &background, const gRGB &foreground)
{
singleLock s(ftlock);
if (!current_font)
return;
if (¤t_font->font.font != cache_current_font)
{
if (FTC_Manager_Lookup_Size(fontRenderClass::instance->cacheManager, ¤t_font->font.font, ¤t_face, ¤t_font->size)<0)
{
eDebug("FTC_Manager_Lookup_Size failed!");
return;
}
cache_current_font=¤t_font->font.font;
}
ePtr<gPixmap> target;
dc.getPixmap(target);
gSurface *surface = target->surface;
register int opcode;
gColor *lookup8=0;
__u32 lookup32[16];
if (surface->bpp == 8)
{
if (surface->clut.data)
{
lookup8=getColor(surface->clut, background, foreground).lookup;
opcode=0;
} else
opcode=1;
} else if (surface->bpp == 32)
{
opcode=3;
if (surface->clut.data)
{
lookup8=getColor(surface->clut, background, foreground).lookup;
for (int i=0; i<16; ++i)
lookup32[i]=((surface->clut.data[lookup8[i]].a<<24)|
(surface->clut.data[lookup8[i]].r<<16)|
(surface->clut.data[lookup8[i]].g<<8)|
(surface->clut.data[lookup8[i]].b))^0xFF000000;
} else
{
for (int i=0; i<16; ++i)
lookup32[i]=(0x010101*i)|0xFF000000;
}
} else
{
eWarning("can't render to %dbpp", surface->bpp);
return;
}
gRegion area(eRect(0, 0, surface->x, surface->y));
gRegion clip = dc.getClip() & area;
int buffer_stride=surface->stride;
for (glyphString::iterator i(glyphs.begin()); i != glyphs.end(); ++i)
{
static FTC_SBit glyph_bitmap;
if (fontRenderClass::instance->getGlyphBitmap(&i->font->font, i->glyph_index, &glyph_bitmap))
continue;
int rx=i->x+glyph_bitmap->left + offset.x();
int ry=i->y-glyph_bitmap->top + offset.y();
__u8 *d=(__u8*)(surface->data)+buffer_stride*ry+rx*surface->bypp;
__u8 *s=glyph_bitmap->buffer;
register int sx=glyph_bitmap->width;
int sy=glyph_bitmap->height;
if ((sy+ry) >= clip.extends.bottom())
sy=clip.extends.bottom()-ry;
if ((sx+rx) >= clip.extends.right())
sx=clip.extends.right()-rx;
if (rx < clip.extends.left())
{
int diff=clip.extends.left()-rx;
s+=diff;
sx-=diff;
rx+=diff;
d+=diff*surface->bypp;
}
if (ry < clip.extends.top())
{
int diff=clip.extends.top()-ry;
s+=diff*glyph_bitmap->pitch;
sy-=diff;
ry+=diff;
d+=diff*buffer_stride;
}
if (sx>0)
for (int ay=0; ay<sy; ay++)
{
if (!opcode) // 4bit lookup to 8bit
{
register __u8 *td=d;
register int ax;
for (ax=0; ax<sx; ax++)
{
register int b=(*s++)>>4;
if(b)
*td++=lookup8[b];
else
td++;
}
} else if (opcode == 1) // 8bit direct
{
register __u8 *td=d;
register int ax;
for (ax=0; ax<sx; ax++)
{
register int b=*s++;
*td++^=b;
}
} else
{
register __u32 *td=(__u32*)d;
register int ax;
for (ax=0; ax<sx; ax++)
{
register int b=(*s++)>>4;
if(b)
*td++=lookup32[b];
else
td++;
}
}
s+=glyph_bitmap->pitch-sx;
d+=buffer_stride;
}
}
}
void eTextPara::realign(int dir) // der code hier ist ein wenig merkwuerdig.
{
glyphString::iterator begin(glyphs.begin()), c(glyphs.begin()), end(glyphs.begin()), last;
if (dir==dirLeft)
return;
while (c != glyphs.end())
{
int linelength=0;
int numspaces=0, num=0;
begin=end;
ASSERT( end != glyphs.end());
// zeilenende suchen
do {
last=end;
++end;
} while ((end != glyphs.end()) && (!(end->flags&GS_ISFIRST)));
// end zeigt jetzt auf begin der naechsten zeile
for (c=begin; c!=end; ++c)
{
// space am zeilenende skippen
if ((c==last) && (c->flags&GS_ISSPACE))
continue;
if (c->flags&GS_ISSPACE)
numspaces++;
linelength+=c->w;
num++;
}
if (!num) // line mit nur einem space
continue;
switch (dir)
{
case dirRight:
case dirCenter:
{
int offset=area.width()-linelength;
if (dir==dirCenter)
offset/=2;
offset+=area.left();
while (begin != end)
{
begin->bbox.moveBy(offset-begin->x,0);
begin->x=offset;
offset+=begin->w;
++begin;
}
break;
}
case dirBlock:
{
if (end == glyphs.end()) // letzte zeile linksbuendig lassen
continue;
int spacemode;
if (numspaces)
spacemode=1;
else
spacemode=0;
if ((!spacemode) && (num<2))
break;
int off=(area.width()-linelength)*256/(spacemode?numspaces:(num-1));
int curoff=0;
while (begin != end)
{
int doadd=0;
if ((!spacemode) || (begin->flags&GS_ISSPACE))
doadd=1;
begin->x+=curoff>>8;
begin->bbox.moveBy(curoff>>8,0);
if (doadd)
curoff+=off;
++begin;
}
break;
}
}
}
bboxValid=false;
calc_bbox();
}
void eTextPara::clear()
{
singleLock s(ftlock);
current_font = 0;
replacement_font = 0;
glyphs.clear();
}
eAutoInitP0<fontRenderClass> init_fontRenderClass(eAutoInitNumbers::graphic-1, "Font Render Class");
|