|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef FRMUTILS_H |
|
22 #define FRMUTILS_H |
|
23 |
|
24 |
|
25 static TChar::TBdCategory BdCategory(TUint aCode) |
|
26 { |
|
27 // Optimise for very common cases. |
|
28 if (aCode == 0x0020) |
|
29 return TChar::EWhitespace; |
|
30 if (aCode >= 0x0061 && aCode <= 0x007A || // a..z |
|
31 aCode >= 0x0041 && aCode <= 0x005A || // A..Z |
|
32 aCode >= 0x00C0 && aCode <= 0x0233 || // Latin-1, Latin Extended A and B |
|
33 aCode >= 0x0388 && aCode <= 0x03F3 || // most Greek letters |
|
34 aCode >= 0x0401 && aCode <= 0x0481) // most Cyrillic letters |
|
35 return TChar::ELeftToRight; |
|
36 if (aCode == 0x002C || aCode == 0x002E) |
|
37 return TChar::ECommonNumberSeparator; |
|
38 if (aCode == 0x002D) |
|
39 return TChar::EEuropeanNumberTerminator; |
|
40 if (aCode >= '0' && aCode <= '9') |
|
41 return TChar::EEuropeanNumber; |
|
42 return TChar(aCode).GetBdCategory(); |
|
43 } |
|
44 |
|
45 static TChar::TBdCategory FirstStrongCategoryInParagraph(TInt aStartPosOfNextLine, RTmTextCache& aText, TInt &aPositionOfLastStrongCategory, TInt aStartPosOfThisLine) |
|
46 { |
|
47 TUint theChar = aText.Char(aStartPosOfNextLine); |
|
48 TChar::TBdCategory cat = BdCategory(theChar); |
|
49 |
|
50 TInt pos = aStartPosOfNextLine + 1; |
|
51 |
|
52 // Surrogate |
|
53 if ( theChar > 0xFFFF ) |
|
54 ++pos; |
|
55 |
|
56 // While category still weak, keep looking |
|
57 while (TChar::EPopDirectionalFormat < cat |
|
58 && cat != TChar::EParagraphSeparator) |
|
59 { |
|
60 __ASSERT_DEBUG(pos <= aText.Source().DocumentLength(), |
|
61 TmPanic(EInvariant)); |
|
62 // If we have reached the part of text that has already been traversed, without finding |
|
63 // a strong category, then just return the category at aPositionOfLastStrongCategory as |
|
64 // that is the first strong category in the remaining paragraph. |
|
65 // This is a possibility when aStartPosOfNextLine is less than aStartPosOfPrevLine |
|
66 if (pos == aStartPosOfThisLine) |
|
67 { |
|
68 return BdCategory(aText.Char(aPositionOfLastStrongCategory)); |
|
69 } |
|
70 theChar = aText.Char(pos); |
|
71 |
|
72 cat = BdCategory( theChar ); |
|
73 ++pos; |
|
74 |
|
75 if ( theChar > 0xFFFF ) |
|
76 { |
|
77 ++pos; |
|
78 } |
|
79 } |
|
80 aPositionOfLastStrongCategory = pos; |
|
81 return cat; |
|
82 } |
|
83 |
|
84 /** |
|
85 Get values for aMaxHeight, aMaxDepth |
|
86 */ |
|
87 static void GetMaxHeightAndDepth( CFont * aFont, TInt& aMaxHeight,TInt& aMaxDepth) |
|
88 { |
|
89 CFbsFont* open_font = NULL; |
|
90 |
|
91 if (aFont->TypeUid() == KCFbsFontUid) |
|
92 { |
|
93 open_font = (CFbsFont*)aFont; |
|
94 if (!open_font->IsOpenFont()) |
|
95 open_font = NULL; |
|
96 } |
|
97 |
|
98 if (open_font) |
|
99 { |
|
100 TOpenFontMetrics font_metrics; |
|
101 open_font->GetFontMetrics(font_metrics); |
|
102 aMaxHeight = font_metrics.MaxHeight(); |
|
103 aMaxDepth = font_metrics.MaxDepth(); |
|
104 } |
|
105 else |
|
106 { |
|
107 aMaxHeight = aFont->AscentInPixels(); |
|
108 aMaxDepth = aFont->DescentInPixels(); |
|
109 } |
|
110 } |
|
111 |
|
112 static void CalculateScale(const MTmSource& aSource,TInt& aXScale,TInt& aYScale) |
|
113 { |
|
114 if (&aSource.FormatDevice() == &aSource.InterpretDevice()) |
|
115 aXScale = aYScale = 1000; |
|
116 else |
|
117 { |
|
118 int p = aSource.FormatDevice().HorizontalPixelsToTwips(1000); |
|
119 int q = aSource.InterpretDevice().HorizontalPixelsToTwips(1000); |
|
120 aXScale = p * 1000 / q; |
|
121 p = aSource.FormatDevice().VerticalPixelsToTwips(1000); |
|
122 q = aSource.InterpretDevice().VerticalPixelsToTwips(1000); |
|
123 aYScale = p * 1000 / q; |
|
124 } |
|
125 } |
|
126 |
|
127 #endif //FRMUTILS_H |