Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fx_apple_impl.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include <stdint.h>
8
9#include <memory>
10#include <vector>
11
12#include "core/fxcrt/data_vector.h"
13#include "core/fxcrt/fx_system.h"
14#include "core/fxge/agg/fx_agg_driver.h"
15#include "core/fxge/apple/fx_apple_platform.h"
16#include "core/fxge/cfx_cliprgn.h"
17#include "core/fxge/cfx_font.h"
18#include "core/fxge/cfx_gemodule.h"
19#include "core/fxge/cfx_glyphbitmap.h"
20#include "core/fxge/cfx_glyphcache.h"
21#include "core/fxge/cfx_renderdevice.h"
22#include "core/fxge/cfx_substfont.h"
23#include "core/fxge/dib/cfx_dibitmap.h"
24#include "core/fxge/text_char_pos.h"
25#include "third_party/base/containers/span.h"
26
27#if defined(OS_IOS)
28#include <CoreGraphics/CoreGraphics.h>
29#endif
30
31namespace {
32
33void DoNothing(void* info, const void* data, size_t size) {}
34
35bool CGDrawGlyphRun(CGContextRef pContext,
36 pdfium::span<const TextCharPos> pCharPos,
37 CFX_Font* pFont,
38 const CFX_Matrix& mtObject2Device,
39 float font_size,
40 uint32_t argb) {
41 if (pCharPos.empty())
42 return true;
43
44 bool bNegSize = font_size < 0;
45 if (bNegSize)
46 font_size = -font_size;
47
48 CFX_Matrix new_matrix = mtObject2Device;
49 CQuartz2D& quartz2d =
50 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatform())
52 if (!pFont->GetPlatformFont()) {
53 if (pFont->GetPsName() == "DFHeiStd-W5")
54 return false;
55
56 pFont->SetPlatformFont(quartz2d.CreateFont(pFont->GetFontSpan()));
57 if (!pFont->GetPlatformFont())
58 return false;
59 }
60 DataVector<uint16_t> glyph_indices(pCharPos.size());
61 std::vector<CGPoint> glyph_positions(pCharPos.size());
62 for (size_t i = 0; i < pCharPos.size(); i++) {
63 glyph_indices[i] =
64 pCharPos[i].m_ExtGID ? pCharPos[i].m_ExtGID : pCharPos[i].m_GlyphIndex;
65 if (bNegSize)
66 glyph_positions[i].x = -pCharPos[i].m_Origin.x;
67 else
68 glyph_positions[i].x = pCharPos[i].m_Origin.x;
69 glyph_positions[i].y = pCharPos[i].m_Origin.y;
70 }
71 if (bNegSize) {
72 new_matrix.a = -new_matrix.a;
73 new_matrix.c = -new_matrix.c;
74 } else {
75 new_matrix.b = -new_matrix.b;
76 new_matrix.d = -new_matrix.d;
77 }
78 quartz2d.SetGraphicsTextMatrix(pContext, new_matrix);
79 return quartz2d.DrawGraphicsString(pContext, pFont->GetPlatformFont(),
80 font_size, glyph_indices, glyph_positions,
81 argb);
82}
83
84} // namespace
85
86namespace pdfium {
87
88void CFX_AggDeviceDriver::InitPlatform() {
89 CQuartz2D& quartz2d =
90 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatform())
92 m_pPlatformGraphics = quartz2d.CreateGraphics(m_pBitmap);
93}
94
95void CFX_AggDeviceDriver::DestroyPlatform() {
96 CQuartz2D& quartz2d =
97 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatform())
99 if (m_pPlatformGraphics) {
100 quartz2d.DestroyGraphics(m_pPlatformGraphics);
101 m_pPlatformGraphics = nullptr;
102 }
103}
104
105bool CFX_AggDeviceDriver::DrawDeviceText(
106 pdfium::span<const TextCharPos> pCharPos,
107 CFX_Font* pFont,
108 const CFX_Matrix& mtObject2Device,
109 float font_size,
110 uint32_t argb,
111 const CFX_TextRenderOptions& /*options*/) {
112 if (!pFont)
113 return false;
114
115 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 (const auto& cp : pCharPos) {
122 if (cp.m_bGlyphAdjust)
123 return false;
124 }
125 CGContextRef ctx = CGContextRef(m_pPlatformGraphics);
126 if (!ctx)
127 return false;
128
129 CGContextSaveGState(ctx);
130 CGContextSetTextDrawingMode(ctx, kCGTextFillClip);
131 CGRect rect_cg;
132 CGImageRef pImageCG = nullptr;
133 if (m_pClipRgn) {
134 rect_cg =
135 CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top,
136 m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height());
137 RetainPtr<CFX_DIBitmap> pClipMask = m_pClipRgn->GetMask();
138 if (pClipMask) {
139 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData(
140 nullptr, pClipMask->GetBuffer().data(),
141 pClipMask->GetPitch() * pClipMask->GetHeight(), DoNothing);
142 CGFloat decode_f[2] = {255.f, 0.f};
143 pImageCG = CGImageMaskCreate(
144 pClipMask->GetWidth(), pClipMask->GetHeight(), 8, 8,
145 pClipMask->GetPitch(), pClipMaskDataProvider, 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 bool ret =
158 CGDrawGlyphRun(ctx, pCharPos, pFont, mtObject2Device, font_size, argb);
159 if (pImageCG)
160 CGImageRelease(pImageCG);
161 CGContextRestoreGState(ctx);
162 return ret;
163}
164
165} // namespace pdfium
166
167std::unique_ptr<CFX_GlyphBitmap> CFX_GlyphCache::RenderGlyph_Nativetext(
168 const CFX_Font* pFont,
169 uint32_t glyph_index,
170 const CFX_Matrix& matrix,
171 int dest_width,
172 int anti_alias) {
173 return nullptr;
174}
175
176void CFX_Font::ReleasePlatformResource() {
177 if (m_pPlatformFont) {
178 CQuartz2D& quartz2d =
179 static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatform())
181 quartz2d.DestroyFont(m_pPlatformFont);
182 m_pPlatformFont = nullptr;
183 }
184}
ByteString GetPsName() const
Definition cfx_font.cpp:358
CFX_SubstFont * GetSubstFont() const
Definition cfx_font.h:82
bool IsBold() const
Definition cfx_font.cpp:343
PlatformIface * GetPlatform() const
static CFX_GEModule * Get()
void SetGraphicsTextMatrix(void *graphics, const CFX_Matrix &matrix)
void * CreateFont(pdfium::span< const uint8_t > pFontData)
bool operator==(const char *ptr) const
bool DrawDeviceText(pdfium::span< const TextCharPos > pCharPos, CFX_Font *pFont, const CFX_Matrix &mtObject2Device, float font_size, uint32_t color, const CFX_TextRenderOptions &options) override