update dev300-m58
[ooovba.git] / applied_patches / 0084-vcl-kerning-fix.diff
blob6f5fff937a287590a8a11d935513a21617226f68
1 --- vcl/source/glyphs/gcach_layout.cxx 2009-08-11 12:51:42.000000000 +0200
2 +++ vcl/source/glyphs/gcach_layout.cxx 2009-08-13 15:51:34.000000000 +0200
3 @@ -36,6 +36,8 @@
4 #include <vcl/sallayout.hxx>
5 #include <vcl/salgdi.hxx>
7 +#include <unicode/uchar.h>
9 #include <vcl/svapp.hxx>
11 #include <sal/alloca.h>
12 @@ -110,7 +112,12 @@
13 int nGlyphWidth = 0;
14 GlyphItem aPrevItem;
15 bool bRightToLeft;
16 - for( int nCharPos = -1; rArgs.GetNextPos( &nCharPos, &bRightToLeft ); )
18 + int nCharPos = -1;
19 + bool hasNextPos = rArgs.GetNextPos( &nCharPos, &bRightToLeft );
20 + bool isAfterEnd = false;
21 + bool bFoundPrintable = false;
22 + while ( hasNextPos || ( isAfterEnd && ( !bFoundPrintable || nCharPos < rArgs.mnLength ) ) )
24 sal_UCS4 cChar = rArgs.mpStr[ nCharPos ];
25 if( (cChar >= 0xD800) && (cChar <= 0xDFFF) )
26 @@ -123,33 +130,68 @@
28 if( bRightToLeft )
29 cChar = GetMirroredChar( cChar );
30 - int nGlyphIndex = rFont.GetGlyphIndex( cChar );
31 - // when glyph fallback is needed update LayoutArgs
32 - if( !nGlyphIndex ) {
33 - rArgs.NeedFallback( nCharPos, bRightToLeft );
34 - if( cChar >= 0x10000 ) // handle surrogate pairs
35 - rArgs.NeedFallback( nCharPos+1, bRightToLeft );
36 - }
38 - // apply pair kerning to prev glyph if requested
39 - if( SAL_LAYOUT_KERNING_PAIRS & rArgs.mnFlags )
40 + // Only handle the printable characters
41 + if ( u_isprint( UChar32( cChar ) ) )
43 - int nKernValue = rFont.GetGlyphKernValue( nOldGlyphId, nGlyphIndex );
44 - nGlyphWidth += nKernValue;
45 - aPrevItem.mnNewWidth = nGlyphWidth;
46 + int nGlyphIndex = rFont.GetGlyphIndex( cChar );
47 + // when glyph fallback is needed update LayoutArgs
48 + if( !nGlyphIndex )
49 + {
50 + rArgs.NeedFallback( nCharPos, bRightToLeft );
51 + if( cChar >= 0x10000 ) // handle surrogate pairs
52 + rArgs.NeedFallback( nCharPos+1, bRightToLeft );
53 + }
55 + // apply pair kerning to prev glyph if requested
56 + if( SAL_LAYOUT_KERNING_PAIRS & rArgs.mnFlags )
57 + {
58 + int nKernValue = rFont.GetGlyphKernValue( nOldGlyphId, nGlyphIndex );
59 + nGlyphWidth += nKernValue;
60 + aPrevItem.mnNewWidth = nGlyphWidth;
61 + }
63 + // finish previous glyph
64 + if( nOldGlyphId >= 0 )
65 + {
66 + rLayout.AppendGlyph( aPrevItem );
67 + }
69 + aNewPos.X() += nGlyphWidth;
71 + // prepare GlyphItem for appending it in next round
72 + if ( !isAfterEnd )
73 + {
74 + nOldGlyphId = nGlyphIndex;
75 + const GlyphMetric& rGM = rFont.GetGlyphMetric( nGlyphIndex );
76 + nGlyphWidth = rGM.GetCharWidth();
77 + int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
79 + aPrevItem = GlyphItem( nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nGlyphWidth );
80 + }
82 + // No need to signal the printable chars before the end of the runs
83 + bFoundPrintable = isAfterEnd;
86 - // finish previous glyph
87 - if( nOldGlyphId >= 0 )
88 - rLayout.AppendGlyph( aPrevItem );
89 - aNewPos.X() += nGlyphWidth;
91 - // prepare GlyphItem for appending it in next round
92 - nOldGlyphId = nGlyphIndex;
93 - const GlyphMetric& rGM = rFont.GetGlyphMetric( nGlyphIndex );
94 - nGlyphWidth = rGM.GetCharWidth();
95 - int nGlyphFlags = bRightToLeft ? GlyphItem::IS_RTL_GLYPH : 0;
96 - aPrevItem = GlyphItem( nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nGlyphWidth );
97 + if ( !isAfterEnd )
98 + {
99 + // Check if we have some more characters
100 + // Get the next position
101 + hasNextPos = rArgs.GetNextPos( &nCharPos, &bRightToLeft );
103 + if ( !hasNextPos && nCharPos < rArgs.mnLength )
104 + isAfterEnd = true;
105 + }
106 + else
108 + nCharPos++;
109 + if ( bFoundPrintable )
111 + isAfterEnd = false;
112 + nOldGlyphId = -1;
117 // append last glyph item if any