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