Jump to content

Search the Community

Showing results for tags '_GDIPlus_GraphicsDrawStringEx'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Hi all. I need a little help with GDI+. I am attempting to display a block of pre-wrapped text using GDI+. (Ultimately I want to be able to print it, so I'm using GDI+ with GRS' UDF. But that doesn't come into play here.) I want to be able to calculate the height and width automatically based on the font and text used. I made a "small" application that asks a user for a font/style and displays a block of typical Latin "lorem ipsum" text. I'm using Melba32's and as far as I can tell it works perfectly. The size it comes up with should be large enough to hold the text. GDI+ disagrees with me, and wraps the text occasionally, causing some lines to have only 1 word and pushing lower lines out of view. Below is my code. Can anyone help me figure out what's causing this? The only current workaround I've found is to pad the width returned by _StringSize by 30 pixels, and I'd really rather not rely on something like that. I suspect there's some kind of a "frame" issue going on, like margin/padding issues in CSS, but I just can't nail it down. Thanks in advance! EDIT - How do I preserve the tabs in my code when pasting here? #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include "StringSize.au3" ; GDI Fonts ; Get a font, show some text. ; Credit: Melba ; For: StringSize UDF ; http://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/ ; Credit: ReFran and UEZ ; For: GDI Repainting ; Source: http://www.autoitscript.com/forum/topic/135199-table-wit-gdiborder-lines-dont-redraw/ ; Credit: loremipsum.net ; For: Lorem Ipsum text ; Source: http://www.loremipsum.net/ AutoItSetOption("MustDeclareVars", 1) Global Const $_ATTRIB = 1, $_NAME = 2, $_SIZE = 3, $_WEIGHT = 4, $_COLOR = 7 ; $aFont indices Global Const $_TEXT = 0, $_WIDTH = 2, $_HEIGHT = 3 ; $aStringSize indices Global $aFont, $aStringSize, $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo, $sText Main() Func Main() ; Sample Text $sText = _ " 1 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt" & @CRLF & _ " 2 - ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci" & @CRLF & _ " 3 - tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum" & @CRLF & _ " 4 - iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat" & @CRLF & _ " 5 - nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum" & @CRLF & _ " 6 - zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis" & @CRLF & _ " 7 - eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non" & @CRLF & _ " 8 - habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes" & @CRLF & _ " 9 - demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus" & @CRLF & _ "10 - dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica," & @CRLF & _ "11 - quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta " & @CRLF & _ "12 - decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes" & @CRLF & _ "13 - in futurum. ##" ; Get font data $aFont = _ChooseFont() If Not IsArray($aFont) Then Return -1 $aFont[$_ATTRIB] = Number($aFont[$_ATTRIB]) ; _ChooseFont() returns an array of strings which must be converted for use $aFont[$_SIZE] = Number($aFont[$_SIZE]) $aFont[$_WEIGHT] = Number($aFont[$_WEIGHT]) $aStringSize = _StringSize($sText, $aFont[$_SIZE], $aFont[$_WEIGHT], $aFont[$_ATTRIB], $aFont[$_NAME]) If Not IsArray($aStringSize) Then Return -1 ; Build GUI $hGUI = GUICreate("GDI+ Font Test (13 Lines)", $aStringSize[$_WIDTH] + 20, $aStringSize[$_HEIGHT] + 50) GUICtrlCreateLabel("Font: " & $aFont[$_NAME] & ", Size: " & $aFont[$_SIZE] & ", Attribute: " & $aFont[$_ATTRIB] & ", Weight: " & $aFont[$_WEIGHT] & ", Color: " & $aFont[$_COLOR], 10, 10, $aStringSize[$_WIDTH], 20) _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & StringMid($aFont[$_COLOR], 3)) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($aFont[$_NAME]) $hFont = _GDIPlus_FontCreate($hFamily, $aFont[$_SIZE], $aFont[$_ATTRIB]) $tLayout = _GDIPlus_RectFCreate(10, 30, $aStringSize[$_WIDTH], $aStringSize[$_HEIGHT]) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $aStringSize[$_TEXT], $hFont, $tLayout, $hFormat) GUIRegisterMsg($WM_PAINT, "_WMPAINT") GUISetState(@SW_SHOW, $hGUI) ; Message Loop Do Until GUIGetMsg() == $GUI_EVENT_CLOSE ; Clean up _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc Func _WMPAINT() ; Repaints the GDI+ stuff (border & text) ; I only tested this on Win7 (x32 and x64), but it *should* be compatible with other Windows versions _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aStringSize[$_TEXT], $hFont, $aInfo[0], $hFormat, $hBrush) _GDIPlus_GraphicsDrawRect($hGraphic, 10, 30, $aStringSize[$_WIDTH], $aStringSize[$_HEIGHT]) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE) EndFunc
×
×
  • Create New...