| 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 "core/fxcrt/fx_system.h" | 7 #include "core/fxcrt/fx_system.h" |
| 8 | 8 |
| 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "core/fxge/fx_freetype.h" | 21 #include "core/fxge/fx_freetype.h" |
| 22 #include "core/fxge/ge/cfx_cliprgn.h" | 22 #include "core/fxge/ge/cfx_cliprgn.h" |
| 23 #include "core/fxge/ge/fx_text_int.h" | 23 #include "core/fxge/ge/fx_text_int.h" |
| 24 | 24 |
| 25 #ifndef _SKIA_SUPPORT_ | 25 #ifndef _SKIA_SUPPORT_ |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void DoNothing(void* info, const void* data, size_t size) {} | 29 void DoNothing(void* info, const void* data, size_t size) {} |
| 30 | 30 |
| 31 FX_BOOL CGDrawGlyphRun(CGContextRef pContext, | 31 bool CGDrawGlyphRun(CGContextRef pContext, |
| 32 int nChars, | 32 int nChars, |
| 33 const FXTEXT_CHARPOS* pCharPos, | 33 const FXTEXT_CHARPOS* pCharPos, |
| 34 CFX_Font* pFont, | 34 CFX_Font* pFont, |
| 35 const CFX_Matrix* pObject2Device, | 35 const CFX_Matrix* pObject2Device, |
| 36 FX_FLOAT font_size, | 36 FX_FLOAT font_size, |
| 37 uint32_t argb) { | 37 uint32_t argb) { |
| 38 if (nChars == 0) | 38 if (nChars == 0) |
| 39 return TRUE; | 39 return true; |
| 40 | 40 |
| 41 CFX_Matrix new_matrix; | 41 CFX_Matrix new_matrix; |
| 42 FX_BOOL bNegSize = font_size < 0; | 42 bool bNegSize = font_size < 0; |
| 43 if (bNegSize) | 43 if (bNegSize) |
| 44 font_size = -font_size; | 44 font_size = -font_size; |
| 45 | 45 |
| 46 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; | 46 FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; |
| 47 new_matrix.Transform(ori_x, ori_y); | 47 new_matrix.Transform(ori_x, ori_y); |
| 48 if (pObject2Device) | 48 if (pObject2Device) |
| 49 new_matrix.Concat(*pObject2Device); | 49 new_matrix.Concat(*pObject2Device); |
| 50 | 50 |
| 51 CQuartz2D& quartz2d = | 51 CQuartz2D& quartz2d = |
| 52 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) | 52 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) |
| 53 ->m_quartz2d; | 53 ->m_quartz2d; |
| 54 if (!pFont->GetPlatformFont()) { | 54 if (!pFont->GetPlatformFont()) { |
| 55 if (pFont->GetPsName() == "DFHeiStd-W5") | 55 if (pFont->GetPsName() == "DFHeiStd-W5") |
| 56 return FALSE; | 56 return false; |
| 57 | 57 |
| 58 pFont->SetPlatformFont( | 58 pFont->SetPlatformFont( |
| 59 quartz2d.CreateFont(pFont->GetFontData(), pFont->GetSize())); | 59 quartz2d.CreateFont(pFont->GetFontData(), pFont->GetSize())); |
| 60 if (!pFont->GetPlatformFont()) | 60 if (!pFont->GetPlatformFont()) |
| 61 return FALSE; | 61 return false; |
| 62 } | 62 } |
| 63 CFX_FixedBufGrow<uint16_t, 32> glyph_indices(nChars); | 63 CFX_FixedBufGrow<uint16_t, 32> glyph_indices(nChars); |
| 64 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); | 64 CFX_FixedBufGrow<CGPoint, 32> glyph_positions(nChars); |
| 65 for (int i = 0; i < nChars; i++) { | 65 for (int i = 0; i < nChars; i++) { |
| 66 glyph_indices[i] = | 66 glyph_indices[i] = |
| 67 pCharPos[i].m_ExtGID ? pCharPos[i].m_ExtGID : pCharPos[i].m_GlyphIndex; | 67 pCharPos[i].m_ExtGID ? pCharPos[i].m_ExtGID : pCharPos[i].m_GlyphIndex; |
| 68 if (bNegSize) | 68 if (bNegSize) |
| 69 glyph_positions[i].x = -pCharPos[i].m_OriginX; | 69 glyph_positions[i].x = -pCharPos[i].m_OriginX; |
| 70 else | 70 else |
| 71 glyph_positions[i].x = pCharPos[i].m_OriginX; | 71 glyph_positions[i].x = pCharPos[i].m_OriginX; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 void CFX_AggDeviceDriver::DestroyPlatform() { | 96 void CFX_AggDeviceDriver::DestroyPlatform() { |
| 97 CQuartz2D& quartz2d = | 97 CQuartz2D& quartz2d = |
| 98 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) | 98 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) |
| 99 ->m_quartz2d; | 99 ->m_quartz2d; |
| 100 if (m_pPlatformGraphics) { | 100 if (m_pPlatformGraphics) { |
| 101 quartz2d.destroyGraphics(m_pPlatformGraphics); | 101 quartz2d.destroyGraphics(m_pPlatformGraphics); |
| 102 m_pPlatformGraphics = nullptr; | 102 m_pPlatformGraphics = nullptr; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int nChars, | 106 bool CFX_AggDeviceDriver::DrawDeviceText(int nChars, |
| 107 const FXTEXT_CHARPOS* pCharPos, | 107 const FXTEXT_CHARPOS* pCharPos, |
| 108 CFX_Font* pFont, | 108 CFX_Font* pFont, |
| 109 const CFX_Matrix* pObject2Device, | 109 const CFX_Matrix* pObject2Device, |
| 110 FX_FLOAT font_size, | 110 FX_FLOAT font_size, |
| 111 uint32_t argb) { | 111 uint32_t argb) { |
| 112 if (!pFont) | 112 if (!pFont) |
| 113 return FALSE; | 113 return false; |
| 114 | 114 |
| 115 FX_BOOL bBold = pFont->IsBold(); | 115 bool bBold = pFont->IsBold(); |
| 116 if (!bBold && pFont->GetSubstFont() && | 116 if (!bBold && pFont->GetSubstFont() && |
| 117 pFont->GetSubstFont()->m_Weight >= 500 && | 117 pFont->GetSubstFont()->m_Weight >= 500 && |
| 118 pFont->GetSubstFont()->m_Weight <= 600) { | 118 pFont->GetSubstFont()->m_Weight <= 600) { |
| 119 return FALSE; | 119 return false; |
| 120 } | 120 } |
| 121 for (int i = 0; i < nChars; i++) { | 121 for (int i = 0; i < nChars; i++) { |
| 122 if (pCharPos[i].m_bGlyphAdjust) | 122 if (pCharPos[i].m_bGlyphAdjust) |
| 123 return FALSE; | 123 return false; |
| 124 } | 124 } |
| 125 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); | 125 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); |
| 126 if (!ctx) | 126 if (!ctx) |
| 127 return FALSE; | 127 return false; |
| 128 | 128 |
| 129 CGContextSaveGState(ctx); | 129 CGContextSaveGState(ctx); |
| 130 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); | 130 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); |
| 131 CGRect rect_cg; | 131 CGRect rect_cg; |
| 132 CGImageRef pImageCG = nullptr; | 132 CGImageRef pImageCG = nullptr; |
| 133 if (m_pClipRgn) { | 133 if (m_pClipRgn) { |
| 134 rect_cg = | 134 rect_cg = |
| 135 CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, | 135 CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, |
| 136 m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); | 136 m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); |
| 137 const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject(); | 137 const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject(); |
| 138 if (pClipMask) { | 138 if (pClipMask) { |
| 139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData( | 139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData( |
| 140 nullptr, pClipMask->GetBuffer(), | 140 nullptr, pClipMask->GetBuffer(), |
| 141 pClipMask->GetPitch() * pClipMask->GetHeight(), DoNothing); | 141 pClipMask->GetPitch() * pClipMask->GetHeight(), DoNothing); |
| 142 CGFloat decode_f[2] = {255.f, 0.f}; | 142 CGFloat decode_f[2] = {255.f, 0.f}; |
| 143 pImageCG = CGImageMaskCreate( | 143 pImageCG = CGImageMaskCreate( |
| 144 pClipMask->GetWidth(), pClipMask->GetHeight(), 8, 8, | 144 pClipMask->GetWidth(), pClipMask->GetHeight(), 8, 8, |
| 145 pClipMask->GetPitch(), pClipMaskDataProvider, decode_f, FALSE); | 145 pClipMask->GetPitch(), pClipMaskDataProvider, decode_f, false); |
| 146 CGDataProviderRelease(pClipMaskDataProvider); | 146 CGDataProviderRelease(pClipMaskDataProvider); |
| 147 } | 147 } |
| 148 } else { | 148 } else { |
| 149 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()); | 149 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()); |
| 150 } | 150 } |
| 151 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); | 151 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); |
| 152 if (pImageCG) | 152 if (pImageCG) |
| 153 CGContextClipToMask(ctx, rect_cg, pImageCG); | 153 CGContextClipToMask(ctx, rect_cg, pImageCG); |
| 154 else | 154 else |
| 155 CGContextClipToRect(ctx, rect_cg); | 155 CGContextClipToRect(ctx, rect_cg); |
| 156 | 156 |
| 157 FX_BOOL ret = CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pObject2Device, | 157 bool ret = CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pObject2Device, |
| 158 font_size, argb); | 158 font_size, argb); |
| 159 if (pImageCG) | 159 if (pImageCG) |
| 160 CGImageRelease(pImageCG); | 160 CGImageRelease(pImageCG); |
| 161 CGContextRestoreGState(ctx); | 161 CGContextRestoreGState(ctx); |
| 162 return ret; | 162 return ret; |
| 163 } | 163 } |
| 164 | 164 |
| 165 #endif // _SKIA_SUPPORT_ | 165 #endif // _SKIA_SUPPORT_ |
| 166 | 166 |
| 167 void CFX_FaceCache::InitPlatform() {} | 167 void CFX_FaceCache::InitPlatform() {} |
| 168 | 168 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 181 if (m_pPlatformFont) { | 181 if (m_pPlatformFont) { |
| 182 CQuartz2D& quartz2d = | 182 CQuartz2D& quartz2d = |
| 183 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) | 183 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatformData()) |
| 184 ->m_quartz2d; | 184 ->m_quartz2d; |
| 185 quartz2d.DestroyFont(m_pPlatformFont); | 185 quartz2d.DestroyFont(m_pPlatformFont); |
| 186 m_pPlatformFont = nullptr; | 186 m_pPlatformFont = nullptr; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 190 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| OLD | NEW |