@@ -903,8 +903,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
903903 this .current .fontSize = size ;
904904
905905 if (fontObj .coded ) {
906- warn ('Unsupported Type3 font (custom Glyph) - ' + fontRefName );
907- return ; // we don't need ctx.font for Type3 fonts
906+ warn ('Found Type3 font (custom Glyph) - ' + fontRefName + ', trying to decode' ); // MQZ 8/23 added Type3 glyph font support
907+ // MQZ. 08/24/2025 need to set up the font context for glyph based text processing
908+ this .ctx .setFont (fontObj );
909+ return ; // we don't need ctx.font for Type3 fonts
908910 }
909911
910912 var name = fontObj .loadedName || 'sans-serif' ;
@@ -1053,13 +1055,36 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10531055 var glyphsLength = glyphs .length ;
10541056 var textLayer = this .textLayer ;
10551057 var geom ;
1056- var textSelection = textLayer && !skipTextSelection ? true : false ;
1058+
1059+ // Always use textSelection for Type3 fonts
1060+ var textSelection = textLayer && (font .coded || !skipTextSelection ) ? true : false ;
1061+ var type3Text = "" ;
1062+
10571063 var canvasWidth = 0.0 ;
10581064 var vertical = font .vertical ;
10591065 var defaultVMetrics = font .defaultVMetrics ;
10601066
1067+ info (`showText called with $ {glyphsLength } glyphs , font type : $ {font .coded ? 'Type3' : font .type || 'Unknown' }, textSelection : $ {textSelection }`);
1068+
10611069 // Type3 fonts - each glyph is a "mini-PDF"
10621070 if (font .coded ) {
1071+ info (`Processing Type3 font with $ {glyphsLength } glyphs `);
1072+
1073+ // For Type3 fonts, collect unicode characters or character codes
1074+ for (var i = 0 ; i < glyphsLength ; ++i ) {
1075+ var glyph = glyphs [i ];
1076+ if (glyph !== null ) {
1077+ // Use unicode value if available, otherwise use fontChar
1078+ if (glyph .unicode ) {
1079+ type3Text += glyph .unicode ;
1080+ } else if (glyph .fontChar ) {
1081+ type3Text += String .fromCharCode (glyph .fontChar );
1082+ }
1083+ }
1084+ }
1085+ info (`Type3 text : $ {type3Text }`);
1086+
1087+ // If we have collected text, store it for later use in appendText
10631088 ctx .save ();
10641089 ctx .transform .apply (ctx , current .textMatrix );
10651090 ctx .translate (current .x , current .y );
@@ -1070,18 +1095,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10701095 this .save ();
10711096 ctx .scale (1 , -1 );
10721097 geom = this .createTextGeometry ();
1098+ // Add the Type3 text to the geometry object so it can be added to the output
1099+ geom .type3Text = type3Text ;
1100+ geom .fontSize = fontSize ;
10731101 this .restore ();
10741102 }
10751103 for (var i = 0 ; i < glyphsLength ; ++i ) {
1076-
10771104 var glyph = glyphs [i ];
10781105 if (glyph === null ) {
10791106 // word break
1107+ info (`Type3 word break at glyph $ {i }`);
10801108 this .ctx .translate (wordSpacing , 0 );
10811109 current .x += wordSpacing * textHScale ;
10821110 continue ;
10831111 }
10841112
1113+ //info(`Processing Type3 glyph ${i}: ${glyph.unicode || glyph.fontChar}`);
10851114 this .processingType3 = glyph ;
10861115 this .save ();
10871116 ctx .scale (fontSize , fontSize );
@@ -1093,24 +1122,46 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10931122 var width = (transformed [0 ] * fontSize + charSpacing ) *
10941123 current .fontDirection ;
10951124
1125+ //info(`Type3 glyph width: ${width}`);
10961126 ctx .translate (width , 0 );
10971127 current .x += width * textHScale ;
10981128
10991129 canvasWidth += width ;
11001130 }
1131+ // Render Type3 text within the transformation context
1132+ if (type3Text ) {
1133+ info (`render Type3 text : '${type3Text}' , disableFontFace : $ {font .disableFontFace }`);
1134+ var curFontSize = fontSize ;
1135+ switch (current .textRenderingMode ) {
1136+ case TextRenderingMode .FILL :
1137+ ctx .fillText (type3Text , 0 , 0 , canvasWidth , curFontSize );
1138+ break ;
1139+ case TextRenderingMode .STROKE :
1140+ ctx .strokeText (type3Text , 0 , 0 , canvasWidth , curFontSize );
1141+ break ;
1142+ case TextRenderingMode .FILL_STROKE :
1143+ ctx .fillText (type3Text , 0 , 0 , canvasWidth , curFontSize );
1144+ break ;
1145+ case TextRenderingMode .INVISIBLE :
1146+ case TextRenderingMode .ADD_TO_PATH :
1147+ break ;
1148+ default : // other unsupported rendering modes
1149+ }
1150+ }
1151+
11011152 ctx .restore ();
11021153 this .processingType3 = null ;
11031154 } else {
11041155 ctx .save ();
11051156
1106- //MQZ Dec.04.2013 handles leading word spacing
1107- var tx = 0 ;
1108- if (wordSpacing !== 0 ) {
1109- var firstGlyph = glyphs .filter (g => g && ('fontChar' in g || 'unicode' in g ))[0 ];
1110- if (firstGlyph && (firstGlyph .fontChar === ' ' || firstGlyph .unicode === ' ' )) {
1157+ //MQZ Dec.04.2013 handles leading word spacing
1158+ var tx = 0 ;
1159+ if (wordSpacing !== 0 ) {
1160+ var firstGlyph = glyphs .filter (g => g && ('fontChar' in g || 'unicode' in g ))[0 ];
1161+ if (firstGlyph && (firstGlyph .fontChar === ' ' || firstGlyph .unicode === ' ' )) {
11111162 tx = wordSpacing * fontSize * textHScale ;
1112- }
1113- }
1163+ }
1164+ }
11141165
11151166 current .x += tx
11161167 this .applyTextTransforms ();
@@ -1135,8 +1186,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
11351186
11361187 ctx .lineWidth = lineWidth ;
11371188
1138- //MQZ. Feb.20.2013. Disable character based painting, make it a string
1139- var str = "" ;
1189+ //MQZ. Feb.20.2013. Disable character based painting, make it a string
1190+ var str = "" ;
11401191
11411192 var x = 0 ;
11421193 for (var i = 0 ; i < glyphsLength ; ++i ) {
@@ -1188,7 +1239,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
11881239
11891240 //MQZ. Feb.20.2013. Disable character based painting, make it a string
11901241// this.paintChar(character, scaledX, scaledY);
1191- str += glyph .unicode || character ;
1242+ str += glyph .unicode || character ;
11921243 if (accent ) {
11931244 scaledAccentX = scaledX + accent .offset .x / fontSizeScale ;
11941245 scaledAccentY = scaledY - accent .offset .y / fontSizeScale ;
@@ -1218,35 +1269,28 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
12181269// info(nodeUtil.inspect(glyphs));
12191270// }
12201271
1221- if (str && !font .disableFontFace ) {
1222- var curFontSize = fontSize * scale * textHScale + 3 ;
1223- switch (current .textRenderingMode ) {
1224- case TextRenderingMode .FILL :
1225- ctx .fillText (str , 0 , 0 , canvasWidth , curFontSize );
1226- break ;
1227- case TextRenderingMode .STROKE :
1228- ctx .strokeText (str , 0 , 0 , canvasWidth , curFontSize );
1229- break ;
1230- case TextRenderingMode .FILL_STROKE :
1231- ctx .fillText (str , 0 , 0 , canvasWidth , curFontSize );
1232- break ;
1233- case TextRenderingMode .INVISIBLE :
1234- case TextRenderingMode .ADD_TO_PATH :
1235- break ;
1236- default : // other unsupported rendering modes
1237- }
1238- }
12391272
12401273 ctx .restore ();
12411274 }
12421275
1243- if (textSelection ) {
1244- geom .canvasWidth = canvasWidth ;
1245- if (vertical ) {
1246- var VERTICAL_TEXT_ROTATION = Math .PI / 2 ;
1247- geom .angle += VERTICAL_TEXT_ROTATION ;
1276+ // Text rendering for regular fonts (Type3 fonts are handled in their own context above)
1277+ if (str && !font .disableFontFace && !font .coded ) {
1278+ var curFontSize = fontSize * scale * textHScale + 3 ;
1279+ switch (current .textRenderingMode ) {
1280+ case TextRenderingMode .FILL :
1281+ ctx .fillText (str , 0 , 0 , canvasWidth , curFontSize );
1282+ break ;
1283+ case TextRenderingMode .STROKE :
1284+ ctx .strokeText (str , 0 , 0 , canvasWidth , curFontSize );
1285+ break ;
1286+ case TextRenderingMode .FILL_STROKE :
1287+ ctx .fillText (str , 0 , 0 , canvasWidth , curFontSize );
1288+ break ;
1289+ case TextRenderingMode .INVISIBLE :
1290+ case TextRenderingMode .ADD_TO_PATH :
1291+ break ;
1292+ default : // other unsupported rendering modes
12481293 }
1249- this .textLayer .appendText (geom );
12501294 }
12511295
12521296 return canvasWidth ;
@@ -1334,7 +1378,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
13341378 var VERTICAL_TEXT_ROTATION = Math .PI / 2 ;
13351379 geom .angle += VERTICAL_TEXT_ROTATION ;
13361380 }
1337- this .textLayer .appendText (geom );
13381381 }
13391382 },
13401383 nextLineShowText : function CanvasGraphics_nextLineShowText (text ) {
0 commit comments