summaryrefslogtreecommitdiffstats
path: root/bf_sw/source/core/txtnode/sw_fntcap.cxx
blob: e6577135a6a10363e2af0f0c7fa63c3ceca5e0aa (plain)
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#ifdef _MSC_VER
#pragma hdrstop
#endif

#include <hintids.hxx>


#include <com/sun/star/i18n/CharType.hdl>
#include <com/sun/star/i18n/WordType.hdl>

#include <vcl/print.hxx>

#include <fntcache.hxx>
#include <swfont.hxx>
#include <breakit.hxx>
namespace binfilter {

using namespace ::com::sun::star::i18n;


#define KAPITAELCHENPROP 66

/*************************************************************************
 *                      class SwCapitalInfo
 *
 * The information encapsulated in SwCapitalInfo is required
 * by the ::Do functions. They contain the information about
 * the original string, whereas rDo.GetInf() contains information
 * about the display string.
 *************************************************************************/

class SwCapitalInfo
{
public:
    explicit SwCapitalInfo( const XubString& rOrigText ) :
        rString( rOrigText ), nIdx( 0 ), nLen( 0 ) {};
    const XubString& rString;
    xub_StrLen nIdx;
    xub_StrLen nLen;
};

/*************************************************************************
 *                      xub_StrLen lcl_CalcCaseMap()
 *
 * rFnt: required for CalcCaseMap
 * rOrigString: The original string
 * nOfst: Position of the substring in rOrigString
 * nLen: Length if the substring in rOrigString
 * nIdx: Referes to a position in the display string and should be mapped
 *       to a position in rOrigString
 *************************************************************************/

xub_StrLen lcl_CalcCaseMap( const SwFont& rFnt,
                            const XubString& rOrigString,
                            xub_StrLen nOfst,
                            xub_StrLen nLen,
                            xub_StrLen nIdx )
{
    int j = 0;
    const xub_StrLen nEnd = nOfst + nLen;
    OSL_ENSURE( nEnd <= rOrigString.Len(), "lcl_CalcCaseMap: Wrong parameters" );
    // special case for title case:
    const bool bTitle = SVX_CASEMAP_TITEL == rFnt.GetCaseMap() &&
                        pBreakIt->xBreak.is();
    for ( int i = nOfst; i < nEnd; ++i )
    {
        XubString aTmp( rOrigString, i, 1 );

        if ( !bTitle ||
             pBreakIt->xBreak->isBeginWord(
                 rOrigString, i,
                 pBreakIt->GetLocale( rFnt.GetLanguage() ),
                 WordType::ANYWORD_IGNOREWHITESPACES ) )
            aTmp = rFnt.GetActualFont().CalcCaseMap( aTmp );

        j += aTmp.Len();

        if ( j > nIdx )
            return i;
    }

    return nOfst + nLen;
}

/*************************************************************************
 *                      class SwDoCapitals
 *************************************************************************/

class SwDoCapitals
{
protected:
    SwDrawTextInfo &rInf;
    SwCapitalInfo* pCapInf; // referes to additional information
                           // required by the ::Do function
    ~SwDoCapitals() {}
public:
    SwDoCapitals ( SwDrawTextInfo &rInfo ) : rInf( rInfo ), pCapInf( 0 ) { }
    virtual void Init( SwFntObj *pUpperFont, SwFntObj *pLowerFont ) = 0;
    virtual void Do() = 0;
    inline OutputDevice *GetOut() { return rInf.GetpOut(); }
    inline SwDrawTextInfo& GetInf() { return rInf; }
    inline SwCapitalInfo* GetCapInf() const { return pCapInf; }
    inline void SetCapInf( SwCapitalInfo& rNew ) { pCapInf = &rNew; }
};

/*************************************************************************
 *                    class SwDoGetCapitalSize
 *************************************************************************/

class SwDoGetCapitalSize : public SwDoCapitals
{
protected:
    Size aTxtSize;
public:
    SwDoGetCapitalSize( SwDrawTextInfo &rInfo ) : SwDoCapitals ( rInfo ) { }
    virtual ~SwDoGetCapitalSize() {}
    virtual void Init( SwFntObj *pUpperFont, SwFntObj *pLowerFont );
    virtual void Do();
    const Size &GetSize() const { return aTxtSize; }
};

/*N*/ void SwDoGetCapitalSize::Init( SwFntObj* /*pUpperFont*/, SwFntObj* /*pLowerFont*/ )
/*N*/ {
/*N*/   aTxtSize.Height() = 0;
/*N*/   aTxtSize.Width() = 0;
/*N*/ }

/*N*/ void SwDoGetCapitalSize::Do()
/*N*/ {
/*N*/   aTxtSize.Width() += rInf.GetSize().Width();
/*N*/   if( rInf.GetUpper() )
/*N*/       aTxtSize.Height() = rInf.GetSize().Height();
/*N*/ }

/*************************************************************************
 *                    SwSubFont::GetCapitalSize()
 *************************************************************************/

/*N*/ Size SwSubFont::GetCapitalSize( SwDrawTextInfo& rInf )
/*N*/ {
/*N*/   // Start:
/*N*/   short nOldKern = rInf.GetKern();
/*N*/   rInf.SetKern( CheckKerning() );
/*N*/   Point aPos;
/*N*/   rInf.SetPos( aPos );
/*N*/   rInf.SetSpace( 0 );
/*N*/   rInf.SetDrawSpace( FALSE );
/*N*/   SwDoGetCapitalSize aDo( rInf );
/*N*/   DoOnCapitals( aDo );
/*N*/   Size aTxtSize( aDo.GetSize() );
/*N*/
/*N*/   // End:
/*N*/   if( !aTxtSize.Height() )
/*N*/   {
/*N*/       SV_STAT( nGetTextSize );
/*N*/       aTxtSize.Height() = short ( rInf.GetpOut()->GetTextHeight() );
/*N*/   }
/*N*/   rInf.SetKern( nOldKern );
/*N*/   return aTxtSize;
/*N*/ }

/*************************************************************************
 *                    class SwDoGetCapitalBreak
 *************************************************************************/

class SwDoGetCapitalBreak : public SwDoCapitals
{
protected:
    xub_StrLen *pExtraPos;
    long nTxtWidth;
    xub_StrLen nBreak;
public:
    SwDoGetCapitalBreak( SwDrawTextInfo &rInfo, long nWidth, xub_StrLen *pExtra)
        : SwDoCapitals ( rInfo )
        , pExtraPos( pExtra )
        , nTxtWidth( nWidth )
        , nBreak( STRING_LEN )
        { }
    virtual ~SwDoGetCapitalBreak() {}
    xub_StrLen GetBreak() const { return nBreak; }
};



/*************************************************************************
 *                    SwFont::GetCapitalBreak()
 *************************************************************************/


/*************************************************************************
 *                     class SwDoDrawCapital
 *************************************************************************/

class SwDoDrawCapital : public SwDoCapitals
{
protected:
    SwFntObj *pUpperFnt;
    SwFntObj *pLowerFnt;
public:
    SwDoDrawCapital( SwDrawTextInfo &rInfo ) :
        SwDoCapitals( rInfo )
        { }

    virtual ~SwDoDrawCapital() {}
};



/*************************************************************************
 *                    SwDoDrawCapital::DrawSpace()
 *************************************************************************/


/*************************************************************************
 *                    SwSubFont::DrawCapital()
 *************************************************************************/


/*************************************************************************
 *                     class SwDoDrawCapital
 *************************************************************************/

class SwDoCapitalCrsrOfst : public SwDoCapitals
{
protected:
    SwFntObj *pUpperFnt;
    SwFntObj *pLowerFnt;
    xub_StrLen nCrsr;
    USHORT nOfst;
public:
    SwDoCapitalCrsrOfst( SwDrawTextInfo &rInfo, const USHORT nOfs )
        : SwDoCapitals( rInfo )
        , nCrsr( 0 )
        , nOfst( nOfs )
        { }

    virtual ~SwDoCapitalCrsrOfst() {}

    void DrawSpace( const Point &rPos );
    inline xub_StrLen GetCrsr(){ return nCrsr; }
};



/*************************************************************************
 *                    SwSubFont::GetCapitalCrsrOfst()
 *************************************************************************/


/*************************************************************************
 *                    class SwDoDrawStretchCapital
 *************************************************************************/

class SwDoDrawStretchCapital : public SwDoDrawCapital
{
    const xub_StrLen nStrLen;
    const USHORT nCapWidth;
    const USHORT nOrgWidth;
public:

    SwDoDrawStretchCapital( SwDrawTextInfo &rInfo, const USHORT nCapWidth2 )
            : SwDoDrawCapital( rInfo )
            , nStrLen( rInfo.GetLen() )
            , nCapWidth( nCapWidth2 )
            , nOrgWidth( rInfo.GetWidth() )
        { }

    virtual ~SwDoDrawStretchCapital() {}
};

/*************************************************************************
 *                  SwSubFont::DoOnCapitals() const
 *************************************************************************/

// JP 22.8.2001 - global optimization off - Bug 91245 / 91223
#ifdef _MSC_VER
#pragma optimize("g",off)
#endif

/*N*/ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
/*N*/ {
/*N*/   OSL_ENSURE( pLastFont, "SwFont::DoOnCapitals: No LastFont?!" );
/*N*/
/*N*/   Size aPartSize;
/*N*/   long nKana = 0;
/*N*/   const XubString aTxt( CalcCaseMap( rDo.GetInf().GetText() ) );
/*N*/   xub_StrLen nMaxPos = Min( USHORT(rDo.GetInf().GetText().Len()
/*N*/                           - rDo.GetInf().GetIdx()), rDo.GetInf().GetLen() );
/*N*/   rDo.GetInf().SetLen( nMaxPos );
/*N*/
/*N*/   const XubString& rOldText = rDo.GetInf().GetText();
/*N*/   rDo.GetInf().SetText( aTxt );
/*N*/   rDo.GetInf().SetSize( aPartSize );
/*N*/   xub_StrLen nPos = rDo.GetInf().GetIdx();
/*N*/   xub_StrLen nOldPos = nPos;
/*N*/   nMaxPos += nPos;
/*N*/
/*N*/   // #107816#
/*N*/   // Look if the length of the original text and the ToUpper-converted
/*N*/   // text is different. If yes, do special handling.
/*N*/   XubString aNewText;
/*N*/     SwCapitalInfo aCapInf( rOldText );
/*N*/     sal_Bool bCaseMapLengthDiffers( aTxt.Len() != rOldText.Len() );
/*N*/     if ( bCaseMapLengthDiffers )
/*N*/         rDo.SetCapInf( aCapInf );
/*N*/
/*N*/   SwFntObj *pOldLast = pLastFont;
/*N*/   SwFntAccess *pBigFontAccess = NULL;
/*N*/   SwFntObj *pBigFont;
/*N*/   SwFntAccess *pSpaceFontAccess = NULL;
/*N*/
/*N*/   const void *pMagic2 = NULL;
/*N*/   USHORT nIndex2 = 0;
/*N*/   SwSubFont aFont( *this );
/*N*/
/*N*/   const BOOL bUnderStriked = aFont.GetUnderline() != UNDERLINE_NONE
/*N*/                           || aFont.GetStrikeout() != STRIKEOUT_NONE;
/*N*/   const BOOL bWordWise = bUnderStriked && aFont.IsWordLineMode() &&
/*N*/                          rDo.GetInf().GetDrawSpace();
/*N*/   const short nKern2 = rDo.GetInf().GetKern();
/*N*/
/*N*/   if ( bUnderStriked )
/*N*/   {
/*N*/       if ( bWordWise )
/*N*/       {
/*?*/           aFont.SetWordLineMode( FALSE );
/*?*/           pSpaceFontAccess = new SwFntAccess( pMagic2, nIndex2, &aFont,
/*?*/                                               rDo.GetInf().GetShell() );
/*N*/       }
/*N*/
/*N*/       // Wir basteln uns einen Font fuer die Grossbuchstaben:
/*N*/       aFont.SetUnderline( UNDERLINE_NONE );
/*N*/       aFont.SetStrikeout( STRIKEOUT_NONE );
/*N*/       pMagic2 = NULL;
/*N*/       nIndex2 = 0;
/*N*/       pBigFontAccess = new SwFntAccess( pMagic2, nIndex2, &aFont,
/*N*/                                         rDo.GetInf().GetShell() );
/*N*/       pBigFont = pBigFontAccess->Get();
/*N*/   }
/*N*/   else
/*N*/       pBigFont = pLastFont;
/*N*/
/*N*/   // Hier entsteht der Kleinbuchstabenfont:
/*N*/   aFont.SetProportion( BYTE( (aFont.GetPropr()*KAPITAELCHENPROP) / 100L) );
/*N*/   pMagic2 = NULL;
/*N*/   nIndex2 = 0;
/*N*/   SwFntAccess *pSmallFontAccess = new SwFntAccess( pMagic2, nIndex2, &aFont,
/*N*/                                                    rDo.GetInf().GetShell() );
/*N*/   SwFntObj *pSmallFont = pSmallFontAccess->Get();
/*N*/
/*N*/   rDo.Init( pBigFont, pSmallFont );
/*N*/   OutputDevice* pOutSize = pSmallFont->GetPrt();
/*N*/   if( !pOutSize )
/*N*/       pOutSize = rDo.GetOut();
/*N*/   OutputDevice* pOldOut = rDo.GetOut();
/*N*/
/*N*/   const LanguageType eLng = LANGUAGE_DONTKNOW == GetLanguage()
/*N*/                           ? LANGUAGE_SYSTEM : GetLanguage();
/*N*/
/*N*/   if( nPos < nMaxPos )
/*N*/   {
/*N*/       nPos = (xub_StrLen)pBreakIt->xBreak->endOfCharBlock( rOldText, nPos,
/*N*/           pBreakIt->GetLocale( eLng ), CharType::LOWERCASE_LETTER);
/*N*/       if( nPos == STRING_LEN )
/*N*/           nPos = nOldPos;
/*N*/       else if( nPos > nMaxPos )
/*N*/           nPos = nMaxPos;
/*N*/   }
/*N*/
/*N*/   while( nOldPos < nMaxPos )
/*N*/   {
/*N*/
/*N*/       //  The lower ones...
/*N*/       if( nOldPos != nPos )
/*N*/       {
/*N*/           SV_STAT( nGetTextSize );
/*N*/           pLastFont = pSmallFont;
/*N*/           pLastFont->SetDevFont( rDo.GetInf().GetShell(), rDo.GetOut() );
/*N*/
/*N*/           // #107816#, #i14820#
/*N*/             if( bCaseMapLengthDiffers )
/*N*/             {
/*N*/                 // Build an own 'changed' string for the given part of the
/*N*/                 // source string and use it. That new string may differ in length
/*N*/                 // from the source string.
/*N*/                 const XubString aSnippet( rOldText, nOldPos, nPos - nOldPos);
/*N*/                 aNewText = CalcCaseMap( aSnippet );
/*N*/                 aCapInf.nIdx = nOldPos;
/*N*/                 aCapInf.nLen = nPos - nOldPos;
/*N*/                 rDo.GetInf().SetIdx( 0 );
/*N*/                 rDo.GetInf().SetLen( aNewText.Len() );
/*N*/                 rDo.GetInf().SetText( aNewText );
/*N*/             }
/*N*/           else
/*N*/           {
/*N*/               rDo.GetInf().SetIdx( nOldPos );
/*N*/               rDo.GetInf().SetLen( nPos - nOldPos );
/*N*/           }
/*N*/
/*N*/           rDo.GetInf().SetUpper( FALSE );
/*N*/           rDo.GetInf().SetOut( *pOutSize );
/*N*/           aPartSize = pSmallFont->GetTextSize( rDo.GetInf() );
/*N*/           nKana += rDo.GetInf().GetKanaDiff();
/*N*/           rDo.GetInf().SetOut( *pOldOut );
/*N*/           if( nKern2 && nPos < nMaxPos )
/*?*/               aPartSize.Width() += nKern2;
/*N*/           rDo.Do();
/*N*/           nOldPos = nPos;
/*N*/       }
/*N*/       nPos = (xub_StrLen)pBreakIt->xBreak->nextCharBlock( rOldText, nPos,
/*N*/              pBreakIt->GetLocale( eLng ), CharType::LOWERCASE_LETTER);
/*N*/       if( nPos == STRING_LEN || nPos > nMaxPos )
/*N*/           nPos = nMaxPos;
/*N*/       OSL_ENSURE( nPos, "nextCharBlock not implemented?" );
/*N*/ #ifdef DBG_UTIL
/*N*/       if( !nPos )
/*N*/           nPos = nMaxPos;
/*N*/ #endif
/*N*/       // The upper ones...
/*N*/       if( nOldPos != nPos )
/*N*/       {
/*N*/           do
/*N*/           {
/*N*/               rDo.GetInf().SetUpper( TRUE );
/*N*/               pLastFont = pBigFont;
/*N*/               pLastFont->SetDevFont( rDo.GetInf().GetShell(), rDo.GetOut() );
/*N*/               xub_StrLen nTmp;
/*N*/               if( bWordWise )
/*N*/               {
/*?*/                   nTmp = nOldPos;
/*?*/                   while( nTmp < nPos && CH_BLANK == rOldText.GetChar( nTmp ) )
/*?*/                       ++nTmp;
/*?*/                   while( nTmp < nPos && CH_BLANK != rOldText.GetChar( nTmp ) )
/*?*/                       ++nTmp;
/*N*/               }
/*N*/               else
/*N*/                   nTmp = nPos;
/*N*/               if( nTmp > nOldPos )
/*N*/               {
/*N*/                       // #107816#, #i14820#
/*N*/                     if( bCaseMapLengthDiffers )
/*N*/                     {
/*N*/                         // Build an own 'changed' string for the given part of the
/*N*/                         // source string and use it. That new string may differ in length
/*N*/                         // from the source string.
/*N*/                         const XubString aSnippet( rOldText, nOldPos, nTmp - nOldPos);
/*N*/                         aNewText = CalcCaseMap( aSnippet );
/*N*/                         aCapInf.nIdx = nOldPos;
/*N*/                         aCapInf.nLen = nTmp - nOldPos;
/*N*/                         rDo.GetInf().SetIdx( 0 );
/*N*/                         rDo.GetInf().SetLen( aNewText.Len() );
/*N*/                         rDo.GetInf().SetText( aNewText );
/*N*/                     }
/*N*/                     else
/*N*/                     {
/*N*/                         rDo.GetInf().SetIdx( nOldPos );
/*N*/                         rDo.GetInf().SetLen( nPos - nOldPos );
/*N*/                     }
/*N*/
/*N*/                   rDo.GetInf().SetOut( *pOutSize );
/*N*/                   aPartSize = pBigFont->GetTextSize( rDo.GetInf() );
/*N*/                   nKana += rDo.GetInf().GetKanaDiff();
/*N*/                   rDo.GetInf().SetOut( *pOldOut );
/*N*/                   if( !bWordWise && rDo.GetInf().GetSpace() )
/*?*/                       for( xub_StrLen nI = nOldPos; nI < nPos; ++nI )
/*?*/                           if( CH_BLANK == rOldText.GetChar( nI ) )
/*?*/                           aPartSize.Width() += rDo.GetInf().GetSpace();
/*N*/                   if( nKern2 && nPos < nMaxPos )
/*?*/                       aPartSize.Width() += nKern2;
/*N*/                   rDo.Do();
/*N*/                   nOldPos = nTmp;
/*N*/               }
/*N*/           } while( nOldPos != nPos );
/*N*/       }
/*N*/       nPos = (xub_StrLen)pBreakIt->xBreak->endOfCharBlock( rOldText, nPos,
/*N*/              pBreakIt->GetLocale( eLng ), CharType::LOWERCASE_LETTER);
/*N*/       if( nPos == STRING_LEN || nPos > nMaxPos )
/*N*/           nPos = nMaxPos;
/*N*/       OSL_ENSURE( nPos, "endOfCharBlock not implemented?" );
/*N*/ #ifdef DBG_UTIL
/*N*/       if( !nPos )
/*N*/           nPos = nMaxPos;
/*N*/ #endif
/*N*/   }
/*N*/
/*N*/   // Aufraeumen:
/*N*/   if( pBigFont != pOldLast )
/*N*/       delete pBigFontAccess;
/*N*/
/*N*/   if( bUnderStriked )
/*N*/   {
/*N*/       if ( bWordWise )
/*?*/           delete pSpaceFontAccess;
/*N*/   }
/*N*/   pLastFont = pOldLast;
/*N*/   pLastFont->SetDevFont( rDo.GetInf().GetShell(), rDo.GetOut() );
/*N*/
/*N*/   delete pSmallFontAccess;
/*N*/   rDo.GetInf().SetText( rOldText );
/*N*/   rDo.GetInf().SetKanaDiff( nKana );
/*N*/ }

// JP 22.8.2001 - global optimization off - Bug 91245 / 91223
#ifdef _MSC_VER
#pragma optimize("g",on)
#endif


}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */