Skip to content

Commit 82acd21

Browse files
committed
[[ RevPDFPrinter ]] Add Android implementation to revpdfprinter external
This patch extends the revprdprinter external to add support for Android.
1 parent e783e22 commit 82acd21

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

livecode.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
},
112112
],
113113
[
114-
'OS != "android" and OS != "emscripten"',
114+
'OS != "emscripten"',
115115
{
116116
'dependencies':
117117
[

revpdfprinter/revpdfprinter.gyp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'src/revpdfprinter_w32.cpp',
3636
'src/revpdfprinter_coretext.mm',
3737
'src/revpdfprinter_ios.mm',
38+
'src/revpdfprinter_android.cpp',
3839
],
3940

4041
# Even on OSX, we don't use the non-coretext method any more
@@ -67,6 +68,18 @@
6768
],
6869
},
6970
],
71+
[
72+
'OS == "android"',
73+
{
74+
'product_name': 'RevPdfPrinter',
75+
'product_extension': '',
76+
77+
'dependencies':
78+
[
79+
'../prebuilt/thirdparty.gyp:thirdparty_prebuilt_freetype',
80+
],
81+
},
82+
],
7083
],
7184

7285
'xcode_settings':
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* Copyright (C) 2018 LiveCode Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include "revpdfprinter.h"
18+
19+
#include <ft2build.h>
20+
#include FT_FREETYPE_H
21+
#include FT_SIZES_H
22+
23+
#include <cairo-ft.h>
24+
#include <time.h>
25+
26+
static cairo_user_data_key_t s_ft_face_key;
27+
28+
struct ft_face_user_data_t
29+
{
30+
FT_Face face;
31+
FT_Size size;
32+
FT_Size old_size;
33+
};
34+
35+
static void free_ft_face_func(void* p_face)
36+
{
37+
ft_face_user_data_t *t_data;
38+
t_data = (ft_face_user_data_t*)p_face;
39+
40+
if (t_data->old_size != nil)
41+
FT_Activate_Size(t_data->old_size);
42+
43+
if (t_data->size != nil)
44+
FT_Done_Size(t_data->size);
45+
46+
if (t_data->face != nil)
47+
FT_Done_Face(t_data->face);
48+
49+
MCMemoryDelete(t_data);
50+
}
51+
52+
bool MCPDFPrintingDevice::create_cairo_font_from_custom_printer_font(const MCCustomPrinterFont &p_cp_font, cairo_font_face_t* &r_cairo_font)
53+
{
54+
bool t_success;
55+
t_success = true;
56+
57+
ft_face_user_data_t *t_user_data;
58+
t_user_data = nil;
59+
if (t_success)
60+
t_success = MCMemoryNew(t_user_data);
61+
62+
// Get the FreeType face
63+
if (t_success)
64+
{
65+
t_user_data->face = (FT_Face)p_cp_font.handle;
66+
t_success = t_user_data->face != nil;
67+
}
68+
69+
// Retain a reference to the FreeType face
70+
if (t_success)
71+
FT_Reference_Face(t_user_data->face);
72+
73+
// Store the old face size so it can be restored once cairo is finished
74+
if (t_success)
75+
{
76+
t_user_data->old_size = t_user_data->face->size;
77+
t_success = FT_Err_Ok == FT_New_Size(t_user_data->face, &t_user_data->size);
78+
}
79+
if (t_success)
80+
t_success = FT_Err_Ok == FT_Activate_Size(t_user_data->size);
81+
if (t_success)
82+
t_success = FT_Err_Ok == FT_Set_Char_Size(t_user_data->face, p_cp_font.size * 64, 0, 0, 0);
83+
84+
bool t_free_user_data;
85+
t_free_user_data = true;
86+
87+
// We can now create the cairo_font
88+
cairo_font_face_t *t_font;
89+
t_font = nil;
90+
if (t_success)
91+
{
92+
t_font = cairo_ft_font_face_create_for_ft_face(t_user_data->face, 0);
93+
t_success = t_font != nil && (m_status = cairo_font_face_status(t_font)) == CAIRO_STATUS_SUCCESS;
94+
}
95+
if (t_success)
96+
{
97+
// Finally, add a piece of user data to the font face. This will ensure
98+
// the FreeType font is restored to its original state and released when
99+
// the cairo font is destroyed.
100+
101+
if (cairo_font_face_get_user_data(t_font, &s_ft_face_key) == nil)
102+
{
103+
m_status = cairo_font_face_set_user_data(t_font, &s_ft_face_key, t_user_data, free_ft_face_func);
104+
t_success = m_status == CAIRO_STATUS_SUCCESS;
105+
if (t_success)
106+
t_free_user_data = false;
107+
}
108+
}
109+
110+
if (t_free_user_data && t_user_data != nil)
111+
free_ft_face_func(t_user_data);
112+
113+
if (t_success)
114+
r_cairo_font = t_font;
115+
else
116+
{
117+
if (t_font != nil)
118+
cairo_font_face_destroy(t_font);
119+
}
120+
121+
return t_success;
122+
}
123+
124+
bool MCPDFPrintingDevice::set_cairo_pdf_datetime_to_now(cairo_pdf_datetime_t &r_datetime)
125+
{
126+
time_t t_time;
127+
tm * t_datetime;
128+
129+
time ( &t_time );
130+
131+
t_datetime = gmtime ( &t_time );
132+
133+
r_datetime.year = t_datetime->tm_year + 1900;
134+
r_datetime.month = t_datetime->tm_mon + 1;
135+
r_datetime.day = t_datetime->tm_mday;
136+
r_datetime.hour = t_datetime->tm_hour;
137+
r_datetime.minute = t_datetime->tm_min;
138+
r_datetime.second = t_datetime->tm_sec;
139+
140+
r_datetime.utc_minute_offset = 0;
141+
142+
return true;
143+
}
144+
145+
// SN-2014-12-23: [[ Bug 14278 ]] Added system-specific to get the path.
146+
bool MCPDFPrintingDevice::get_filename(const char* p_utf8_path, char *& r_system_path)
147+
{
148+
return MCCStringClone(p_utf8_path, r_system_path);
149+
}

0 commit comments

Comments
 (0)