Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
fx_quartz_device.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
"core/fxge/apple/fx_quartz_device.h"
8
9
#
include
<
CoreGraphics
/
CoreGraphics
.
h
>
10
11
#
include
"core/fxcrt/fixed_size_data_vector.h"
12
#
include
"core/fxcrt/fx_extension.h"
13
#
include
"core/fxcrt/fx_memory_wrappers.h"
14
#
include
"core/fxcrt/zip.h"
15
#
include
"core/fxge/cfx_graphstatedata.h"
16
#
include
"core/fxge/cfx_path.h"
17
#
include
"core/fxge/cfx_renderdevice.h"
18
#
include
"core/fxge/dib/cfx_dibitmap.h"
19
20
#
ifndef
CGFLOAT_IS_DOUBLE
21
#
error
Expected
CGFLOAT_IS_DOUBLE
to
be
defined
by
CoreGraphics
headers
22
#
endif
23
24
FX_DATA_PARTITION_EXCEPTION
(CGPoint);
25
26
void
*
CQuartz2D
::
CreateGraphics
(
const
RetainPtr
<CFX_DIBitmap>& pBitmap) {
27
if
(!pBitmap)
28
return
nullptr
;
29
CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little;
30
switch
(pBitmap->GetFormat()) {
31
case
FXDIB_Format::kBgrx:
32
bmpInfo |= kCGImageAlphaNoneSkipFirst;
33
break
;
34
case
FXDIB_Format::kBgra:
35
default
:
36
return
nullptr
;
37
}
38
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
39
CGContextRef context = CGBitmapContextCreate(
40
pBitmap->GetWritableBuffer().data(), pBitmap->GetWidth(),
41
pBitmap->GetHeight(), 8, pBitmap->GetPitch(), colorSpace, bmpInfo);
42
CGColorSpaceRelease(colorSpace);
43
return
context;
44
}
45
46
void
CQuartz2D
::
DestroyGraphics
(
void
* graphics) {
47
if
(graphics)
48
CGContextRelease((CGContextRef)graphics);
49
}
50
51
void
*
CQuartz2D
::
CreateFont
(pdfium::span<
const
uint8_t> font_data) {
52
CGDataProviderRef data_provider = CGDataProviderCreateWithData(
53
nullptr
, font_data.data(), font_data.size(),
nullptr
);
54
if
(!data_provider) {
55
return
nullptr
;
56
}
57
58
CGFontRef cg_font = CGFontCreateWithDataProvider(data_provider);
59
CGDataProviderRelease(data_provider);
60
return
cg_font;
61
}
62
63
void
CQuartz2D
::
DestroyFont
(
void
* font) {
64
CGFontRelease((CGFontRef)font);
65
}
66
67
void
CQuartz2D
::
SetGraphicsTextMatrix
(
void
* graphics,
68
const
CFX_Matrix
& matrix) {
69
if
(!graphics)
70
return
;
71
CGContextRef context =
reinterpret_cast
<CGContextRef>(graphics);
72
CGFloat ty = CGBitmapContextGetHeight(context) - matrix
.
f
;
73
CGContextSetTextMatrix(
74
context, CGAffineTransformMake(matrix
.
a
, matrix
.
b
, matrix
.
c
, matrix
.
d
,
75
matrix
.
e
, ty));
76
}
77
78
bool
CQuartz2D
::
DrawGraphicsString
(
void
* graphics,
79
void
* font,
80
float
font_size,
81
pdfium::span<uint16_t> glyph_indices,
82
pdfium::span<CGPoint> glyph_positions,
83
FX_ARGB
argb) {
84
if
(!graphics)
85
return
false
;
86
87
CGContextRef context = (CGContextRef)graphics;
88
CGContextSetFont(context, (CGFontRef)font);
89
CGContextSetFontSize(context, font_size);
90
91
const
FX_BGRA_STRUCT
<uint8_t> bgra = ArgbToBGRAStruct(argb);
92
CGContextSetRGBFillColor(context, bgra.red / 255.f, bgra.green / 255.f,
93
bgra.blue / 255.f, bgra.alpha / 255.f);
94
CGContextSaveGState(context);
95
#
if
CGFLOAT_IS_DOUBLE
96
auto
glyph_positions_cg =
97
FixedSizeDataVector<CGPoint>::Uninit(glyph_positions.size());
98
for
(
auto
[input, output] :
99
fxcrt::Zip(glyph_positions, glyph_positions_cg.span())) {
100
output.x = input.x;
101
output.y = input.y;
102
}
103
const
CGPoint* glyph_positions_cg_ptr = glyph_positions_cg.span().data();
104
#
else
105
const
CGPoint* glyph_positions_cg_ptr = glyph_positions.data();
106
#
endif
107
CGContextShowGlyphsAtPositions(
108
context,
reinterpret_cast
<CGGlyph*>(glyph_indices.data()),
109
glyph_positions_cg_ptr, glyph_positions.size());
110
CGContextRestoreGState(context);
111
return
true
;
112
}
CFX_Matrix
Definition
fx_coordinates.h:440
CFX_Matrix::d
float d
Definition
fx_coordinates.h:510
CFX_Matrix::a
float a
Definition
fx_coordinates.h:507
CFX_Matrix::c
float c
Definition
fx_coordinates.h:509
CFX_Matrix::f
float f
Definition
fx_coordinates.h:512
CFX_Matrix::e
float e
Definition
fx_coordinates.h:511
CFX_Matrix::b
float b
Definition
fx_coordinates.h:508
CQuartz2D
Definition
fx_quartz_device.h:20
CQuartz2D::SetGraphicsTextMatrix
void SetGraphicsTextMatrix(void *graphics, const CFX_Matrix &matrix)
Definition
fx_quartz_device.cpp:67
CQuartz2D::CreateFont
void * CreateFont(pdfium::span< const uint8_t > font_data)
Definition
fx_quartz_device.cpp:51
CQuartz2D::DrawGraphicsString
bool DrawGraphicsString(void *graphics, void *font, float font_size, pdfium::span< uint16_t > glyph_indices, pdfium::span< CGPoint > glyph_positions, FX_ARGB argb)
Definition
fx_quartz_device.cpp:78
CQuartz2D::DestroyGraphics
void DestroyGraphics(void *graphics)
Definition
fx_quartz_device.cpp:46
CQuartz2D::CreateGraphics
void * CreateGraphics(const RetainPtr< CFX_DIBitmap > &bitmap)
Definition
fx_quartz_device.cpp:26
CQuartz2D::DestroyFont
void DestroyFont(void *font)
Definition
fx_quartz_device.cpp:63
fxcrt::RetainPtr
Definition
retain_ptr.h:28
FX_ARGB
uint32_t FX_ARGB
Definition
fx_dib.h:36
FX_DATA_PARTITION_EXCEPTION
#define FX_DATA_PARTITION_EXCEPTION(T)
Definition
fx_memory_wrappers.h:26
FX_BGRA_STRUCT
Definition
fx_dib.h:84
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxge
apple
fx_quartz_device.cpp
Generated on
for Qt by
1.18.0