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

Commit 80158a5

Browse files
committed
[[ Bug 12594 ]] Add 'text_byte_count' parameter to MCCustomPrintingDevice::DrawText otherwise NUL bytes in strings cause problems.
1 parent 264107f commit 80158a5

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

engine/include/customprinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class MCCustomPrintingDevice
383383
// should be considered to map to the text 'in one piece'. The clusters
384384
// array maps each byte of the text to the index of the first glyph in
385385
// its cluster.
386-
virtual bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
386+
virtual bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
387387

388388
// Make an anchor with the given name at the specified position - the name must
389389
// not have the form of a URI.

engine/src/customprinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ static bool dotextmark_callback(void *p_context, const MCTextLayoutSpan *p_span)
10201020
t_font . handle = t_font_handle;
10211021

10221022
bool t_success;
1023-
t_success = context -> device -> DrawText((const MCCustomPrinterGlyph *)p_span -> glyphs, p_span -> glyph_count, (const char *)t_bytes, t_clusters, t_font, context -> paint, context -> transform, context -> clip);
1023+
t_success = context -> device -> DrawText((const MCCustomPrinterGlyph *)p_span -> glyphs, p_span -> glyph_count, (const char *)t_bytes, t_byte_count, t_clusters, t_font, context -> paint, context -> transform, context -> clip);
10241024

10251025
MCMemoryDeleteArray(t_clusters);
10261026

@@ -1710,9 +1710,9 @@ class MCLoggingPrintingDevice: public MCCustomPrintingDevice
17101710
return true;
17111711
}
17121712

1713-
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& p_clip)
1713+
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& p_clip)
17141714
{
1715-
if (!m_target -> DrawText(glyphs, glyph_count, text, clusters, font, paint, transform, p_clip))
1715+
if (!m_target -> DrawText(glyphs, glyph_count, text_bytes, text_byte_count, clusters, font, paint, transform, p_clip))
17161716
return Failed("DrawText");
17171717
return true;
17181718
}
@@ -1899,9 +1899,9 @@ class MCDebugPrintingDevice: public MCCustomPrintingDevice
18991899
return true;
19001900
}
19011901

1902-
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& p_clip)
1902+
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& p_clip)
19031903
{
1904-
Enter("begin text '%s' with clip (%f, %f)-(%f, %f)", text,
1904+
Enter("begin text '%s' with clip (%f, %f)-(%f, %f)", text_bytes,
19051905
p_clip . left, p_clip . top, p_clip . right, p_clip . bottom);
19061906
for(uint32_t i = 0; i < glyph_count; i++)
19071907
Print("glyph %d at (%f, %f)", glyphs[i] . id, glyphs[i] . x, glyphs[i] . y);

revpdfprinter/src/revpdfprinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ bool MCPDFPrintingDevice::DrawImage(const MCCustomPrinterImage& image, const MCC
521521
return t_success;
522522
}
523523

524-
bool MCPDFPrintingDevice::DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip)
524+
bool MCPDFPrintingDevice::DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip)
525525
{
526526
bool t_success = true;
527527
cairo_save(m_context);
@@ -574,7 +574,7 @@ bool MCPDFPrintingDevice::DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t
574574
uint32_t t_cluster_count;
575575
bool t_reverse_clusters;
576576
if (t_success)
577-
t_success = custom_printer_clusters_to_cairo_clusters(clusters, MCCStringLength(text), glyph_count, t_clusters, t_cluster_count, t_reverse_clusters);
577+
t_success = custom_printer_clusters_to_cairo_clusters(clusters, text_byte_count, glyph_count, t_clusters, t_cluster_count, t_reverse_clusters);
578578

579579
if (t_success)
580580
t_success = apply_paint(paint);
@@ -584,7 +584,7 @@ bool MCPDFPrintingDevice::DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t
584584
cairo_set_font_face(m_context, t_font);
585585
cairo_set_font_size(m_context, font . size);
586586

587-
cairo_show_text_glyphs(m_context, text, MCCStringLength(text), t_glyphs, glyph_count, t_clusters, t_cluster_count, t_reverse_clusters ? CAIRO_TEXT_CLUSTER_FLAG_BACKWARD : (cairo_text_cluster_flags_t)0);
587+
cairo_show_text_glyphs(m_context, text_bytes, text_byte_count, t_glyphs, glyph_count, t_clusters, t_cluster_count, t_reverse_clusters ? CAIRO_TEXT_CLUSTER_FLAG_BACKWARD : (cairo_text_cluster_flags_t)0);
588588
cairo_restore(m_context);
589589
t_success = (m_status = cairo_status(m_context)) == CAIRO_STATUS_SUCCESS;
590590
}

revpdfprinter/src/revpdfprinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class MCPDFPrintingDevice: public MCCustomPrintingDevice
5959
bool FillPath(const MCCustomPrinterPath& path, MCCustomPrinterFillRule rule, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip);
6060
bool StrokePath(const MCCustomPrinterPath& path, const MCCustomPrinterStroke& stroke, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip);
6161
bool DrawImage(const MCCustomPrinterImage& image, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip);
62-
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip);
62+
bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip);
6363

6464
bool MakeAnchor(const MCCustomPrinterPoint& position, const char *name);
6565
bool MakeLink(const MCCustomPrinterRectangle& area, const char *link, MCCustomPrinterLinkType type);

0 commit comments

Comments
 (0)