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"
28#include <CoreGraphics/CoreGraphics.h>
33void DoNothing(
void* info,
const void* data, size_t size) {}
35bool CGDrawGlyphRun(CGContextRef pContext,
44 bool bNegSize = font_size < 0;
46 font_size = -font_size;
52 if (!pFont->GetPlatformFont()) {
56 pFont->SetPlatformFont(quartz2d
.CreateFont(pFont->GetFontSpan()
));
57 if (!pFont->GetPlatformFont())
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++) {
64 pCharPos[i].m_ExtGID ? pCharPos[i].m_ExtGID : pCharPos[i].m_GlyphIndex;
66 glyph_positions[i].x = -pCharPos[i].m_Origin.x;
68 glyph_positions[i].x = pCharPos[i].m_Origin.x;
69 glyph_positions[i].y = pCharPos[i].m_Origin.y;
72 new_matrix
.a = -new_matrix
.a;
73 new_matrix
.c = -new_matrix
.c;
75 new_matrix
.b = -new_matrix
.b;
76 new_matrix
.d = -new_matrix
.d;
79 return quartz2d.DrawGraphicsString(pContext, pFont->GetPlatformFont(),
80 font_size, glyph_indices, glyph_positions,
92 m_pPlatformGraphics = quartz2d.CreateGraphics(m_pBitmap);
99 if (m_pPlatformGraphics) {
100 quartz2d.DestroyGraphics(m_pPlatformGraphics);
101 m_pPlatformGraphics =
nullptr;
121 for (
const auto& cp : pCharPos) {
122 if (cp.m_bGlyphAdjust)
125 CGContextRef ctx = CGContextRef(m_pPlatformGraphics);
129 CGContextSaveGState(ctx);
130 CGContextSetTextDrawingMode(ctx, kCGTextFillClip);
132 CGImageRef pImageCG =
nullptr;
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();
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);
149 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight());
151 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg);
153 CGContextClipToMask(ctx, rect_cg, pImageCG);
155 CGContextClipToRect(ctx, rect_cg);
158 CGDrawGlyphRun(ctx, pCharPos, pFont, mtObject2Device, font_size, argb);
160 CGImageRelease(pImageCG);
161 CGContextRestoreGState(ctx);
167std::unique_ptr<CFX_GlyphBitmap> CFX_GlyphCache::RenderGlyph_Nativetext(
169 uint32_t glyph_index,
176void CFX_Font::ReleasePlatformResource() {
177 if (m_pPlatformFont) {
181 quartz2d.DestroyFont(m_pPlatformFont);
182 m_pPlatformFont =
nullptr;
ByteString GetPsName() const
CFX_SubstFont * GetSubstFont() const
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