i just tested the new feature and it didn´t work well :
Tailbiten function pdf_GetStringWidth(String$)
Code: Select all
format MS64 COFF
Public PB_pdf_GetStringWidth
Extrn SYS_FastAllocateString4
Extrn PurePDF_ipf_GetStringWidth
Extrn SYS_FreeString
section '.text' code readable executable
PB_pdf_GetStringWidth:
MOV qword [rsp+8],rcx
PS134=64
XOR rax,rax
PUSH rax
PUSH rax
SUB rsp,40
MOV rdx,[rsp+PS134+0]
LEA rcx,[rsp+40]
SUB rsp,16
CALL SYS_FastAllocateString4
ADD rsp,16
; Protected res.f
;
; res = ipf_GetStringWidth(String$)
ADD rsp,-8
PUSH qword [rsp+48]
POP rcx
ADD rsp,-8
CALL PurePDF_ipf_GetStringWidth
ADD rsp,16
FSTP dword [rsp+48]
; ProcedureReturn res
MOVSD xmm0,qword [rsp+48]
MOVSXD rax,eax
JMP _EndProcedure135
; EndProcedure
FLDZ
_EndProcedure135:
PUSH rax
MOV rcx,qword [rsp+48]
SUB rsp,32
CALL SYS_FreeString
ADD rsp,32
POP rax
ADD rsp,56
RET
pdf_GetStringWidth(String$) from PurePDF.pb (modified to work with TB!)
Code: Select all
ProcedureDLL.f pdf_GetStringWidth(String$) ;Get width of a string in the current font.
Protected res.f
res = ipf_GetStringWidth(String$)
;ProcedureReturn ipf_GetStringWidth(String$) ; <- TB won´t detect this
ProcedureReturn res
EndProcedure
Results from Example Tutorial03 StringWidth.pb :
Code: Select all
X64:
-9223372036854775808
-9223372036854775808
-9223372036854775808
-9223372036854775808
X86:
84
84
84
84
Code: Select all
;The pdf_GetStringWidth() method allows to determine the length of a string in the current font,
;which is used here to calculate the position and the width of the frame surrounding the title.
;Then colors are set (via pdf_SetDrawColor(), pdf_SetFillColor() and pdf_SetTextColor()) and the
;thickness of the line is set to 1 mm (against 0.2 by default) with pdf_SetLineWidth(). Finally,
;we output the cell (the last parameter to 1 indicates that the background must be filled).
;The method used to print the paragraphs is pdf_MultiCell(). Each time a line reaches the right
;extremity of the cell or a carriage-return character is met, a line break is issued and a new cell
;automatically created under the current one. Text is justified by default.
;Two document properties are defined: title (pdf_SetTitle()) and author (pdf_SetAuthor()).
;Properties can be viewed by two means. First is open the document directly with Acrobat Reader,
;go to the File menu, Document info, General. Second, also available from the plug-in, is click on
;the triangle just above the right scrollbar and choose Document info.
Global title.s
title="20000 Leagues Under the Seas"
Procedure Header()
pdf_SetFont("Arial","B",15)
w = pdf_GetStringWidth(title)+6
Debug w
pdf_SetX((210 - w)/2)
pdf_SetDrawColor(0,80,180)
pdf_SetFillColor(230,230,0)
pdf_SetTextColor(220,50,50)
pdf_SetLineWidth(1)
pdf_Cell(w,9,title,1,1,#PDF_ALIGN_CENTER,1)
pdf_Ln(10)
EndProcedure
Procedure footer()
pdf_SetY(-15)
pdf_SetFont("Arial","I",8)
pdf_SetTextColor(128)
txt.s = "Page " + Str(pdf_GetPageNo())
pdf_Cell(0,10,txt,0,0,#PDF_ALIGN_CENTER)
EndProcedure
Procedure ChapterTitle(num, label.s)
pdf_SetFont("Arial", "",12)
pdf_SetFillColor(200,220,255)
pdf_Cell(0,6,"Chapter " + Str(num) + " : " + label,0,1,#PDF_ALIGN_LEFT,1)
pdf_Ln(4)
EndProcedure
Procedure ChapterBody(file.s)
txt.s = ""
FileID=OpenFile(#PB_Any,file)
If FileID
l = Lof(FileID)
If l
*MemoryBuffer = AllocateMemory(l+2)
If *MemoryBuffer
l = ReadData(FileID,*MemoryBuffer,l)
txt = PeekS(*MemoryBuffer,l,#PB_Ascii)
FreeMemory(*MemoryBuffer)
EndIf
EndIf
CloseFile(FileID)
EndIf
If txt
pdf_SetFont("Times","",12)
txt=pdf_MultiCell(0,5,txt)
pdf_Cell(0,5,txt)
pdf_Ln()
pdf_SetFont("","I")
pdf_Cell(0,5,"(end of excerpt)")
EndIf
EndProcedure
Procedure PrintChapter(num,atitle.s,file.s)
pdf_AddPage()
ChapterTitle(num,atitle)
ChapterBody(file)
EndProcedure
pdf_Create()
pdf_SetProcFooter(@Footer())
pdf_SetProcHeader(@Header())
pdf_SetTitle(title)
pdf_SetAuthor("Jules Verne")
PrintChapter(1,"A RUNAWAY REEF","20k_c1.txt");
PrintChapter(2,"THE PROS And CONS","20k_c2.txt");
pdf_Save("Tutorial03 StringWidth.pdf")