Hallo zusammen,
Ich habe ein kleines Problem bei der Benutzung von der Funktion GDIPlus_Text2Curve() welche ich aus dem englischem AutoIt Forum habe. Sie sollte eigentlich einen gewölbten String auf eine GUI zeichnen. Hier mal die Funktion:
Spoiler anzeigen
;Parameters
; $hGraphics - Handle to a Graphics object
; $sText - The string of text to be displayed around the ellipse.
; $iX - The X coordinate of the upper left corner of the rectangle that bounds the ellipse
; in which todraw the arc on which the text will be placed.
; $iY - The Y coordinate of the upper left corner of the rectangle that bounds the ellipse in which to
; draw the arc on which the text will be placed.
; $iWidth - The width of the rectangle that bounds the ellipse in which to draw the arc
; $iHeight - The height of the rectangle that bounds the ellipse in which to draw the arc
; $nStartAngle - The angle between the X axis and the starting point of the arc
; $iSpacing - A plus or minus value to increase or decrease the spacing between the displayed characters.
; $nFontName - Name of the font to use for drawing
; $nFontSize - Font size to use for drawing
; $iARGB - A colour that is used to colour the text. Default is a black. If an array of colours is used,
; the colours will be used sequencially on each character, again and again to end of string.
Func GDIPlus_Text2Curve($hGraphics, $sText, $iX, $iY, $iWidth, $iHeight, $debugmode = 0, $iStartAngle = 200, $iSpacing = -1, _
$nFontName = "Arial", $nFontSize = 12, $iARGB = 0xFF000000)
Local $aChar, $hFormat, $hFamily, $hFont, $tLayout, $aInfo, $iRectWidth, $iRectHeight, $iMaxRectWidth = 0
Local $hPen1, $aTextDat, $aARGB
If IsArray($iARGB) Then $aARGB = $iARGB
$aChar = StringSplit($sText, "")
Local $aCharAll[$aChar[0] + 1][3]
For $n = 1 To $aChar[0]
;ConsoleWrite($n & " " & $aChar[$n] & " Width = ")
$hFormat = _GDIPlus_StringFormatCreate(0)
$hFamily = _GDIPlus_FontFamilyCreate($nFontName)
$hFont = _GDIPlus_FontCreate($hFamily, $nFontSize, 3, 3)
$tLayout = _GDIPlus_RectFCreate(50, 50, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $aChar[$n], $hFont, $tLayout, $hFormat)
$aCharAll[$n][1] = Ceiling(DllStructGetData($aInfo[0], "Width"))
$aCharAll[$n][2] = Ceiling(DllStructGetData($aInfo[0], "Height"))
If $aCharAll[$n][1] > $iMaxRectWidth Then $iMaxRectWidth = $aCharAll[$n][1]
;ConsoleWrite($aCharAll[$n][1 ]& " Height = " & $aCharAll[$n][2] & @CRLF)
Next
; Draw Ellipses
$hPen1 = _GDIPlus_PenCreate(0xFF800000, 2)
;GDIPlus_AntiAlias($hGraphic)
If $debugmode Then
_GDIPlus_GraphicsDrawArc($hGraphics, $iX - $iMaxRectWidth - 2, $iY - $iMaxRectWidth - 2, _
$iWidth + 4 + $iMaxRectWidth * 2, $iHeight + 4 + $iMaxRectWidth * 2, $iStartAngle, 360, $hPen1)
_GDIPlus_GraphicsDrawArc($hGraphics, $iX, $iY, $iWidth, $iHeight, $iStartAngle, 360, $hPen1)
;ConsoleWrite( "$iMaxRectWidth = " &$iMaxRectWidth & @CRLF)
EndIf
; For each character get positioning data, then use GDIPlus_SetAngledText() to draw rotated text.
Local $index
For $n = 1 To $aChar[0]
$aTextDat = TextDataClockwiseEllipse($iStartAngle, $iMaxRectWidth, $aCharAll[$n][2], $iX, $iY, $iWidth, $iHeight, $iSpacing)
$iStartAngle = $aTextDat[3]
;ConsoleWrite("$aChar[$n] = " & $aChar[$n] & " $iStartAngle = " & $iStartAngle & @CRLF)
If IsArray($aARGB) Then
$index = Mod($n, UBound($aARGB))
$iARGB = $aARGB[$index]
EndIf
GDIPlus_SetAngledText($hGraphics, $aChar[$n], $aTextDat[0], $aTextDat[1], $aTextDat[2], "", "", $iARGB, 0)
Next
If $hPen1 <> "" Then _GDIPlus_PenDispose($hPen1)
EndFunc ;==>GDIPlus_Text2Curve
; Used in conjuction with and called from GDIPlus_Text2Curve().
Func TextDataClockwiseEllipse($iStartAngle, $iRectWidth, $iRectHeight, $iX, $iY, $iWidth, $iHeight, $iSpacing)
Local $x2, $y2, $dist, $xT, $yT, $dist1, $xfact, $yfact, $direct, $aRet[4], $iQuadrant, $t, $x, $y
Local $SmallAxis
Local $h = $iX + ($iWidth / 2) ; X coordinate of centre of ellipse
Local $k = $iY + ($iHeight / 2) ; Y coordinate of centre of ellipse
Local $a = $iWidth / 2 ; a axis length of ellipse
Local $b = $iHeight / 2 ; other axis of ellipse
If $a < $b Then
$SmallAxis = $a
Else
$SmallAxis = $a
EndIf
$iRectWidth += $iSpacing
$t = $iStartAngle
$x = $h + $a * Cos($t * $iPI / 180); 1st point on ellipse boundary
$y = $k + $b * Sin($t * $iPI / 180)
;Initializing ready for Do/Until loop
Local $Ang = Int(($iRectWidth / ($SmallAxis * 2)) * 360 / $iPI) + 10
Local $increm = 5
Local $counter = 0
$t = $iStartAngle + $Ang
$x2 = $h + $a * Cos($t * $iPI / 180) ; 2nd point on ellipse
$y2 = $k + $b * Sin($t * $iPI / 180)
$dist = Sqrt(($x - $x2) ^ 2 + ($y - $y2) ^ 2)
; Finds the 2nd point on the ellipse boundary that is $iRectWidth distance from 1st point
Do
$dist1 = $dist
$t = $iStartAngle + $Ang ;The angle from centre of ellipse to 2nd point on ellipse boundary
$x2 = $h + $a * Cos($t * $iPI / 180) ; keep adjusting the angle for new 2nd point
$y2 = $k + $b * Sin($t * $iPI / 180)
$dist = Sqrt(($x - $x2) ^ 2 + ($y - $y2) ^ 2) ; new distance between 1st and 2nd points.
If $dist < $iRectWidth Then $Ang += $increm
If $dist > $iRectWidth Then $Ang -= $increm
If $dist1 < $dist Then $increm = $increm * 0.75
$counter += 1
If $counter > 300 Then
MsgBox(0, "Error", "Stuck in Do / Until loop in TextDataClockwiseEllipse()")
Exit
EndIf
;ConsoleWrite(" $counter = " & $counter &" $iRectWidth = " & $iRectWidth & " $x2 = " & _
;$x2 & " $y2 = " & $y2 & "$t = " & $t & " Near $dist = " & $dist & @CRLF)
Until $dist + 0.000001 > $iRectWidth And $dist - 0.000001 < $iRectWidth
Local $AngPerp = ATan(-($x2 - $x) / ($y2 - $y)) * 180 / $iPI + 180;Angle perpendicular to chord, $iRectWidth long
;ConsoleWrite( " $AngPerp = " & $AngPerp & @CRLF)
Local $xc = ($x2 - $x) / 2 + $x ;Midpoint of chord
Local $yc = ($y2 - $y) / 2 + $y
; Chech which quadrant the angle of the line from the centre of ellipse through centre of $iRectWidth (chord on ellipse)
$iQuadrant = Mod(Int((($t - $iStartAngle) / 2 + $iStartAngle) / 90), 4) + 1
Switch $iQuadrant
Case 1 ; 1st quadrant between zero and 90 degrees
$xfact = -1
$yfact = -1
$direct = -90
Case 2 ; 2nd quadrant between 90 and 180 degrees
$xfact = 1
$yfact = 1
$direct = 90
Case 3 ; 3rd quadrant between 180 and 270 degrees
$xfact = 1
$yfact = 1
$direct = 90
Case 4 ; 4th quadrant between 270 and 360 degrees
$xfact = -1
$yfact = -1
$direct = -90
EndSwitch
; The point that is half the font height ($iRectHeight) distance away from, and is perpendicular to
; the midpoint of the font width($iRectWidth). $iRectWidth is a chord on the curved ellipse boundary.
$xT = $xc + $iRectHeight / 2 * Cos($AngPerp * $iPI / 180) * $xfact
$yT = $yc + $iRectHeight / 2 * Sin($AngPerp * $iPI / 180) * $yfact
$aRet[0] = $xT
$aRet[1] = $yT
$aRet[2] = $AngPerp + $direct
; $t is the angle off X-axis of line from centre oy ellipse to 2nd point on ellipse boundary. Will become
; starting angle for next character.
$aRet[3] = $t
Return $aRet
EndFunc ;==>TextDataClockwiseEllipse
;See 1st post at http://www.autoitscript.com/forum/index.ph…ndpost&p=584436
Func GDIPlus_SetAngledText($hGraphic, $nText, $iCentreX = 0, $iCentreY = 0, $iAngle = 0, $nFontName = "Arial", _
$nFontSize = 12, $iARGB = 0xFFFF00FF, $iAnchor = 0)
Local $x, $y, $iX, $iY, $iWidth, $iHeight
Local $hMatrix, $iXt, $iYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
If $iAngle = "" Then $iAngle = 0
If $nFontName = "" Or $nFontName = -1 Then $nFontName = "Arial" ; "Microsoft Sans Serif"
If $nFontSize = "" Then $nFontSize = 12
If $iARGB = "" Then ; Randomize ARGB color
$iARGB = "0xFF" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
EndIf
$hFormat = _GDIPlus_StringFormatCreate(0)
$hFamily = _GDIPlus_FontFamilyCreate($nFontName)
$hFont = _GDIPlus_FontCreate($hFamily, $nFontSize, 1, 3)
$tLayout = _GDIPlus_RectFCreate($iCentreX, $iCentreY, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
$iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
$iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
If $iAnchor = 0 Then ; Reference to middle of Text rectangle
$iX = $iCentreX
$iY = $iCentreY
Else ; Referenced centre point moved to top left corner of text string.
$iX = $iCentreX + (($iWidth - Abs($iHeight * Sin($iAngle * $iPI / 180))) / 2)
$iY = $iCentreY + (($iHeight + Abs($iWidth * Sin($iAngle * $iPI / 180))) / 2)
EndIf
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixRotate($hMatrix, $iAngle, 1)
_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
$x = ($iWidth / 2) * Cos($iAngle * $iPI / 180) - ($iHeight / 2) * Sin($iAngle * $iPI / 180)
$y = ($iWidth / 2) * Sin($iAngle * $iPI / 180) + ($iHeight / 2) * Cos($iAngle * $iPI / 180)
$iXt = ($iX - $x) * Cos($iAngle * $iPI / 180) + ($iY - $y) * Sin($iAngle * $iPI / 180)
$iYt = -($iX - $x) * Sin($iAngle * $iPI / 180) + ($iY - $y) * Cos($iAngle * $iPI / 180)
$hBrush = _GDIPlus_BrushCreateSolid($iARGB)
$tLayout = _GDIPlus_RectFCreate($iXt, $iYt, $iWidth, $iHeight)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $nText, $hFont, $tLayout, $hFormat, $hBrush)
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
$tLayout = ""
Return 1
EndFunc ;==>GDIPlus_SetAngledText
Das funktioniert auch soweit, aber nur wenn ich meine GUI wie folgt erstelle:
Spoiler anzeigen
_Main()
Func _Main()
Local $iGuiX = 500, $iGuiY = 500, $hBrush
Local $hMatrix, $iXt, $iYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
$hGUI = GUICreate("Test", $iGuiX, $iGuiY, 100, 100, BitOR(0x80000000, 0x08000000), BitOR(0x00000008, 0x00000080));, $WS_SYSMENU))
GUISetState()
$hDC_Window = _WinAPI_GetDC($hGUI)
$hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC_Window)
$hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iGuiX, $iGuiY)
_WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit];$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iGuiX, $iGuiY, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
[/autoit] [autoit][/autoit] [autoit];---- Start of Drawing Graphics
$hPen = _GDIPlus_PenCreate(0xFF000000, 1)
_GDIPlus_GraphicsClear($hGraphic, 0xFFf0FFF0)
GDIPlus_Text2Curve($hGraphic, "TEST", 50, 50, 250, 150, 0, 0)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_PenDispose($hPen)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_Shutdown()
[/autoit] [autoit][/autoit] [autoit]EndFunc ;==>_Main
[/autoit]Sobald ich aber das Grafikobjekt nicht mehr direkt vom GUI erzeuge sondern vom $hDC_Buffer - also die Zeile
[autoit]$hGraphicGUI = _GDIPlus_GraphicsCreateFromHDC($hGUI)
[/autoit]
mit dieser ersetze:
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
[/autoit]Wird der Text nicht mehr gezeichnet. Leider muss ich in meinem Script in welchem ich die Funktion einbauen will das Grafikobjekt vom Buffer erstellen. Hat jemand eine Ahnung wie ich das ganze so umbauen kann, dass es auch funktioniert wenn ich das Objekt vom Buffer erstelle?
Grüße ErrorKid