Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 173061d

Browse files
committed
Merge remote-tracking branch 'michael/bugfix-13174' into bugfix-13174
2 parents 7e4191d + 015b83f commit 173061d

File tree

7 files changed

+307
-14
lines changed

7 files changed

+307
-14
lines changed

docs/notes/bugfix-13174.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Text is clipped when printing to PDF from OS X

engine/engine-mobile.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
3CC6F42812AD0A6100852B3B /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CC6F42712AD0A6100852B3B /* CFNetwork.framework */; };
2525
4C529CBC1973CF16007C5F7C /* sysunxthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C529CBB1973CF16007C5F7C /* sysunxthreads.cpp */; };
2626
4C529CBF1973CF4A007C5F7C /* stacktile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C529CBD1973CF4A007C5F7C /* stacktile.cpp */; };
27+
4C8544E8199E10DB00A568B6 /* coretextlayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C8544E7199E10DB00A568B6 /* coretextlayout.mm */; };
2728
4C977245193C986700DB2F4A /* coretextfonts.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C977244193C986700DB2F4A /* coretextfonts.cpp */; };
2829
4CD038F316C8FE1700EBCCBA /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4CD038F216C8FE1700EBCCBA /* [email protected] */; };
2930
4CD7DFE318A140D800CBCB57 /* opensslsocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DD3DEA61040AD9300CAC7EF /* opensslsocket.cpp */; };
@@ -177,7 +178,6 @@
177178
4DABCE0D15ECD4B50085E214 /* mbliphonesound.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D5435DC129EE62E0086A96E /* mbliphonesound.mm */; };
178179
4DABCE0E15ECD4B50085E214 /* mbliphonestack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D7E38B412815B1900E7F80A /* mbliphonestack.mm */; };
179180
4DABCE0F15ECD4B50085E214 /* mbliphonestore.mm in Sources */ = {isa = PBXBuildFile; fileRef = E864816F1439BC9400775960 /* mbliphonestore.mm */; };
180-
4DABCE1015ECD4B50085E214 /* mbliphonetextlayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4DDD7F57134BA833009037A0 /* mbliphonetextlayout.mm */; };
181181
4DABCE1115ECD4B50085E214 /* mbliphonetextmessaging.mm in Sources */ = {isa = PBXBuildFile; fileRef = F62D52A714DC00FB00E7C1CD /* mbliphonetextmessaging.mm */; };
182182
4DABCE1215ECD4B50085E214 /* mbliphoneurl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4DDA602A113C7E7000930F4F /* mbliphoneurl.mm */; };
183183
4DABCE1315ECD4B50085E214 /* mbliphonevideo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D5435DD129EE62E0086A96E /* mbliphonevideo.mm */; };
@@ -518,6 +518,7 @@
518518
4C7D1CE5147674C300129F01 /* mblcamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mblcamera.cpp; path = src/mblcamera.cpp; sourceTree = "<group>"; };
519519
4C7D1CF714767FD000129F01 /* mbliphonecamera.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = mbliphonecamera.mm; path = src/mbliphonecamera.mm; sourceTree = "<group>"; };
520520
4C7D1CFA1476863600129F01 /* mblsyntax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mblsyntax.h; path = src/mblsyntax.h; sourceTree = "<group>"; };
521+
4C8544E7199E10DB00A568B6 /* coretextlayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = coretextlayout.mm; path = src/coretextlayout.mm; sourceTree = "<group>"; };
521522
4C88A916147E652400A528AB /* mbliphonesensor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = mbliphonesensor.mm; path = src/mbliphonesensor.mm; sourceTree = "<group>"; };
522523
4C977244193C986700DB2F4A /* coretextfonts.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = coretextfonts.cpp; path = src/coretextfonts.cpp; sourceTree = "<group>"; };
523524
4C9EAA0314E58FE100CCF92C /* SoundModule.java */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.java; path = SoundModule.java; sourceTree = "<group>"; };
@@ -1092,6 +1093,7 @@
10921093
isa = PBXGroup;
10931094
children = (
10941095
4C977244193C986700DB2F4A /* coretextfonts.cpp */,
1096+
4C8544E7199E10DB00A568B6 /* coretextlayout.mm */,
10951097
4D4BA4E412C14F850031AB06 /* mbliphone.h */,
10961098
4DD3E1B11041192800CAC7EF /* mbliphone.mm */,
10971099
4C34550114F3FEA1008D7E50 /* mbliphonead.mm */,
@@ -2207,7 +2209,6 @@
22072209
4DABCE0D15ECD4B50085E214 /* mbliphonesound.mm in Sources */,
22082210
4DABCE0E15ECD4B50085E214 /* mbliphonestack.mm in Sources */,
22092211
4DABCE0F15ECD4B50085E214 /* mbliphonestore.mm in Sources */,
2210-
4DABCE1015ECD4B50085E214 /* mbliphonetextlayout.mm in Sources */,
22112212
4DABCE1115ECD4B50085E214 /* mbliphonetextmessaging.mm in Sources */,
22122213
4DABCE1215ECD4B50085E214 /* mbliphoneurl.mm in Sources */,
22132214
4DABCE1315ECD4B50085E214 /* mbliphonevideo.mm in Sources */,
@@ -2252,6 +2253,7 @@
22522253
4DABCE3A15ECD4B50085E214 /* property.cpp in Sources */,
22532254
4DABCE3C15ECD4B50085E214 /* redraw.cpp in Sources */,
22542255
4DABCE3D15ECD4B50085E214 /* regex.cpp in Sources */,
2256+
4C8544E8199E10DB00A568B6 /* coretextlayout.mm in Sources */,
22552257
4DABCE3E15ECD4B50085E214 /* rtf.cpp in Sources */,
22562258
4DABCE3F15ECD4B50085E214 /* rtfsupport.cpp in Sources */,
22572259
4DABCE4015ECD4B50085E214 /* scriptpt.cpp in Sources */,

engine/engine.xcodeproj/project.pbxproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
4C977251193CAF5D00DB2F4A /* coretextfonts.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C977250193CAF5000DB2F4A /* coretextfonts.cpp */; };
5252
4CC1535714E7FB91009FA80E /* paragrafattr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CC1535614E7FB91009FA80E /* paragrafattr.cpp */; };
5353
4CC1536214E7FE1D009FA80E /* fieldstyledtext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CC1536114E7FE1D009FA80E /* fieldstyledtext.cpp */; };
54+
4CF4B864199E05F300E33AEE /* customprinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6A00EE10C578C600FA48D2 /* customprinter.cpp */; };
55+
4CF4B865199E05F300E33AEE /* customprinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6A00EE10C578C600FA48D2 /* customprinter.cpp */; };
56+
4CF4B883199E0D9900E33AEE /* coretextlayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CF4B87F199E0C1C00E33AEE /* coretextlayout.mm */; };
5457
4D00C6290CE1F27300341AD3 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D00C6280CE1F27300341AD3 /* SystemConfiguration.framework */; };
5558
4D00C62A0CE1F27300341AD3 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D00C6280CE1F27300341AD3 /* SystemConfiguration.framework */; };
5659
4D01C88E12247B0F00AAD151 /* bsdiff_apply.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D01C88D12247B0F00AAD151 /* bsdiff_apply.cpp */; };
@@ -97,7 +100,6 @@
97100
4D1F9D35171C682E0091C6CB /* constant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E360B8096FD00200116 /* constant.cpp */; };
98101
4D1F9D37171C682E0091C6CB /* control.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E840B8096FD00200116 /* control.cpp */; };
99102
4D1F9D38171C682E0091C6CB /* cpalette.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E4D0B8096FD00200116 /* cpalette.cpp */; };
100-
4D1F9D39171C682E0091C6CB /* customprinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6A00EE10C578C600FA48D2 /* customprinter.cpp */; };
101103
4D1F9D3A171C682E0091C6CB /* date.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E830B8096FD00200116 /* date.cpp */; };
102104
4D1F9D3B171C682E0091C6CB /* debug.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E850B8096FD00200116 /* debug.cpp */; };
103105
4D1F9D3C171C682E0091C6CB /* dispatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D587E2F0B8096FD00200116 /* dispatch.cpp */; };
@@ -322,7 +324,6 @@
322324
4D657F9B17143B770086071B /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D6C7989171348B4000BCF78 /* libjpeg.a */; };
323325
4D657F9C17143B7A0086071B /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D6C7981171348A6000BCF78 /* libpng.a */; };
324326
4D657F9D17143B800086071B /* libz.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D6C797917134897000BCF78 /* libz.a */; };
325-
4D6A00F010C578C600FA48D2 /* customprinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6A00EE10C578C600FA48D2 /* customprinter.cpp */; };
326327
4D6F2AE718981E7F0099947D /* mac-pasteboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4D6F2AE618981E7F0099947D /* mac-pasteboard.mm */; };
327328
4D7740CB1226AA58001C9150 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D5881C10B80C7C300200116 /* Quartz.framework */; };
328329
4D7740CC1226AA65001C9150 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D5881C10B80C7C300200116 /* Quartz.framework */; };
@@ -377,7 +378,6 @@
377378
4DC66D8B1045D41700D1CFA3 /* notify.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC66D8A1045D41700D1CFA3 /* notify.cpp */; };
378379
4DC6E30518896CFB00FD43C3 /* mac-menu.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4DC6E30418896CFB00FD43C3 /* mac-menu.mm */; };
379380
4DCB65721653B2F700E438E6 /* stackcache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DCB65711653B2F700E438E6 /* stackcache.cpp */; };
380-
4DCFFD1C10CE8F5800FA2262 /* osxtextlayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DCFFD1B10CE8F5800FA2262 /* osxtextlayout.cpp */; };
381381
4DCFFD2E10CE927700FA2262 /* iquantize_new.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DCFFD2D10CE927700FA2262 /* iquantize_new.cpp */; };
382382
4DDB666F14139FF500E5C84C /* tilecache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDB666D14139FF500E5C84C /* tilecache.cpp */; };
383383
4DDB66721413A02000E5C84C /* redraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDB66701413A02000E5C84C /* redraw.cpp */; };
@@ -979,6 +979,7 @@
979979
4CC1535614E7FB91009FA80E /* paragrafattr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = paragrafattr.cpp; path = src/paragrafattr.cpp; sourceTree = "<group>"; };
980980
4CC1536114E7FE1D009FA80E /* fieldstyledtext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fieldstyledtext.cpp; path = src/fieldstyledtext.cpp; sourceTree = "<group>"; };
981981
4CC55320180D546000C10387 /* graphics_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = graphics_util.h; path = src/graphics_util.h; sourceTree = "<group>"; };
982+
4CF4B87F199E0C1C00E33AEE /* coretextlayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = coretextlayout.mm; path = src/coretextlayout.mm; sourceTree = "<group>"; };
982983
4D00C6280CE1F27300341AD3 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
983984
4D00CD75103305D4003D3C0D /* bitmapeffectblur.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bitmapeffectblur.cpp; path = src/bitmapeffectblur.cpp; sourceTree = "<group>"; };
984985
4D00CD76103305D4003D3C0D /* bitmapeffectblur.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bitmapeffectblur.h; path = src/bitmapeffectblur.h; sourceTree = "<group>"; };
@@ -2106,6 +2107,7 @@
21062107
76CCAA7B198003B000C79271 /* mac-qt-recorder.mm */,
21072108
E8AE876B177B3F5C0041B7E0 /* cgimageutil.cpp */,
21082109
4C977250193CAF5000DB2F4A /* coretextfonts.cpp */,
2110+
4CF4B87F199E0C1C00E33AEE /* coretextlayout.mm */,
21092111
4D5880140B80A4F800200116 /* osxcoreimage.cpp */,
21102112
4D5881B90B80C79600200116 /* osxcisupport.mm */,
21112113
4D4F9E6613CDFB8100B9B15D /* osxfield.cpp */,
@@ -3482,7 +3484,6 @@
34823484
4D1F9D35171C682E0091C6CB /* constant.cpp in Sources */,
34833485
4D1F9D37171C682E0091C6CB /* control.cpp in Sources */,
34843486
4D1F9D38171C682E0091C6CB /* cpalette.cpp in Sources */,
3485-
4D1F9D39171C682E0091C6CB /* customprinter.cpp in Sources */,
34863487
4D1F9D3A171C682E0091C6CB /* date.cpp in Sources */,
34873488
4D1F9D3B171C682E0091C6CB /* debug.cpp in Sources */,
34883489
4D1F9D3C171C682E0091C6CB /* dispatch.cpp in Sources */,
@@ -3587,6 +3588,7 @@
35873588
4D1F9D9E171C682E0091C6CB /* objectpropsets.cpp in Sources */,
35883589
4D1F9D9F171C682E0091C6CB /* name.cpp in Sources */,
35893590
4D1F9DA0171C682E0091C6CB /* srvmultipart.cpp in Sources */,
3591+
4CF4B865199E05F300E33AEE /* customprinter.cpp in Sources */,
35903592
4D1F9DA1171C682E0091C6CB /* srvsession.cpp in Sources */,
35913593
4D1F9DA2171C682E0091C6CB /* redraw.cpp in Sources */,
35923594
4D1F9DA3171C682E0091C6CB /* tilecache.cpp in Sources */,
@@ -3724,6 +3726,7 @@
37243726
4DEE2AB60FDE42710009423C /* gradient.cpp in Sources */,
37253727
4DEE2AB70FDE42710009423C /* graphic.cpp in Sources */,
37263728
4DEE2AB80FDE42710009423C /* group.cpp in Sources */,
3729+
4CF4B864199E05F300E33AEE /* customprinter.cpp in Sources */,
37273730
4DEE2AB90FDE42710009423C /* handler.cpp in Sources */,
37283731
4DEE2ABA0FDE42710009423C /* hc.cpp in Sources */,
37293732
4DEE2ABB0FDE42710009423C /* hndlrlst.cpp in Sources */,
@@ -3802,8 +3805,6 @@
38023805
4D17F4381042877000C49A3B /* externalv1.cpp in Sources */,
38033806
4DC66D8B1045D41700D1CFA3 /* notify.cpp in Sources */,
38043807
3C0A3CC410BAF6120074D630 /* iquantization.cpp in Sources */,
3805-
4D6A00F010C578C600FA48D2 /* customprinter.cpp in Sources */,
3806-
4DCFFD1C10CE8F5800FA2262 /* osxtextlayout.cpp in Sources */,
38073808
4DCFFD2E10CE927700FA2262 /* iquantize_new.cpp in Sources */,
38083809
4D81A4C411171F6B008AE3F1 /* objectprops.cpp in Sources */,
38093810
4D81A4C511171F6B008AE3F1 /* variablevalue.cpp in Sources */,
@@ -3871,6 +3872,7 @@
38713872
4D79B5D418A9087B00D4974C /* mac-printer.mm in Sources */,
38723873
4D30E18218AA2FCE0034CDC6 /* mac-abort.mm in Sources */,
38733874
4D30E40718AA73870034CDC6 /* mac-dialog.mm in Sources */,
3875+
4CF4B883199E0D9900E33AEE /* coretextlayout.mm in Sources */,
38743876
4D30E44618AA7C200034CDC6 /* desktop-ans.cpp in Sources */,
38753877
E82206E1184F810A00117D10 /* resolution.cpp in Sources */,
38763878
4DAF5C8718C0E76500B9713C /* mac-scripting.mm in Sources */,

engine/src/coretextlayout.mm

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/* Copyright (C) 2003-2013 Runtime Revolution 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 "prefix.h"
18+
19+
#include "unicode.h"
20+
#include "textlayout.h"
21+
22+
#include <Foundation/Foundation.h>
23+
#include <CoreText/CoreText.h>
24+
25+
struct MCTextLayoutFont
26+
{
27+
MCTextLayoutFont *next;
28+
NSString *name;
29+
CGFloat size;
30+
CTFontRef handle;
31+
};
32+
33+
static MCTextLayoutFont *s_fonts = nil;
34+
35+
bool MCTextLayoutInitialize(void)
36+
{
37+
return true;
38+
}
39+
40+
void MCTextLayoutFinalize(void)
41+
{
42+
while(s_fonts != nil)
43+
{
44+
MCTextLayoutFont *t_font;
45+
t_font = s_fonts;
46+
s_fonts = s_fonts -> next;
47+
48+
[t_font -> name release];
49+
CFRelease(t_font -> handle);
50+
delete t_font;
51+
}
52+
}
53+
54+
static CTFontRef ctfont_from_fontstruct(MCFontStruct *p_font_struct)
55+
{
56+
// MM-2014-06-04: [[ CoreText ]] Fonts are now already coretext font refs. No extra work needed here anymore.
57+
return (CTFontRef)CFRetain((CTFontRef) p_font_struct -> fid);
58+
}
59+
60+
static CTFontRef ctfont_from_ctfont(CTFontRef p_ct_font)
61+
{
62+
NSString *t_ct_font_name;
63+
CGFloat t_ct_font_size;
64+
t_ct_font_name = (NSString *)CTFontCopyPostScriptName(p_ct_font);
65+
t_ct_font_size = CTFontGetSize(p_ct_font);
66+
67+
CTFontRef t_handle;
68+
t_handle = nil;
69+
for(MCTextLayoutFont *t_font = s_fonts; t_font != nil && t_handle == nil; t_font = t_font -> next)
70+
{
71+
NSString *t_font_name;
72+
float t_font_size;
73+
t_font_name = (NSString *)CTFontCopyPostScriptName(t_font -> handle);
74+
t_font_size = CTFontGetSize(t_font -> handle);
75+
if ([t_font_name isEqualToString: t_ct_font_name] && t_font_size == t_ct_font_size)
76+
t_handle = t_font -> handle;
77+
[t_font_name release];
78+
}
79+
80+
if (t_handle == nil)
81+
{
82+
MCTextLayoutFont *t_font;
83+
t_font = new MCTextLayoutFont;
84+
t_font -> next = s_fonts;
85+
t_font -> name = [t_ct_font_name retain];
86+
t_font -> size = t_ct_font_size;
87+
t_font -> handle = p_ct_font;
88+
CFRetain(p_ct_font);
89+
s_fonts = t_font;
90+
91+
t_handle = p_ct_font;
92+
}
93+
94+
[t_ct_font_name release];
95+
96+
return t_handle;
97+
}
98+
99+
bool MCTextLayout(const unichar_t *p_chars, uint32_t p_char_count, MCFontStruct *p_font_struct, MCTextLayoutCallback p_callback, void *p_context)
100+
{
101+
bool t_success;
102+
t_success = true;
103+
104+
// Make the font
105+
106+
CTFontRef t_font;
107+
t_font = nil;
108+
if (t_success)
109+
{
110+
t_font = ctfont_from_fontstruct(p_font_struct);
111+
if (t_font == nil)
112+
t_success = false;
113+
}
114+
115+
// Build the typesetter
116+
CTTypesetterRef t_typesetter;
117+
t_typesetter = nil;
118+
if (t_success)
119+
{
120+
NSString *t_string;
121+
t_string = [[NSString alloc] initWithCharacters: (unichar_t *)p_chars length: p_char_count];
122+
123+
NSDictionary *t_attributes;
124+
t_attributes = [[NSDictionary alloc] initWithObjectsAndKeys: (id)t_font, kCTFontAttributeName, nil];
125+
126+
NSAttributedString *t_text;
127+
t_text = [[NSAttributedString alloc] initWithString: t_string attributes: t_attributes];
128+
[t_string release];
129+
[t_attributes release];
130+
131+
t_typesetter = CTTypesetterCreateWithAttributedString((CFAttributedStringRef)t_text);
132+
[t_text release];
133+
if (t_typesetter == nil)
134+
t_success = false;
135+
}
136+
137+
CTLineRef t_line;
138+
t_line = nil;
139+
if (t_success)
140+
{
141+
t_line = CTTypesetterCreateLine(t_typesetter, CFRangeMake(0, 0));
142+
if (t_line == nil)
143+
t_success = false;
144+
}
145+
146+
if (t_success)
147+
{
148+
NSArray *t_runs;
149+
t_runs = (NSArray *)CTLineGetGlyphRuns(t_line);
150+
for(id t_run_id in t_runs)
151+
{
152+
CTRunRef t_run;
153+
t_run = (CTRunRef)t_run_id;
154+
155+
uint32_t t_glyph_count;
156+
t_glyph_count = CTRunGetGlyphCount(t_run);
157+
158+
CFRange t_char_range;
159+
t_char_range = CTRunGetStringRange(t_run);
160+
161+
CGGlyph *t_glyphs;
162+
CGPoint *t_positions;
163+
CFIndex *t_indices;
164+
t_glyphs = new CGGlyph[t_glyph_count];
165+
t_positions = new CGPoint[t_glyph_count];
166+
t_indices = new CFIndex[t_glyph_count];
167+
CTRunGetGlyphs(t_run, CFRangeMake(0, 0), t_glyphs);
168+
CTRunGetPositions(t_run, CFRangeMake(0, 0), t_positions);
169+
CTRunGetStringIndices(t_run, CFRangeMake(0, 0), t_indices);
170+
171+
MCTextLayoutGlyph *t_layout_glyphs;
172+
uint16_t *t_clusters;
173+
t_layout_glyphs = new MCTextLayoutGlyph[t_glyph_count];
174+
t_clusters = new uint16_t[t_char_range . length];
175+
for(uint32_t i = 0; i < t_glyph_count; i++)
176+
{
177+
t_layout_glyphs[i] . index = t_glyphs[i];
178+
t_layout_glyphs[i] . x = t_positions[i] . x;
179+
t_layout_glyphs[i] . y = t_positions[i] . y;
180+
}
181+
182+
// Compute the clusters.
183+
for(uint32_t i = 0; i < t_char_range . length; i++)
184+
t_clusters[i] = 65535;
185+
for(uint32_t i = 0; i < t_glyph_count; i++)
186+
t_clusters[t_indices[i] - t_char_range . location] = MCMin((uint32_t)t_clusters[t_indices[i]], i);
187+
188+
for(uint32_t i = 1; i < t_char_range . length; i++)
189+
{
190+
// If a cluster has 0xffff as its value it means it was never set and must be
191+
// part of a surrogate, so we set it to the previous char.
192+
if (t_clusters[i] == 0xffff)
193+
t_clusters[i] = t_clusters[i - 1];
194+
}
195+
196+
MCTextLayoutSpan t_span;
197+
t_span . chars = p_chars + t_char_range . location;
198+
t_span . clusters = t_clusters;
199+
t_span . char_count = t_char_range . length;
200+
t_span . glyphs = t_layout_glyphs;
201+
t_span . glyph_count = t_glyph_count;
202+
t_span . font = (void *)ctfont_from_ctfont((CTFontRef)CFDictionaryGetValue(CTRunGetAttributes(t_run), kCTFontAttributeName));
203+
p_callback(p_context, &t_span);
204+
205+
delete[] t_indices;
206+
delete[] t_positions;
207+
delete[] t_glyphs;
208+
delete[] t_layout_glyphs;
209+
delete[] t_clusters;
210+
}
211+
}
212+
213+
if (t_line != nil)
214+
CFRelease(t_line);
215+
if (t_typesetter != nil)
216+
CFRelease(t_typesetter);
217+
if (t_font != nil)
218+
CFRelease(t_font);
219+
220+
return true;
221+
}
222+
223+

0 commit comments

Comments
 (0)