OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fxcrt/fx_system.h" | 7 #include "../../../include/fxcrt/fx_system.h" |
8 #include "../../../include/fxge/fx_ge.h" | 8 #include "../../../include/fxge/fx_ge.h" |
9 | 9 |
10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
11 | 11 |
12 #include "../../../include/fxge/fx_freetype.h" | 12 #include "../../../include/fxge/fx_freetype.h" |
13 #include "../../../include/fxge/fx_ge_apple.h" | 13 #include "../../../include/fxge/fx_ge_apple.h" |
14 #include "../agg/include/fx_agg_driver.h" | 14 #include "../agg/include/fx_agg_driver.h" |
15 #include "../dib/dib_int.h" | 15 #include "../dib/dib_int.h" |
16 #include "../ge/text_int.h" | 16 #include "../ge/text_int.h" |
17 #include "apple_int.h" | 17 #include "apple_int.h" |
18 | 18 |
19 void CFX_AggDeviceDriver::InitPlatform() | 19 void CFX_AggDeviceDriver::InitPlatform() { |
20 { | 20 CQuartz2D& quartz2d = |
21 CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformD
ata())->_quartz2d; | 21 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; |
22 m_pPlatformGraphics = quartz2d.createGraphics(m_pBitmap); | 22 m_pPlatformGraphics = quartz2d.createGraphics(m_pBitmap); |
23 } | 23 } |
24 void CFX_AggDeviceDriver::DestroyPlatform() | 24 void CFX_AggDeviceDriver::DestroyPlatform() { |
25 { | 25 CQuartz2D& quartz2d = |
26 CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformD
ata())->_quartz2d; | 26 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; |
27 if (m_pPlatformGraphics) { | 27 if (m_pPlatformGraphics) { |
28 quartz2d.destroyGraphics(m_pPlatformGraphics); | 28 quartz2d.destroyGraphics(m_pPlatformGraphics); |
29 m_pPlatformGraphics = NULL; | 29 m_pPlatformGraphics = NULL; |
30 } | 30 } |
31 } | 31 } |
32 void CFX_FaceCache::InitPlatform() {} | 32 void CFX_FaceCache::InitPlatform() {} |
33 void CFX_FaceCache::DestroyPlatform() {} | 33 void CFX_FaceCache::DestroyPlatform() {} |
34 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph_Nativetext(CFX_Font *» »
» » pFont, | 34 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph_Nativetext( |
35 FX_DWORD» » » » » glyph_index, | 35 CFX_Font* pFont, |
36 const CFX_AffineMatrix *» pMatrix, | 36 FX_DWORD glyph_index, |
37 int» » » » » » dest_width, | 37 const CFX_AffineMatrix* pMatrix, |
38 int» » » » » » anti_alias) | 38 int dest_width, |
39 { | 39 int anti_alias) { |
40 return NULL; | 40 return NULL; |
41 } | 41 } |
42 static FX_BOOL _CGDrawGlyphRun(CGContextRef pContext, | 42 static FX_BOOL _CGDrawGlyphRun(CGContextRef pContext, |
43 int nChars, | 43 int nChars, |
44 const FXTEXT_CHARPOS* pCharPos, | 44 const FXTEXT_CHARPOS* pCharPos, |
45 CFX_Font* pFont, | 45 CFX_Font* pFont, |
46 CFX_FontCache* pCache, | 46 CFX_FontCache* pCache, |
47 const CFX_AffineMatrix* pObject2Device, | 47 const CFX_AffineMatrix* pObject2Device, |
48 FX_FLOAT font_size, | 48 FX_FLOAT font_size, |
49 FX_DWORD argb, | 49 FX_DWORD argb, |
50 int alpha_flag, | 50 int alpha_flag, |
51 void* pIccTransform) | 51 void* pIccTransform) { |
52 { | 52 if (nChars == 0) { |
53 if (nChars == 0) { | 53 return TRUE; |
54 return TRUE; | 54 } |
| 55 CFX_AffineMatrix new_matrix; |
| 56 FX_BOOL bNegSize = font_size < 0; |
| 57 if (bNegSize) { |
| 58 font_size = -font_size; |
| 59 } |
| 60 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; |
| 61 new_matrix.Transform(ori_x, ori_y); |
| 62 if (pObject2Device) { |
| 63 new_matrix.Concat(*pObject2Device); |
| 64 } |
| 65 CQuartz2D& quartz2d = |
| 66 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; |
| 67 if (!pFont->m_pPlatformFont) { |
| 68 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { |
| 69 return FALSE; |
55 } | 70 } |
56 CFX_AffineMatrix new_matrix; | 71 pFont->m_pPlatformFont = |
57 FX_BOOL bNegSize = font_size < 0; | 72 quartz2d.CreateFont(pFont->m_pFontData, pFont->m_dwSize); |
| 73 if (NULL == pFont->m_pPlatformFont) { |
| 74 return FALSE; |
| 75 } |
| 76 } |
| 77 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars); |
| 78 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); |
| 79 for (int i = 0; i < nChars; i++) { |
| 80 glyph_indices[i] = pCharPos[i].m_ExtGID; |
58 if (bNegSize) { | 81 if (bNegSize) { |
59 font_size = -font_size; | 82 glyph_positions[i].x = -pCharPos[i].m_OriginX; |
| 83 } else { |
| 84 glyph_positions[i].x = pCharPos[i].m_OriginX; |
60 } | 85 } |
61 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; | 86 glyph_positions[i].y = pCharPos[i].m_OriginY; |
62 new_matrix.Transform(ori_x, ori_y); | 87 } |
63 if (pObject2Device) { | 88 if (bNegSize) { |
64 new_matrix.Concat(*pObject2Device); | 89 new_matrix.a = -new_matrix.a; |
| 90 } else { |
| 91 new_matrix.b = -new_matrix.b; |
| 92 new_matrix.d = -new_matrix.d; |
| 93 } |
| 94 quartz2d.setGraphicsTextMatrix(pContext, &new_matrix); |
| 95 return quartz2d.drawGraphicsString(pContext, pFont->m_pPlatformFont, |
| 96 font_size, glyph_indices, glyph_positions, |
| 97 nChars, argb, NULL); |
| 98 } |
| 99 static void _DoNothing(void* info, const void* data, size_t size) {} |
| 100 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText( |
| 101 int nChars, |
| 102 const FXTEXT_CHARPOS* pCharPos, |
| 103 CFX_Font* pFont, |
| 104 CFX_FontCache* pCache, |
| 105 const CFX_AffineMatrix* pObject2Device, |
| 106 FX_FLOAT font_size, |
| 107 FX_DWORD argb, |
| 108 int alpha_flag, |
| 109 void* pIccTransform) { |
| 110 if (!pFont) { |
| 111 return FALSE; |
| 112 } |
| 113 FX_BOOL bBold = pFont->IsBold(); |
| 114 if (!bBold && pFont->GetSubstFont() && |
| 115 pFont->GetSubstFont()->m_Weight >= 500 && |
| 116 pFont->GetSubstFont()->m_Weight <= 600) { |
| 117 return FALSE; |
| 118 } |
| 119 for (int i = 0; i < nChars; i++) { |
| 120 if (pCharPos[i].m_bGlyphAdjust) { |
| 121 return FALSE; |
65 } | 122 } |
66 CQuartz2D& quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformDa
ta())->_quartz2d; | 123 } |
67 if (!pFont->m_pPlatformFont) { | 124 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); |
68 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { | 125 if (NULL == ctx) { |
69 return FALSE; | 126 return FALSE; |
70 } | 127 } |
71 pFont->m_pPlatformFont = quartz2d.CreateFont(pFont->m_pFontData, pFont->
m_dwSize); | 128 CGContextSaveGState(ctx); |
72 if (NULL == pFont->m_pPlatformFont) { | 129 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); |
73 return FALSE; | 130 CGRect rect_cg; |
74 } | 131 CGImageRef pImageCG = NULL; |
| 132 if (m_pClipRgn) { |
| 133 rect_cg = |
| 134 CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, |
| 135 m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); |
| 136 const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask(); |
| 137 if (pClipMask) { |
| 138 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData( |
| 139 NULL, pClipMask->GetBuffer(), |
| 140 pClipMask->GetPitch() * pClipMask->GetHeight(), _DoNothing); |
| 141 CGFloat decode_f[2] = {255.f, 0.f}; |
| 142 pImageCG = CGImageMaskCreate( |
| 143 pClipMask->GetWidth(), pClipMask->GetHeight(), 8, 8, |
| 144 pClipMask->GetPitch(), pClipMaskDataProvider, decode_f, FALSE); |
| 145 CGDataProviderRelease(pClipMaskDataProvider); |
75 } | 146 } |
76 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars); | 147 } else { |
77 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); | 148 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()); |
78 for (int i = 0; i < nChars; i++ ) { | 149 } |
79 glyph_indices[i] = pCharPos[i].m_ExtGID; | 150 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); |
80 if (bNegSize) { | 151 if (pImageCG) { |
81 glyph_positions[i].x = -pCharPos[i].m_OriginX; | 152 CGContextClipToMask(ctx, rect_cg, pImageCG); |
82 } else { | 153 } else { |
83 glyph_positions[i].x = pCharPos[i].m_OriginX; | 154 CGContextClipToRect(ctx, rect_cg); |
84 } | 155 } |
85 glyph_positions[i].y = pCharPos[i].m_OriginY; | 156 FX_BOOL ret = |
86 } | 157 _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2Device, |
87 if (bNegSize) { | 158 font_size, argb, alpha_flag, pIccTransform); |
88 new_matrix.a = -new_matrix.a; | 159 if (pImageCG) { |
89 } else { | 160 CGImageRelease(pImageCG); |
90 new_matrix.b = -new_matrix.b; | 161 } |
91 new_matrix.d = -new_matrix.d; | 162 CGContextRestoreGState(ctx); |
92 } | 163 return ret; |
93 quartz2d.setGraphicsTextMatrix(pContext, &new_matrix); | |
94 return quartz2d.drawGraphicsString(pContext, | |
95 pFont->m_pPlatformFont, | |
96 font_size, | |
97 glyph_indices, | |
98 glyph_positions, | |
99 nChars, | |
100 argb, | |
101 NULL); | |
102 } | 164 } |
103 static void _DoNothing(void *info, const void *data, size_t size) {} | 165 void CFX_Font::ReleasePlatformResource() { |
104 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int»» » » »
» nChars, | 166 if (m_pPlatformFont) { |
105 const FXTEXT_CHARPOS *» pCharPos, | 167 CQuartz2D& quartz2d = |
106 CFX_Font *» » » » pFont, | 168 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; |
107 CFX_FontCache *»» » pCache, | 169 quartz2d.DestroyFont(m_pPlatformFont); |
108 const CFX_AffineMatrix * pObject2Device, | 170 m_pPlatformFont = NULL; |
109 FX_FLOAT» » » » font_size, | 171 } |
110 FX_DWORD» » » » argb, | |
111 int alpha_flag, void* pIccTransform) | |
112 { | |
113 if (!pFont) { | |
114 return FALSE; | |
115 } | |
116 FX_BOOL bBold = pFont->IsBold(); | |
117 if (!bBold && pFont->GetSubstFont() && | |
118 pFont->GetSubstFont()->m_Weight >= 500 && | |
119 pFont->GetSubstFont()->m_Weight <= 600) { | |
120 return FALSE; | |
121 } | |
122 for (int i = 0; i < nChars; i ++) { | |
123 if (pCharPos[i].m_bGlyphAdjust) { | |
124 return FALSE; | |
125 } | |
126 } | |
127 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); | |
128 if (NULL == ctx) { | |
129 return FALSE; | |
130 } | |
131 CGContextSaveGState(ctx); | |
132 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); | |
133 CGRect rect_cg; | |
134 CGImageRef pImageCG = NULL; | |
135 if (m_pClipRgn) { | |
136 rect_cg = CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top
, m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); | |
137 const CFX_DIBitmap*» pClipMask = m_pClipRgn->GetMask(); | |
138 if (pClipMask) { | |
139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithDa
ta(NULL, | |
140 pClipMask->GetBuffer(), | |
141 pClipMask->GetPitch() * pClipMask->GetHeight(), | |
142 _DoNothing); | |
143 CGFloat decode_f[2] = {255.f, 0.f}; | |
144 pImageCG = CGImageMaskCreate(pClipMask->GetWidth(), pClipMask->GetHe
ight(), | |
145 8, 8, pClipMask->GetPitch(), pClipMaskD
ataProvider, | |
146 decode_f, FALSE); | |
147 CGDataProviderRelease(pClipMaskDataProvider); | |
148 } | |
149 } else { | |
150 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()
); | |
151 } | |
152 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); | |
153 if (pImageCG) { | |
154 CGContextClipToMask(ctx, rect_cg, pImageCG); | |
155 } else { | |
156 CGContextClipToRect(ctx, rect_cg); | |
157 } | |
158 FX_BOOL ret = _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2
Device, font_size, argb, alpha_flag, pIccTransform); | |
159 if (pImageCG) { | |
160 CGImageRelease(pImageCG); | |
161 } | |
162 CGContextRestoreGState(ctx); | |
163 return ret; | |
164 } | |
165 void CFX_Font::ReleasePlatformResource() | |
166 { | |
167 if (m_pPlatformFont) { | |
168 CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatf
ormData())->_quartz2d; | |
169 quartz2d.DestroyFont(m_pPlatformFont); | |
170 m_pPlatformFont = NULL; | |
171 } | |
172 } | 172 } |
173 | 173 |
174 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 174 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
OLD | NEW |