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
|
/*************************************************************************
*
* $RCSfile: xfont.cxx,v $
*
* $Revision: 1.25 $
*
* last change: $Author: hr $ $Date: 2003-03-27 17:58:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <salunx.h>
#ifndef EXTENDED_FONTSTRUCT_HXX
#include "xfont.hxx"
#endif
#ifndef XLFD_EXTENDED_HXX
#include "xlfd_extd.hxx"
#endif
#ifndef SAL_CONVERTER_CACHE_HXX_
#include "salcvt.hxx"
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef _SV_OUTFONT_HXX
#include <outfont.hxx>
#endif
#ifndef _SV_SALGDI_HXX
#include <salgdi.hxx>
#endif
#ifdef DEBUG
#include <cstdio>
#endif
#include <algorithm>
#define VCLASS_ROTATE 0
#define VCLASS_ROTATE_REVERSE 1
#define VCLASS_TRANSFORM1 2
#define VCLASS_TRANSFORM2 3
#define VCLASS_CJK 4
#define VCLASS_DONTKNOW 5
#define VCLASS_FONT_NUM 2 // Other than rotate and rotate_reverse,
// don't have spacial font
ExtendedFontStruct::ExtendedFontStruct( Display* pDisplay, unsigned short nPixelSize,
sal_Bool bVertical, ExtendedXlfd* pXlfd ) :
mpDisplay( pDisplay ),
mnPixelSize( nPixelSize ),
mbVertical( bVertical ),
mpXlfd( pXlfd ),
mnCachedEncoding( RTL_TEXTENCODING_DONTKNOW )
{
mnAsciiEncoding = GetAsciiEncoding (NULL);
mnDefaultWidth = GetDefaultWidth();
mpXFontStruct = (XFontStruct**)calloc( mpXlfd->NumEncodings(),
sizeof(XFontStruct*) );
}
ExtendedFontStruct::~ExtendedFontStruct()
{
for ( int nIdx = 0; nIdx < mpXlfd->NumEncodings(); nIdx++ )
if ( mpXFontStruct[nIdx] != NULL )
XFreeFont( mpDisplay, mpXFontStruct[nIdx] );
}
rtl_TextEncoding
ExtendedFontStruct::GetAsciiEncoding( int *pAsciiRange ) const
{
return mpXlfd->GetAsciiEncoding( pAsciiRange );
}
FontPitch
ExtendedFontStruct::GetSpacing( rtl_TextEncoding nEncoding )
{
return mpXlfd->GetSpacing( nEncoding );
}
static XFontStruct*
LoadXFont (Display* pDisplay, const char* pFontName)
{
XFontStruct* pFont = XLoadQueryFont (pDisplay, pFontName);
if ((pFont != NULL) && (pFont->fid == 0))
pFont->fid = XLoadFont(pDisplay, pFontName);
return pFont;
}
int
ExtendedFontStruct::LoadEncoding( rtl_TextEncoding nEncoding )
{
int nIdx = mpXlfd->GetEncodingIdx( nEncoding );
if ( (nIdx < 0) || (mpXFontStruct[ nIdx ] != NULL) )
return nIdx;
ByteString aFontName;
mpXlfd->ToString( aFontName, mnPixelSize, nEncoding );
mpXFontStruct[ nIdx ] = LoadXFont( mpDisplay, aFontName.GetBuffer() );
if (mpXFontStruct[nIdx] == NULL)
mpXFontStruct[nIdx] = LoadXFont( mpDisplay, "fixed" );
return nIdx;
}
XFontStruct*
ExtendedFontStruct::GetFontStruct( rtl_TextEncoding nEncoding )
{
int nIdx = LoadEncoding( nEncoding );
return nIdx < 0 ? NULL : mpXFontStruct[nIdx] ;
}
Bool
ExtendedFontStruct::GetFontBoundingBox( XCharStruct *pCharStruct,
int *pAscent, int *pDescent )
{
pCharStruct->lbearing = 0;
pCharStruct->rbearing = 0;
pCharStruct->width = 0;
pCharStruct->ascent = 0;
pCharStruct->descent = 0;
*pAscent = 0;
*pDescent = 0;
int nIdx;
// check if there is at least one encoding already loaded
Bool bEmpty = True;
for ( nIdx = 0; nIdx < mpXlfd->NumEncodings(); nIdx++ )
bEmpty = bEmpty && (mpXFontStruct[nIdx] == NULL);
if ( bEmpty )
LoadEncoding( mpXlfd->GetAsciiEncoding() );
// get the max bounding box from all font structs
for ( nIdx = 0; nIdx < mpXlfd->NumEncodings(); nIdx++ )
if ( mpXFontStruct[ nIdx ] != NULL )
{
*pAscent = std::max( mpXFontStruct[nIdx]->ascent, *pAscent );
*pDescent = std::max( mpXFontStruct[nIdx]->descent, *pDescent );
XCharStruct* pMaxBounds = &(mpXFontStruct[nIdx]->max_bounds);
pCharStruct->lbearing = std::max( pMaxBounds->lbearing,
pCharStruct->lbearing );
pCharStruct->rbearing = std::max( pMaxBounds->rbearing,
pCharStruct->rbearing );
pCharStruct->width = std::max( pMaxBounds->width,
pCharStruct->width );
pCharStruct->ascent = std::max( pMaxBounds->ascent,
pCharStruct->ascent );
pCharStruct->descent = std::max( pMaxBounds->descent,
pCharStruct->descent );
}
return (pCharStruct->width > 0);
}
Bool
ExtendedFontStruct::ToImplFontMetricData(ImplFontMetricData *pFontMetric)
{
pFontMetric->mnOrientation = 0;
pFontMetric->mnSlant = 0;
pFontMetric->mbDevice = TRUE;
pFontMetric->meCharSet = mpXlfd->GetEncoding( );
pFontMetric->meFamily = mpXlfd->GetFamily();
pFontMetric->meWeight = mpXlfd->GetWeight();
pFontMetric->mePitch = mpXlfd->GetSpacing();
pFontMetric->meItalic = mpXlfd->GetItalic();
pFontMetric->meType = mpXlfd->GetFontType();
int nAscent, nDescent;
XCharStruct aBoundingBox;
if ( GetFontBoundingBox(&aBoundingBox, &nAscent, &nDescent) )
{
pFontMetric->mnWidth = aBoundingBox.width;
pFontMetric->mnAscent = aBoundingBox.ascent;
pFontMetric->mnDescent = aBoundingBox.descent;
pFontMetric->mnLeading = std::max(0, aBoundingBox.ascent - nAscent
+ aBoundingBox.descent - nDescent );
// XXX Fix me
pFontMetric->mnFirstChar = 0;
pFontMetric->mnLastChar = 255;
return True;
}
else
{
return False;
}
}
Bool
ExtendedFontStruct::Match( const ExtendedXlfd *pXlfd,
int nPixelSize, sal_Bool bVertical ) const
{
if( mpXlfd != pXlfd )
return FALSE;
return (mnPixelSize == nPixelSize) && (mbVertical == bVertical);
}
// Get an appropriate x-font that contains a glyph for the given unicode
// code point.
// This routine is designed to be called for each character in a text.
// It first checks the given encoding to optimize for the fact that two
// adjacent characters in a text most probably have the same encoding
// In the first call initialize pEncodingInOut to dontknow, this causes
// EncodingHasChar() to fail and thus bootstraps the encoding, otherwise
// make sure that the initial value of pFontInOut matches the encoding and
// that the encoding is valid for the font.
XFontStruct*
ExtendedFontStruct::GetFontStruct( sal_Unicode nChar, rtl_TextEncoding *pEncoding )
{
SalConverterCache *pCvt = SalConverterCache::GetInstance();
if ( pCvt->EncodingHasChar(mnAsciiEncoding, nChar) )
{
*pEncoding = mnAsciiEncoding;
return GetFontStruct (mnAsciiEncoding);
}
else
if ( pCvt->EncodingHasChar(mnCachedEncoding, nChar) )
{
*pEncoding = mnCachedEncoding;
return GetFontStruct (mnCachedEncoding);
}
else
{
for ( int nIdx = 0; nIdx < mpXlfd->NumEncodings(); nIdx++ )
{
rtl_TextEncoding nEnc = mpXlfd->GetEncoding(nIdx);
if ( (nEnc != mnCachedEncoding) && (nEnc != mnAsciiEncoding)
&& pCvt->EncodingHasChar(nEnc, nChar))
{
mnCachedEncoding = nEnc;
*pEncoding = mnCachedEncoding;
return GetFontStruct (mnCachedEncoding);
}
}
}
*pEncoding = RTL_TEXTENCODING_DONTKNOW;
return NULL;
}
// ---------------------------------------------------------------------------
// utility functions to handle xfontstruct information, this is all to
// calculate charwidth information
// ---------------------------------------------------------------------------
static Bool
CharExists( const XCharStruct* pChar )
{
if ( pChar == NULL )
return False;
return pChar->width
|| pChar->ascent || pChar->descent
|| pChar->lbearing || pChar->rbearing;
}
// this relies on non-null per_char information in the fontstruct
static XCharStruct*
GetCharinfo( const XFontStruct *pXFontStruct, sal_MultiByte nChar )
{
unsigned int nRow = nChar >> 8;
unsigned int nCol = nChar & 0xFF;
int nMinRow = pXFontStruct->min_byte1;
int nMaxRow = pXFontStruct->max_byte1;
int nMinCol = pXFontStruct->min_char_or_byte2;
int nMaxCol = pXFontStruct->max_char_or_byte2;
if ( nRow >= nMinRow && nRow <= nMaxRow
&& nCol >= nMinCol && nCol <= nMaxCol )
{
return &pXFontStruct->per_char[
(nRow-nMinRow) * (nMaxCol-nMinCol+1) + (nCol-nMinCol) ];
}
return NULL;
}
static sal_Size
QueryCharWidth16( Display* pDisplay, XLIB_Font nFontID, sal_MultiByte nChar,
sal_Size nDefaultWidth )
{
int nDirection, nFontAscent, nFontDescent;
XCharStruct aBoundingBox;
XQueryTextExtents16( pDisplay, nFontID, (XChar2b*)&nChar, 1,
&nDirection, &nFontAscent, &nFontDescent, &aBoundingBox );
return CharExists( &aBoundingBox ) ? aBoundingBox.width : nDefaultWidth;
}
static sal_Size
QueryCharWidth8( XFontStruct* pXFontStruct, sal_Char nChar,
sal_Size nDefaultWidth )
{
int nDirection, nFontAscent, nFontDescent;
XCharStruct aBoundingBox;
XTextExtents( pXFontStruct, &nChar, 1,
&nDirection, &nFontAscent, &nFontDescent, &aBoundingBox );
return CharExists( &aBoundingBox ) ? aBoundingBox.width : nDefaultWidth;
}
sal_Size
ExtendedFontStruct::GetDefaultWidth()
{
return (mnPixelSize + 1) / 2;
}
// Handle single byte fonts which do not require conversion, this exploits
// the fact that unicode equals latin1 or ansi1252 in the range [0..0xff] and
// is compatible with iso8859-X at least in the range to 0x7f
sal_Size
ExtendedFontStruct::GetCharWidth8( sal_Unicode nFrom, sal_Unicode nTo,
long *pWidthArray, rtl_TextEncoding nEncoding )
{
if ( !(nFrom <= nTo) )
return 0;
XFontStruct* pXFontStruct = GetFontStruct( nEncoding );
if ( pXFontStruct == NULL )
return 0;
// query the font metrics
if ( (pXFontStruct->max_bounds.width == pXFontStruct->min_bounds.width)
|| (pXFontStruct->per_char == NULL) )
{
// fixed width font
for ( int nIdx = nFrom; nIdx <= nTo; nIdx++, pWidthArray++ )
*pWidthArray = pXFontStruct->max_bounds.width;
}
else
{
// variable width font
int nMinChar = pXFontStruct->min_char_or_byte2;
int nMaxChar = pXFontStruct->max_char_or_byte2;
int nIdx = nFrom;
for ( ; nIdx < std::min((int)nTo, nMinChar); nIdx++, pWidthArray++ )
*pWidthArray = mnDefaultWidth;
for ( ; nIdx <= std::min((int)nTo, nMaxChar); nIdx++, pWidthArray++ )
{
XCharStruct* pChar = &(pXFontStruct->per_char[nIdx - nMinChar]);
*pWidthArray = CharExists(pChar) ? pChar->width : mnDefaultWidth;
}
for ( ; nIdx <= nTo; nIdx++, pWidthArray++ )
*pWidthArray = mnDefaultWidth;
}
// return amount of handled chars
return nTo - nFrom + 1;
}
// Handle utf16 encoded fonts, which do not require conversion
sal_Size
ExtendedFontStruct::GetCharWidthUTF16( sal_Unicode nFrom, sal_Unicode nTo,
long *pWidthArray )
{
if ( !(nFrom <= nTo) )
return 0;
XFontStruct* pXFontStruct = GetFontStruct( RTL_TEXTENCODING_UNICODE );
FontPitch nSpacing = mpXlfd->GetSpacing( RTL_TEXTENCODING_UNICODE );
if ( pXFontStruct == NULL )
return 0;
// query the font metrics
if ( nSpacing == PITCH_VARIABLE
&& pXFontStruct->per_char == NULL)
{
// get per_char information from the server
for ( sal_Int32 nIdx = nFrom; nIdx <= nTo; nIdx++, pWidthArray++ )
*pWidthArray = QueryCharWidth16( mpDisplay, pXFontStruct->fid,
nIdx, mnDefaultWidth );
}
else
if ( (pXFontStruct->max_bounds.width == pXFontStruct->min_bounds.width)
|| (pXFontStruct->per_char == NULL) )
{
// really a fixed width font
for ( sal_Int32 nIdx = nFrom; nIdx <= nTo; nIdx++, pWidthArray++ )
*pWidthArray = pXFontStruct->max_bounds.width;
}
else
{
// get per_char information from the xfontstruct
for ( sal_Int32 nIdx = nFrom; nIdx <= nTo; nIdx++, pWidthArray++ )
{
XCharStruct* pChar = GetCharinfo( pXFontStruct, nIdx );
*pWidthArray = CharExists(pChar) ? pChar->width : mnDefaultWidth;
}
}
// return amount of handled chars
return nTo - nFrom + 1;
}
// handle non unicode fonts that are converted into encoding matching the
// font in fontstruct, 8 and 16 bit fonts are handled the same way
sal_Size
ExtendedFontStruct::GetCharWidth16( sal_Unicode nFrom, sal_Unicode nTo,
long *pWidthArray, ExtendedFontStruct *pFallback )
{
if ( !(nFrom <= nTo) )
return 0;
sal_Char pBuffer[16];
sal_MultiByte nChar;
SalConverterCache *pCvt = SalConverterCache::GetInstance();
for ( sal_Int32 nIdx = nFrom ; nIdx <= nTo ; nIdx++, pWidthArray++ )
{
FontPitch nSpacing;
sal_Size nSize;
sal_Unicode nUniIdx = (sal_Unicode)nIdx;
// get a matching fontstruct
rtl_TextEncoding nEnc;
XFontStruct *pFont;
if ( (pFont = GetFontStruct(nUniIdx, &nEnc)) != NULL )
{
nSpacing = GetSpacing( nEnc );
}
else
if ( (pFallback != NULL)
&& ((pFont = pFallback->GetFontStruct(nUniIdx, &nEnc)) != NULL) )
{
nSpacing = pFallback->GetSpacing( nEnc );
}
else
if ( (pFallback != NULL)
&& ((pFont = pFallback->GetFontStruct(nUniIdx = '?', &nEnc)) != NULL) )
{
nSpacing = pFallback->GetSpacing( nEnc );
}
if ( pFont )
{
nSize = pCvt->ConvertStringUTF16(&nUniIdx, 1, pBuffer, sizeof(pBuffer), nEnc);
// XXX FIXME
if ((nEnc == RTL_TEXTENCODING_GB_2312) || (nEnc == RTL_TEXTENCODING_EUC_KR))
{
for (int n_char = 0; n_char < nSize; n_char++ )
pBuffer[ n_char ] &= 0x7F;
}
}
// query font metrics
if ( pFont && (nSize == 1 || nSize == 2) )
{
nChar = nSize == 1 ? (unsigned char)pBuffer[0] :
((sal_MultiByte)pBuffer[0] << 8) + (sal_MultiByte)pBuffer[1];
if ( nSpacing == PITCH_VARIABLE
&& pFont->per_char == NULL)
{
// get per_char information from the x-server
*pWidthArray = QueryCharWidth16( mpDisplay, pFont->fid,
nChar, mnDefaultWidth );
}
else
if ( (pFont->max_bounds.width == pFont->min_bounds.width)
|| (pFont->per_char == NULL) )
{
// fixed width font
*pWidthArray = pFont->max_bounds.width;
}
else
{
// get per_char information from the xfontstruct
XCharStruct* pChar = GetCharinfo( pFont, nChar );
*pWidthArray = CharExists(pChar) ? pChar->width : mnDefaultWidth;
}
}
else
{
// conversion error
*pWidthArray = mnDefaultWidth;
}
}
// return amount of handled chars
return nTo - nFrom + 1;
}
sal_Size
ExtendedFontStruct::GetCharWidth( sal_Unicode nFrom, sal_Unicode nTo, long *pWidthArray,
ExtendedFontStruct *pFallback )
{
int nAsciiRange;
sal_Size nConverted = 0;
rtl_TextEncoding nEncoding = mpXlfd->GetAsciiEncoding(&nAsciiRange);
// dispatch querying of metrics to most promising encoding candidate
if ( nEncoding == RTL_TEXTENCODING_UNICODE )
{
// if we have a unicode encoded system font than we get the charwidth
// straight forward
nConverted = GetCharWidthUTF16( nFrom, nTo, pWidthArray );
}
else
{
if ( nFrom < nAsciiRange )
{
// optimize the most frequent case, requesting only the latin1
// chars which are mappable to a single encoding
sal_Unicode nMinTo = std::min(nAsciiRange, (int)nTo);
nConverted = GetCharWidth8( nFrom, nMinTo, pWidthArray, nEncoding );
}
// if further requests are pending, then the according unicode
// codepoint has to be dispatched to one of the system fonts and
// converted to this fonts encoding
nConverted += GetCharWidth16( nFrom + nConverted, nTo, pWidthArray + nConverted,
pFallback );
}
return nConverted;
}
ULONG ExtendedFontStruct::GetFontCodeRanges( sal_uInt32* pCodePairs ) const
{
ULONG nRangeCount = 0;
// TODO: get better info
// problems are 1) the X Server will lie about monospaced fonts
// and 2) translation into unicode and query for every unicode char is very costly
if( RTL_TEXTENCODING_SYMBOL == mpXlfd->GetEncoding() )
{
// postscript symbol font
nRangeCount = 1;
if( pCodePairs )
{
pCodePairs[ 0 ] = 0xF020;
pCodePairs[ 1 ] = 0xF100;
}
}
return nRangeCount;
}
static short
GetVerticalClass( sal_Unicode nChar )
{
if ( (nChar >= 0x1100 && nChar <= 0x11f9) || // Hangul Jamo
(nChar >= 0x3000 && nChar <= 0xfaff) ) // other CJK
{
if ( nChar == 0x2010 || nChar == 0x2015 ||
nChar == 0x2016 || nChar == 0x2026 ||
(nChar >= 0x3008 && nChar <= 0x3017) ||
nChar >= 0xFF00 )
{
return VCLASS_ROTATE;
}
else
if ( nChar == 0x3001 || nChar == 0x3002 )
{
return VCLASS_TRANSFORM1;
}
else
if ( nChar == 0x3041 || nChar == 0x3043 ||
nChar == 0x3045 || nChar == 0x3047 ||
nChar == 0x3049 || nChar == 0x3063 ||
nChar == 0x3083 || nChar == 0x3085 ||
nChar == 0x3087 || nChar == 0x308e ||
nChar == 0x30a1 || nChar == 0x30a3 ||
nChar == 0x30a5 || nChar == 0x30a7 ||
nChar == 0x30a9 || nChar == 0x30c3 ||
nChar == 0x30e3 || nChar == 0x30e5 ||
nChar == 0x30e7 || nChar == 0x30ee ||
nChar == 0x30f5 || nChar == 0x30f6 )
{
return VCLASS_TRANSFORM2;
}
else
if ( nChar == 0x30fc )
{
return VCLASS_ROTATE_REVERSE;
}
return VCLASS_CJK;
}
return VCLASS_ROTATE;
}
// =======================================================================
X11FontLayout::X11FontLayout( ExtendedFontStruct& rFont )
: mrFont( rFont )
{}
// -----------------------------------------------------------------------
bool X11FontLayout::LayoutText( ImplLayoutArgs& rArgs )
{
SetOrientation( 0 ); // X11 fonts are to be rotated in upper layers
Point aNewPos( 0, 0 );
int nGlyphCount = 0;
for(;; ++nGlyphCount )
{
int nCharPos;
bool bRightToLeft;
if( !rArgs.GetNextPos( &nCharPos, &bRightToLeft ) )
break;
sal_Unicode cChar = rArgs.mpStr[ nCharPos ];
if( bRightToLeft )
cChar = GetMirroredChar( cChar );
// request fallback glyph if necessary
if( IsNotdefGlyph( cChar ) )
rArgs.NeedFallback( nCharPos, bRightToLeft );
long nGlyphWidth;
mrFont.GetCharWidth( cChar, cChar, &nGlyphWidth, NULL );
int nGlyphFlags = (nGlyphWidth > 0) ? 0 : GlyphItem::IS_IN_CLUSTER;
if( bRightToLeft )
nGlyphFlags |= GlyphItem::IS_RTL_GLYPH;
int nGlyphIndex = cChar | GF_ISCHAR;
GlyphItem aGI( nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nGlyphWidth );
AppendGlyph( aGI );
aNewPos.X() += nGlyphWidth;
}
return (nGlyphCount > 0);
}
// -----------------------------------------------------------------------
void X11FontLayout::DrawText( SalGraphics& rSalGraphics ) const
{
static const int MAXGLYPHS = 160;
int nMaxGlyphs = GetOrientation() ? 1 : MAXGLYPHS;
Point aPos;
long aGlyphAry[ MAXGLYPHS ];
sal_Unicode pStr[ MAXGLYPHS ];
for( int nStart=0;;)
{
int nGlyphCount = GetNextGlyphs( nMaxGlyphs, aGlyphAry, aPos, nStart );
if( !nGlyphCount )
break;
for( int i = 0; i < nGlyphCount; ++i )
pStr[ i ] = aGlyphAry[ i ] & GF_IDXMASK;
rSalGraphics.maGraphicsData.DrawStringUCS2MB( mrFont, aPos, pStr, nGlyphCount );
}
}
// -----------------------------------------------------------------------
bool X11FontLayout::IsNotdefGlyph( long nGlyphIndex ) const
{
// TODO: find less costly alternative, e.g. cache info
if( !(nGlyphIndex & GF_ISCHAR) )
return false;
XFontStruct* pXFontStruct = mrFont.GetFontStruct( RTL_TEXTENCODING_UNICODE );
if( !pXFontStruct )
return false;
sal_MultiByte nChar = nGlyphIndex & GF_IDXMASK;
XCharStruct* pCharStruct = ::GetCharinfo( pXFontStruct, nChar );
if( !pCharStruct )
return false;
Bool bRet = CharExists( pCharStruct );
return (bRet == 0);
}
// =======================================================================
|