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_ |
(...skipping 21 matching lines...) Expand all Loading... |
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(CFX_Font *
pFont, |
35 FX_DWORD glyph_index, | 35 FX_DWORD glyph_index, |
36 const CFX_AffineMatrix * pMatrix, | 36 const CFX_AffineMatrix * pMatrix, |
37 int dest_width, | 37 int dest_width, |
38 int anti_alias) | 38 int anti_alias) |
39 { | 39 { |
40 return NULL; | 40 return NULL; |
41 } | 41 } |
42 static FX_BOOL _CGDrawGlyphRun(CGContextRef pContext, | 42 static 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 { |
53 if (nChars == 0) { | 53 if (nChars == 0) { |
54 return TRUE; | 54 return true; |
55 } | 55 } |
56 CFX_AffineMatrix new_matrix; | 56 CFX_AffineMatrix new_matrix; |
57 FX_BOOL bNegSize = font_size < 0; | 57 bool bNegSize = font_size < 0; |
58 if (bNegSize) { | 58 if (bNegSize) { |
59 font_size = -font_size; | 59 font_size = -font_size; |
60 } | 60 } |
61 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; | 61 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; |
62 new_matrix.Transform(ori_x, ori_y); | 62 new_matrix.Transform(ori_x, ori_y); |
63 if (pObject2Device) { | 63 if (pObject2Device) { |
64 new_matrix.Concat(*pObject2Device); | 64 new_matrix.Concat(*pObject2Device); |
65 } | 65 } |
66 CQuartz2D& quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformDa
ta())->_quartz2d; | 66 CQuartz2D& quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformDa
ta())->_quartz2d; |
67 if (!pFont->m_pPlatformFont) { | 67 if (!pFont->m_pPlatformFont) { |
68 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { | 68 if (pFont->GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { |
69 return FALSE; | 69 return false; |
70 } | 70 } |
71 pFont->m_pPlatformFont = quartz2d.CreateFont(pFont->m_pFontData, pFont->
m_dwSize); | 71 pFont->m_pPlatformFont = quartz2d.CreateFont(pFont->m_pFontData, pFont->
m_dwSize); |
72 if (NULL == pFont->m_pPlatformFont) { | 72 if (NULL == pFont->m_pPlatformFont) { |
73 return FALSE; | 73 return false; |
74 } | 74 } |
75 } | 75 } |
76 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars); | 76 CFX_FixedBufGrow<FX_WORD, 32> glyph_indices(nChars); |
77 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); | 77 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); |
78 for (int i = 0; i < nChars; i++ ) { | 78 for (int i = 0; i < nChars; i++ ) { |
79 glyph_indices[i] = pCharPos[i].m_ExtGID; | 79 glyph_indices[i] = pCharPos[i].m_ExtGID; |
80 if (bNegSize) { | 80 if (bNegSize) { |
81 glyph_positions[i].x = -pCharPos[i].m_OriginX; | 81 glyph_positions[i].x = -pCharPos[i].m_OriginX; |
82 } else { | 82 } else { |
83 glyph_positions[i].x = pCharPos[i].m_OriginX; | 83 glyph_positions[i].x = pCharPos[i].m_OriginX; |
(...skipping 10 matching lines...) Expand all Loading... |
94 return quartz2d.drawGraphicsString(pContext, | 94 return quartz2d.drawGraphicsString(pContext, |
95 pFont->m_pPlatformFont, | 95 pFont->m_pPlatformFont, |
96 font_size, | 96 font_size, |
97 glyph_indices, | 97 glyph_indices, |
98 glyph_positions, | 98 glyph_positions, |
99 nChars, | 99 nChars, |
100 argb, | 100 argb, |
101 NULL); | 101 NULL); |
102 } | 102 } |
103 static void _DoNothing(void *info, const void *data, size_t size) {} | 103 static void _DoNothing(void *info, const void *data, size_t size) {} |
104 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int»» » » »
» nChars, | 104 bool CFX_AggDeviceDriver::DrawDeviceText(int» » » » »
» nChars, |
105 const FXTEXT_CHARPOS * pCharPos, | 105 const FXTEXT_CHARPOS * pCharPos, |
106 CFX_Font * pFont, | 106 CFX_Font * pFont, |
107 CFX_FontCache * pCache, | 107 CFX_FontCache * pCache, |
108 const CFX_AffineMatrix * pObject2Device, | 108 const CFX_AffineMatrix * pObject2Device, |
109 FX_FLOAT font_size, | 109 FX_FLOAT font_size, |
110 FX_DWORD argb, | 110 FX_DWORD argb, |
111 int alpha_flag, void* pIccTransform) | 111 int alpha_flag, void* pIccTransform) |
112 { | 112 { |
113 if (!pFont) { | 113 if (!pFont) { |
114 return FALSE; | 114 return false; |
115 } | 115 } |
116 FX_BOOL bBold = pFont->IsBold(); | 116 bool bBold = pFont->IsBold(); |
117 if (!bBold && pFont->GetSubstFont() && | 117 if (!bBold && pFont->GetSubstFont() && |
118 pFont->GetSubstFont()->m_Weight >= 500 && | 118 pFont->GetSubstFont()->m_Weight >= 500 && |
119 pFont->GetSubstFont()->m_Weight <= 600) { | 119 pFont->GetSubstFont()->m_Weight <= 600) { |
120 return FALSE; | 120 return false; |
121 } | 121 } |
122 for (int i = 0; i < nChars; i ++) { | 122 for (int i = 0; i < nChars; i ++) { |
123 if (pCharPos[i].m_bGlyphAdjust) { | 123 if (pCharPos[i].m_bGlyphAdjust) { |
124 return FALSE; | 124 return false; |
125 } | 125 } |
126 } | 126 } |
127 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); | 127 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); |
128 if (NULL == ctx) { | 128 if (NULL == ctx) { |
129 return FALSE; | 129 return false; |
130 } | 130 } |
131 CGContextSaveGState(ctx); | 131 CGContextSaveGState(ctx); |
132 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); | 132 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); |
133 CGRect rect_cg; | 133 CGRect rect_cg; |
134 CGImageRef pImageCG = NULL; | 134 CGImageRef pImageCG = NULL; |
135 if (m_pClipRgn) { | 135 if (m_pClipRgn) { |
136 rect_cg = CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top
, m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); | 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(); | 137 const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask(); |
138 if (pClipMask) { | 138 if (pClipMask) { |
139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithDa
ta(NULL, | 139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithDa
ta(NULL, |
140 pClipMask->GetBuffer(), | 140 pClipMask->GetBuffer(), |
141 pClipMask->GetPitch() * pClipMask->GetHeight(), | 141 pClipMask->GetPitch() * pClipMask->GetHeight(), |
142 _DoNothing); | 142 _DoNothing); |
143 CGFloat decode_f[2] = {255.f, 0.f}; | 143 CGFloat decode_f[2] = {255.f, 0.f}; |
144 pImageCG = CGImageMaskCreate(pClipMask->GetWidth(), pClipMask->GetHe
ight(), | 144 pImageCG = CGImageMaskCreate(pClipMask->GetWidth(), pClipMask->GetHe
ight(), |
145 8, 8, pClipMask->GetPitch(), pClipMaskD
ataProvider, | 145 8, 8, pClipMask->GetPitch(), pClipMaskD
ataProvider, |
146 decode_f, FALSE); | 146 decode_f, false); |
147 CGDataProviderRelease(pClipMaskDataProvider); | 147 CGDataProviderRelease(pClipMaskDataProvider); |
148 } | 148 } |
149 } else { | 149 } else { |
150 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()
); | 150 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()
); |
151 } | 151 } |
152 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); | 152 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); |
153 if (pImageCG) { | 153 if (pImageCG) { |
154 CGContextClipToMask(ctx, rect_cg, pImageCG); | 154 CGContextClipToMask(ctx, rect_cg, pImageCG); |
155 } else { | 155 } else { |
156 CGContextClipToRect(ctx, rect_cg); | 156 CGContextClipToRect(ctx, rect_cg); |
157 } | 157 } |
158 FX_BOOL ret = _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2
Device, font_size, argb, alpha_flag, pIccTransform); | 158 bool ret = _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2Dev
ice, font_size, argb, alpha_flag, pIccTransform); |
159 if (pImageCG) { | 159 if (pImageCG) { |
160 CGImageRelease(pImageCG); | 160 CGImageRelease(pImageCG); |
161 } | 161 } |
162 CGContextRestoreGState(ctx); | 162 CGContextRestoreGState(ctx); |
163 return ret; | 163 return ret; |
164 } | 164 } |
165 void CFX_Font::ReleasePlatformResource() | 165 void CFX_Font::ReleasePlatformResource() |
166 { | 166 { |
167 if (m_pPlatformFont) { | 167 if (m_pPlatformFont) { |
168 CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatf
ormData())->_quartz2d; | 168 CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatf
ormData())->_quartz2d; |
169 quartz2d.DestroyFont(m_pPlatformFont); | 169 quartz2d.DestroyFont(m_pPlatformFont); |
170 m_pPlatformFont = NULL; | 170 m_pPlatformFont = NULL; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 174 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
OLD | NEW |