@@ -381,6 +381,35 @@ func (tf *TextField) renderBackground(w io.Writer, bgCol, boCol *color.SimpleCol
381381 }
382382}
383383
384+ func (tf * TextField ) renderLines (xRefTable * model.XRefTable , boWidth , lh , w , y float64 , lines []string , buf io.Writer ) {
385+ f := tf .Font
386+ cjk := pdffont .CJK (f .Script , f .Lang )
387+ for i := 0 ; i < len (lines ); i ++ {
388+ s := lines [i ]
389+ lineBB := model .CalcBoundingBox (s , 0 , 0 , f .Name , f .Size )
390+ s = model .PrepBytes (xRefTable , s , f .Name , ! cjk , f .RTL ())
391+ x := 2 * boWidth
392+ if x == 0 {
393+ x = 2
394+ }
395+ switch tf .HorAlign {
396+ case types .AlignCenter :
397+ x = w / 2 - lineBB .Width ()/ 2
398+ case types .AlignRight :
399+ x = w - lineBB .Width () - 2
400+ }
401+ fmt .Fprint (buf , "BT " )
402+ if i == 0 {
403+ fmt .Fprintf (buf , "/%s %d Tf %.2f %.2f %.2f RG %.2f %.2f %.2f rg " ,
404+ tf .fontID , f .Size ,
405+ f .col .R , f .col .G , f .col .B ,
406+ f .col .R , f .col .G , f .col .B )
407+ }
408+ fmt .Fprintf (buf , "%.2f %.2f Td (%s) Tj ET " , x , y , s )
409+ y -= lh
410+ }
411+ }
412+
384413func (tf * TextField ) renderN (xRefTable * model.XRefTable ) ([]byte , error ) {
385414 w , h := tf .BoundingBox .Width (), tf .BoundingBox .Height ()
386415 bgCol := tf .BgCol
@@ -417,32 +446,33 @@ func (tf *TextField) renderN(xRefTable *model.XRefTable) ([]byte, error) {
417446 fmt .Fprintf (buf , "q 1 1 %.1f %.1f re W n " , w - 2 , h - 2 )
418447 }
419448
420- cjk := pdffont .CJK (f .Script , f .Lang )
421-
422- for i := 0 ; i < len (lines ); i ++ {
423- s := lines [i ]
424- lineBB := model .CalcBoundingBox (s , 0 , 0 , f .Name , f .Size )
425- s = model .PrepBytes (xRefTable , s , f .Name , ! cjk , f .RTL ())
426- x := 2 * boWidth
427- if x == 0 {
428- x = 2
429- }
430- switch tf .HorAlign {
431- case types .AlignCenter :
432- x = w / 2 - lineBB .Width ()/ 2
433- case types .AlignRight :
434- x = w - lineBB .Width () - 2
435- }
436- fmt .Fprint (buf , "BT " )
437- if i == 0 {
438- fmt .Fprintf (buf , "/%s %d Tf %.2f %.2f %.2f RG %.2f %.2f %.2f rg " ,
439- tf .fontID , f .Size ,
440- f .col .R , f .col .G , f .col .B ,
441- f .col .R , f .col .G , f .col .B )
442- }
443- fmt .Fprintf (buf , "%.2f %.2f Td (%s) Tj ET " , x , y , s )
444- y -= lh
445- }
449+ tf .renderLines (xRefTable , boWidth , lh , w , y , lines , buf )
450+ //cjk := pdffont.CJK(f.Script, f.Lang)
451+
452+ // for i := 0; i < len(lines); i++ {
453+ // s := lines[i]
454+ // lineBB := model.CalcBoundingBox(s, 0, 0, f.Name, f.Size)
455+ // s = model.PrepBytes(xRefTable, s, f.Name, !cjk, f.RTL())
456+ // x := 2 * boWidth
457+ // if x == 0 {
458+ // x = 2
459+ // }
460+ // switch tf.HorAlign {
461+ // case types.AlignCenter:
462+ // x = w/2 - lineBB.Width()/2
463+ // case types.AlignRight:
464+ // x = w - lineBB.Width() - 2
465+ // }
466+ // fmt.Fprint(buf, "BT ")
467+ // if i == 0 {
468+ // fmt.Fprintf(buf, "/%s %d Tf %.2f %.2f %.2f RG %.2f %.2f %.2f rg ",
469+ // tf.fontID, f.Size,
470+ // f.col.R, f.col.G, f.col.B,
471+ // f.col.R, f.col.G, f.col.B)
472+ // }
473+ // fmt.Fprintf(buf, "%.2f %.2f Td (%s) Tj ET ", x, y, s)
474+ // y -= lh
475+ // }
446476
447477 if len (lines ) > 0 {
448478 fmt .Fprint (buf , "Q " )
0 commit comments