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

Commit cd93eca

Browse files
[[ Bug 14278 ]] PDF output filenames updated to UTF-8 strings
1 parent 27c6e2c commit cd93eca

File tree

10 files changed

+47
-25
lines changed

10 files changed

+47
-25
lines changed

docs/notes/bugfix-14278.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Unicode PDF file name changes to ??????.pdf

engine/src/exec-printing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,8 @@ void MCPrintingGetPrintDeviceOutput(MCExecContext& ctxt, MCPrintingPrintDeviceOu
828828

829829
if (t_output_type == PRINTER_OUTPUT_FILE)
830830
{
831-
if (!MCStringCreateWithCString(MCprinter -> GetDeviceOutputLocation(), r_output . location))
831+
// SN-2014-12-22: [[ Bug 14278 ]] Output location now stored as a UTF-8 string.
832+
if (!MCStringCreateWithBytes((byte_t*)MCprinter -> GetDeviceOutputLocation(), strlen(MCprinter->GetDeviceOutputLocation()), kMCStringEncodingUTF8, false, r_output . location))
832833
{
833834
ctxt . Throw();
834835
return;

engine/src/mac-scripting.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@
203203

204204
///////////////////////////////////////////////////////////////////////////////
205205

206-
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release);
206+
// SN-2014-12-22: [[ Bug 14278 ]] Parameter added to choose a UTF-8 string.
207+
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release, bool p_utf8 = false);
207208

208209
static bool ConvertMCStringToJSString(MCStringRef p_string, JSStringRef &r_js_string)
209210
{

engine/src/opensslsocket.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5353
#include <SystemConfiguration/SCDynamicStore.h>
5454
#include <SystemConfiguration/SCDynamicStoreKey.h>
5555
#include <SystemConfiguration/SCSchemaDefinitions.h>
56-
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release);
56+
// SN-2014-12-22: [[ Bug 14278 ]] Parameter added to choose a UTF-8 string.
57+
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release, bool p_utf8_string);
5758
#endif
5859

5960
#include <sys/types.h>
@@ -1003,7 +1004,7 @@ bool MCS_hostaddress(MCStringRef &r_host_address)
10031004
CFStringRef t_string;
10041005
t_string = (CFStringRef)CFArrayGetValueAtIndex(t_addresses, 0);
10051006
if (t_string != NULL)
1006-
t_result = osx_cfstring_to_cstring(t_string, false);
1007+
t_result = osx_cfstring_to_cstring(t_string, false, false);
10071008
}
10081009
}
10091010

engine/src/osxprinter.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ extern void MCRemotePageSetupDialog(MCDataRef p_config_data, MCDataRef &r_reply_
7777

7878
///////////////////////////////////////////////////////////////////////////////
7979

80-
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release = true);
80+
// SN-2014-12-22: [[ Bug 14278 ]] Parameter added to choose a UTF-8 string.
81+
extern char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release = true, bool p_utf8_string = false);
8182
extern bool MCImageBitmapToCGImage(MCImageBitmap *p_bitmap, bool p_copy, bool p_invert, CGImageRef &r_image);
8283
extern bool MCGImageToCGImage(MCGImageRef p_src, MCGRectangle p_src_rect, CGColorSpaceRef p_colorspace, bool p_copy, bool p_invert, CGImageRef &r_image);
8384
extern bool MCGImageToCGImage(MCGImageRef p_src, MCGRectangle p_src_rect, bool p_copy, bool p_invert, CGImageRef &r_image);
@@ -689,7 +690,8 @@ void MCMacOSXPrinter::SetProperties(bool p_include_output)
689690
PDEBUG(stderr, "SetProperties: Output location is file\n");
690691
CFStringRef t_output_format;
691692
t_output_type = PRINTER_OUTPUT_FILE;
692-
t_output_location = osx_cfstring_to_cstring(CFURLCopyFileSystemPath(t_output_location_url, kCFURLPOSIXPathStyle), true);
693+
// SN-2014-12-22: [[ Bug 14278 ]] Get a UTF-8-encoded filename
694+
t_output_location = osx_cfstring_to_cstring(CFURLCopyFileSystemPath(t_output_location_url, kCFURLPOSIXPathStyle), true, true);
693695
}
694696
else if (t_type == kPMDestinationPrinter)
695697
{
@@ -704,8 +706,9 @@ void MCMacOSXPrinter::SetProperties(bool p_include_output)
704706
t_output_location = NULL;
705707
}
706708

707-
MCAutoStringRef t_output_location_str;
708-
/* UNCHECKED */ MCStringCreateWithCString(t_output_location, &t_output_location_str);
709+
MCAutoStringRef t_output_location_str;
710+
// SN-2014-12-22: [[ Bug 14278 ]] We get the output location as a UTF-8 string.
711+
/* UNCHECKED */ MCStringCreateWithBytes((byte_t*)t_output_location, strlen(t_output_location), kMCStringEncodingUTF8, false, &t_output_location_str);
709712
SetDeviceOutput(t_output_type, *t_output_location_str);
710713

711714
delete t_output_location;
@@ -925,7 +928,8 @@ void MCMacOSXPrinter::GetProperties(bool p_include_output)
925928
case PRINTER_OUTPUT_FILE:
926929
{
927930
CFStringRef t_output_file;
928-
t_output_file = CFStringCreateWithCString(kCFAllocatorDefault, GetDeviceOutputLocation(), kCFStringEncodingMacRoman);
931+
// SN-2014-12-22: [[ Bug 14278 ]] Output location now stored as a UTF-8 string
932+
t_output_file = CFStringCreateWithCString(kCFAllocatorDefault, GetDeviceOutputLocation(), kCFStringEncodingUTF8);
929933
t_output_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, t_output_file, kCFURLPOSIXPathStyle, false);
930934
CFRelease(t_output_file);
931935
t_output_type = kPMDestinationFile;

engine/src/printer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ void MCPrinter::SetDeviceOutput(MCPrinterOutputType p_type, MCStringRef p_locati
220220
if (p_location != NULL)
221221
{
222222
char *t_loc;
223-
/* UNCHECKED */ MCStringConvertToCString(p_location, t_loc);
223+
// SN-2014-12-22: [[ Bug 14278 ]] Now store the string as a UTF-8 string.
224+
/* UNCHECKED */ MCStringConvertToUTF8String(p_location, t_loc);
224225
m_device_output_location = t_loc;
225226
}
226227
}

engine/src/syscfdate.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ MCLocaleRef MCS_getsystemlocale()
109109
static MCDateTimeLocale *s_locale_info = NULL;
110110
static CFTimeZoneRef s_locale_timezone = NULL;
111111

112-
char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release = true)
112+
// SN-2014-12-22: [[ Bug 14278 ]] Parameter added to choose a UTF-8 string.
113+
char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release = true, bool p_utf8_string = false)
113114
{
114115
bool t_success;
115116
t_success = true;
@@ -123,17 +124,24 @@ char *osx_cfstring_to_cstring(CFStringRef p_string, bool p_release = true)
123124
{
124125
CFIndex t_string_length;
125126
t_string_length = CFStringGetLength(p_string);
127+
128+
// SN-2014-12-22: [[ Bug 14278 ]] Parameter added to choose a UTF-8 string.
129+
CFStringEncoding t_encoding;
130+
if (p_utf8_string)
131+
t_encoding = kCFStringEncodingUTF8;
132+
else
133+
t_encoding = kCFStringEncodingMacRoman;
126134

127135
CFIndex t_buffer_size;
128-
t_buffer_size = CFStringGetMaximumSizeForEncoding(t_string_length, kCFStringEncodingMacRoman) + 1;
136+
t_buffer_size = CFStringGetMaximumSizeForEncoding(t_string_length, t_encoding) + 1;
129137
t_cstring = (char *)malloc(t_buffer_size);
130138

131139
if (t_cstring != NULL)
132140
{
133141
// MW-2012-03-15: [[ Bug 9935 ]] Use CFStringGetBytes() so that '?' is substituted for any non-
134142
// mappable chars.
135143
CFIndex t_used;
136-
CFStringGetBytes(p_string, CFRangeMake(0, CFStringGetLength(p_string)), kCFStringEncodingMacRoman, '?', False, (UInt8*)t_cstring, t_buffer_size, &t_used);
144+
CFStringGetBytes(p_string, CFRangeMake(0, CFStringGetLength(p_string)), t_encoding, '?', False, (UInt8*)t_cstring, t_buffer_size, &t_used);
137145
t_cstring[t_used] = '\0';
138146
}
139147
else

engine/src/w32printer.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,16 +1194,18 @@ const char *MCWindowsPrinterDevice::Error(void) const
11941194
return m_error;
11951195
}
11961196

1197-
MCPrinterResult MCWindowsPrinterDevice::Start(HDC p_dc, const char *p_document_name, const char *p_output_file)
1197+
// SN-2014-12-22: [[ Bug 14278 ]] Function updated to take wchar params
1198+
MCPrinterResult MCWindowsPrinterDevice::Start(HDC p_dc, const wchar *p_document_name, const wchar *p_output_file)
11981199
{
1199-
DOCINFOA t_info;
1200-
t_info . cbSize = sizeof(DOCINFOA);
1200+
// SN-2014-12-22: [[ Bug 14278 ]] Document name and output file now encoded as UTF16 chars
1201+
DOCINFOW t_info;
1202+
t_info . cbSize = sizeof(DOCINFOW);
12011203
t_info . lpszDocName = p_document_name;
12021204
t_info . lpszOutput = p_output_file;
12031205
t_info . lpszDatatype = NULL;
12041206
t_info . fwType = 0;
12051207

1206-
if (StartDocA(p_dc, &t_info) <= 0)
1208+
if (StartDocW(p_dc, &t_info) <= 0)
12071209
{
12081210
SetError("unable to start document");
12091211
return PRINTER_RESULT_ERROR;
@@ -1731,9 +1733,15 @@ MCPrinterResult MCWindowsPrinter::DoBeginPrint(MCStringRef p_document_name, MCPr
17311733
t_device = new MCWindowsPrinterDevice;
17321734

17331735
MCPrinterResult t_result;
1734-
MCAutoPointer<char> t_doc_name;
1735-
/* UNCHECKED */ MCStringConvertToCString(p_document_name, &t_doc_name);
1736-
t_result = t_device -> Start(t_dc, *t_doc_name, GetDeviceOutputLocation());
1736+
// SN-2014-12-22: [[ Bug 14278 ]] Updated to Unicode name and location
1737+
MCAutoStringRefAsWString t_doc_name, t_output_file;
1738+
/* UNCHECKED */ t_doc_name . Lock(p_document_name);
1739+
1740+
MCStringRef p_output_file_stringref;
1741+
MCStringCreateWithBytes(GetDeviceOutputLocation(), strlen(GetDeviceOutputLocation()), kMCStringEncodingUTF8, false, &t_output_file_stringref);
1742+
/* UNCHECKED */ t_output_file . Lock(*t_output_file_stringref);
1743+
1744+
t_result = t_device -> Start(t_dc, *t_doc_name, *t_output_file);
17371745

17381746
r_device = t_device;
17391747

engine/src/w32printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MCWindowsPrinterDevice: public MCPrinterDevice
2929

3030
//
3131

32-
MCPrinterResult Start(HDC p_dc, const char *p_document_name, const char *p_output_file);
32+
MCPrinterResult Start(HDC p_dc, const wchar *p_document_name, const wchar *p_output_file);
3333
MCPrinterResult Finish(void);
3434

3535
//

revpdfprinter/src/revpdfprinter.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,8 @@ bool MCPDFPrintingDevice::BeginDocument(const MCCustomPrinterDocument& p_documen
237237
{
238238
bool t_success = true;
239239

240-
#ifdef _MACOSX
241-
t_success = MCCStringFromNative(p_document . filename, m_filename);
242-
#else
240+
// SN-2014-12-22: [[ Bug 14278 ]] p_document.filename is now a UTF-8 string.
243241
t_success = MCCStringClone(p_document.filename, m_filename);
244-
#endif
245242

246243
if (t_success)
247244
{

0 commit comments

Comments
 (0)