So, habe mein Ziel erreicht.
Was damit gleich zusätzlich gelöst wurde ist, das nun die "überflüssige" Leerraum bei kleinen Elementen weg.
Zugegeben meine Prozeduren sind nicht das gelbe vom Ei aber sie funktionieren. Denn irgendwie mutte ich ja DrawText() dazu bringen die fehlenden Sachen mit darzustellen, also Leerzeichen ran und abstand weg ^^
Hier die Verbesserungen:
Mit
DrawRealText() wird nun der Text richtig eingerückt und komplett dargestellt.
Hintergrund bei mir war, ich musste einem Bitmap-Font erstellen und habe mich gewunder warum manche Zeichen Fehlerhaft sind.
TextShiftLeft(), TextShiftRight() ermitteln die "Verschiebung" des Zeichens
TextRealWidth() ermitteln "reale" Breite des Textes
Code: Alles auswählen
Procedure TextShiftLeft(FontID, Text$)
Protected ABC.ABC, *DC = CreateCompatibleDC_(0)
If *DC
SelectObject_(*DC, FontID)
GetCharABCWidths_(*DC, Asc(Left(Text$,1)), Asc(Left(Text$,1)), @ABC)
DeleteDC_(*DC)
EndIf
ProcedureReturn ABC\abcA
EndProcedure
Procedure TextShiftRight(FontID, Text$)
Protected ABC.ABC, *DC = CreateCompatibleDC_(0)
If *DC
SelectObject_(*DC, FontID)
GetCharABCWidths_(*DC, Asc(Right(Text$,1)), Asc(Right(Text$,1)), @ABC)
DeleteDC_(*DC)
EndIf
ProcedureReturn ABC\abcC
EndProcedure
Procedure TextRealWidth(FontID, Text$)
Protected *Char.Character = @Text$
Protected ABC.ABC, *DC = CreateCompatibleDC_(0), RealWidth
If *DC
SelectObject_(*DC, FontID)
While *Char\c
GetCharABCWidths_(*DC, *Char\c, *Char\c, @ABC)
RealWidth + ABC\abcA + ABC\abcB + ABC\abcC
*Char + SizeOf(Character)
Wend
DeleteDC_(*DCRealWidth)
EndIf
ProcedureReturn RealWidth-TextShiftLeft(FontID, Text$)-TextShiftRight(FontID, Text$)
EndProcedure
Procedure DrawRealText(FontID, x, y, Text$, Color)
Protected Shift = TextShiftLeft(FontID, Text$)
Text$ = Space(16)+Text$+Space(16)
DrawText(x-Shift-TextWidth(Space(17))+TextWidth(" "), y, Text$, Color)
EndProcedure
Enumeration
#Window : #Gadget : #Image
EndEnumeration
Global Font = FontID(LoadFont(#PB_Any, "Times New Roman", 50, #PB_Font_Italic))
CreateImage(#Image, 400,400)
StartDrawing(ImageOutput(#Image))
DrawingFont(Font)
DrawingMode(#PB_2DDrawing_Transparent)
Text$ = "jf"
Width = TextWidth(Text$)
RealWidth = TextRealWidth(Font, Text$)
Box(10, 10, Width, TextHeight(Text$), $808080)
DrawText(10, 10, Text$, $FFFFFF)
Box(10, 210, RealWidth, TextHeight(Text$), $808080)
DrawRealText(Font, 10, 210, Text$, $FFFFFF)
Debug Chr(34)+Text$+chr(34)
Debug " Links = "+Str(TextShiftLeft(Font, Text$))
Debug " Rechts = "+Str(TextShiftRight(Font, Text$))
Text$ = "´ig."
Width = TextWidth(Text$)
RealWidth = TextRealWidth(Font, Text$)
Box(210, 10, Width, TextHeight(Text$), $808080)
DrawText(210, 10, Text$, $FFFFFF)
Box(210, 210, RealWidth, TextHeight(Text$), $808080)
DrawRealText(Font, 210, 210, Text$, $FFFFFF)
Debug Chr(34)+Text$+chr(34)
Debug " Links = "+Str(TextShiftLeft(Font, Text$))
Debug " Rechts = "+Str(TextShiftRight(Font, Text$))
StopDrawing()
SetClipboardImage(#Image)
OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ImageGadget(#Gadget, 0, 0, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow