Obtient un ensemble d'objets région dont chacun délimite une plage de positions de caractère dans une chaîne
#include <GDIPlus.au3>
_GDIPlus_GraphicsMeasureCharacterRanges ( $hGraphics, $sString, $hFont, $tLayout, $hStringFormat )
$hGraphics | Handle de l'objet Graphics |
$sString | La chaîne à mesurer |
$hFont | Handle de l'objet Font qui spécifie les caractéristiques de la police |
$tLayout | Structure $tagGDIPRECTF qui définit les limites de la chaîne |
$hStringFormat | Handle de l'objet StringFormat qui spécifie les plages de caractères et les informations de mise en page, tels que l'alignement, le rognage, les taquets de tabulation, et ainsi de suite |
Succès: | Retourne un tableau d'objets région : [0] - Nombre de régions [1] - Région 1 [2] - Région 2 [3] - Région 3 |
Échec: | Définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Si la fonction réussit, c'est la responsabilité de l'utilisateur de libérer ces régions.
$tagGDIPRECTF, _GDIPlus_GraphicsMeasureString, _GDIPlus_RegionDispose
Consultez GdipMeasureCharacterRanges dans la Librairie MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Crée une GUI Local $hGUI = GUICreate("GDI+", 640, 220) GUISetState(@SW_SHOW) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Crée un objet graphique à partir d'un handle fenêtre _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) Local $hPen = _GDIPlus_PenCreate(0xFF006600) Local $hBrush_Region = _GDIPlus_BrushCreateSolid(0x44FF0000) Local $hBrush_Font = _GDIPlus_BrushCreateSolid(0xFFFF0000) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $sString = "Measure Character Ranges" Local $aRanges[4][2] = [[3]] $aRanges[1][0] = 0 ; Mesure le premier caractère (de base 0) $aRanges[1][1] = 1 ; Un caractère à mesurer $aRanges[2][0] = 4 ; 5-ième caractère $aRanges[2][1] = 5 ; mesure 5 caractères $aRanges[3][0] = 14 ; Le 15-ième caractère $aRanges[3][1] = 7 ; Mesure 7 caractères _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ; Définit les plages ; Mesure les caractères, taille de police 14 Local $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Local $tLayout = _GDIPlus_RectFCreate(10, 10, 200, 200) _GDIPlus_GraphicsDrawRect($hGraphic, 10, 10, 200, 200, $hPen) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush_Font) Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ; Obtient l'ensemble des régions For $i = 1 To $aRegions[0] _GDIPlus_GraphicsFillRegion($hGraphic, $aRegions[$i], $hBrush_Region) _GDIPlus_RegionDispose($aRegions[$i]) Next _GDIPlus_FontDispose($hFont) ; Mesure les caractères, taille de police 28 $hFont = _GDIPlus_FontCreate($hFamily, 28, 0) $tLayout = _GDIPlus_RectFCreate(220, 10, 200, 200) _GDIPlus_GraphicsDrawRect($hGraphic, 220, 10, 200, 200, $hPen) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush_Font) $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) For $i = 1 To $aRegions[0] _GDIPlus_GraphicsFillRegion($hGraphic, $aRegions[$i], $hBrush_Region) _GDIPlus_RegionDispose($aRegions[$i]) Next _GDIPlus_FontDispose($hFont) ; Mesure les caractères, taille de police 56 $hFont = _GDIPlus_FontCreate($hFamily, 56, 0) $tLayout = _GDIPlus_RectFCreate(430, 10, 200, 200) _GDIPlus_GraphicsDrawRect($hGraphic, 430, 10, 200, 200, $hPen) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush_Font) $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) For $i = 1 To $aRegions[0] _GDIPlus_GraphicsFillRegion($hGraphic, $aRegions[$i], $hBrush_Region) _GDIPlus_RegionDispose($aRegions[$i]) Next _GDIPlus_FontDispose($hFont) Local $iCount = _GDIPlus_StringFormatGetMeasurableCharacterRangeCount($hFormat) MsgBox($MB_SYSTEMMODAL, "", "MeasurableCharacterRangeCount: " & $iCount) ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Nettoie les ressources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush_Font) _GDIPlus_BrushDispose($hBrush_Region) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example