Fr33b0w Posted October 28, 2009 Posted October 28, 2009 Guys... I am using autoit from time to time when I want to make something for myself but those scripts are not even close to things You do in here so I never posted anything... For me its important just to work, not how fast or short it will be... I hope You understand me... At this point I am trying to do something here but I dont know how to do it. I got a headache and not even know how to explain this anymore. Lets try like this: I have some text I would like to fit somewhere and every letter has its width. Script should be counting width from every letter in the text I want to chose and when it exceed certain number it should go to another line until whole text is entered. Here is a peace of shame that I wrote and I know it can be much much better. I dont need better..... just need it to work somehow... guys... any idea? expandcollapse popup#include <GUIConstants.au3> #include <string.au3> #include <date.au3> ;----------------------------------------------------------------------------------------------------------- ; CONFIGURATION ;----------------------------------------------------------------------------------------------------------- ;filename for storing previous text $file="text.txt" $linecount=1 $counterchar=0 $tfile=FileRead($file,20000) $999 = GUICreate("Char Width Tryout", 435, 800) ;----------------------------------------------------------------------------------------------------------- $button = GUICtrlCreateButton("DONE",10,06,212,21) ;----------------------------------------------------------------------------------------------------------- $input02=GuiCtrlCreateEdit($tfile, 06, 49, 425, 740, $ES_CENTER + $ES_MULTILINE + $ES_AUTOVSCROLL,$UDS_WRAP) $text=$input02 GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete() EXIT Case $msg = $button ExitLoop EndSelect WEnd ;----------------------------------------------------------------------------------------------------------- ; ######################################################################################################### ;----------------------------------------------------------------------------------------------------------- $text = GUICtrlRead($input02) FileDelete($file) FileWrite($file, $text) ;----------------------------------------------------------------------------------------------------------- ; ######################################################################################################### ;----------------------------------------------------------------------------------------------------------- $counterline=1 $counterchar=1 While 1 $counterchar=1 $fileline=FileReadLine($file, $counterline) If @error = -1 Then ExitLoop lineload () WEnd Exit ;----------------------------------------------------------------------------------------------------------- ; LINE LOAD ;----------------------------------------------------------------------------------------------------------- Func lineload () $char2 = StringSplit($fileline, "") $char=$char2[1] checker() $char=$char2[2] checker() $char=$char2[3] checker() $char=$char2[4] checker() $char=$char2[5] checker() $char=$char2[6] checker() $char=$char2[7] checker() $char=$char2[8] checker() $char=$char2[9] checker() $char=$char2[10] checker() $char=$char2[11] checker() $char=$char2[12] checker() $char=$char2[13] checker() $char=$char2[14] checker() $char=$char2[15] checker() $char=$char2[16] checker() $char=$char2[17] checker() $char=$char2[18] checker() $char=$char2[19] checker() $char=$char2[20] checker() $char=$char2[21] checker() $char=$char2[22] checker() $char=$char2[23] checker() $char=$char2[24] checker() $char=$char2[25] checker() $char=$char2[26] checker() $char=$char2[27] EndFunc ;----------------------------------------------------------------------------------------------------------- ; COUNTER ;----------------------------------------------------------------------------------------------------------- Func counter () IniWrite("setings.ini", $counter, $line & $counter, $linecount) $counter=$counter+1 $linecount=0 EndFunc ;----------------------------------------------------------------------------------------------------------- ; CHECKER ;----------------------------------------------------------------------------------------------------------- Func checker () Select Case $char = "a" $linecount=$linecount+6 Case $char = "b" $linecount=$linecount+6 Case $char = "c" $linecount=$linecount+6 Case $char = "d" $linecount=$linecount+6 Case $char = "e" $linecount=$linecount+6 Case $char = "f" $linecount=$linecount+4 Case $char = "g" $linecount=$linecount+6 Case $char = "h" $linecount=$linecount+6 Case $char = "i" $linecount=$linecount+2 Case $char = "j" $linecount=$linecount+3 Case $char = "k" $linecount=$linecount+5 Case $char = "l" $linecount=$linecount+2 Case $char = "m" $linecount=$linecount+8 Case $char = "n" $linecount=$linecount+6 Case $char = "o" $linecount=$linecount+6 Case $char = "p" $linecount=$linecount+6 Case $char = "r" $linecount=$linecount+4 Case $char = "s" $linecount=$linecount+5 Case $char = "t" $linecount=$linecount+4 Case $char = "u" $linecount=$linecount+6 Case $char = "v" $linecount=$linecount+6 Case $char = "x" $linecount=$linecount+6 Case $char = "w" $linecount=$linecount+6 Case $char = "y" $linecount=$linecount+6 Case $char = "z" $linecount=$linecount+5 Case $char = "," $linecount=$linecount+4 Case $char = "." $linecount=$linecount+4 Case $char = " " $linecount=$linecount+3 Case $char = "'" $linecount=$linecount+2 Case $char = "-" $linecount=$linecount+4 Case $char = "(" $linecount=$linecount+4 Case $char = ")" $linecount=$linecount+4 Case $char = "_" $linecount=$linecount+6 Case $char = "•" $linecount=$linecount+5 Case $char = "°" $linecount=$linecount+5 Case $char = "1" $linecount=$linecount+5 Case $char = "2" $linecount=$linecount+6 Case $char = "3" $linecount=$linecount+6 Case $char = "4" $linecount=$linecount+6 Case $char = "5" $linecount=$linecount+6 Case $char = "6" $linecount=$linecount+6 Case $char = "7" $linecount=$linecount+6 Case $char = "8" $linecount=$linecount+6 Case $char = "9" $linecount=$linecount+6 Case $char = "0" $linecount=$linecount+6 EndSelect Endfunc I was writing this over and over again... I am sorry if this does not make any sense but I can't think anymore.. I am complitely lost... I hope You do understand what I want to get... Just give me an example and idea how to do it please...
Moderators Melba23 Posted October 28, 2009 Moderators Posted October 28, 2009 Freebow,I wrote a UDF a while ago to wordwrap text to fit in fixed width labels and GUIs. I hope it will do what you want.Here is the UDF with an example commented out at the end - just remove the #cs/#ce lines:expandcollapse popup#include-once #include <WindowsConstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> ; #FUNCTION# ======================================================================================= ; ; Name...........: _StringSize ; Description ...: Returns size of rectangle required to display string - width can be chosen ; Syntax ........: _StringSize($sText[, $iSize[, $iWeight[, $iAttrib[, $sName[, $iWidth]]]]]) ; Parameters ....: $sText - String to display ; $iSize - Font size in points - default AutoIt GUI default ; $iWeight - Font weight (400 = normal) - default AutoIt GUI default ; $iAttrib - Font attribute (0-Normal, 2-Italic, 4-Underline, 8 Strike - default AutoIt ; $sName - Font name - default AutoIt GUI default ; $iWidth - [optional] Width of rectangle - default is unwrapped width of string ; Requirement(s) : v3.2.12.1 or higher ; Return values .: Success - Returns array with details of rectangle required for text: ; |$array[0] = String formatted with @CRLF at required wrap points ; |$array[1] = Height of single line in selected font ; |$array[2] = Width of rectangle required to hold formatted string ; |$array[3] = Height of rectangle required to hold formatted string ; Failure - Returns 0 and sets @error: ; |1 - Incorrect parameter type (@extended = parameter index) ; |2 - Failure to create GUI to test label size ; |3 - Failure of _WinAPI_SelectObject ; |4 - Font too large for chosen width - longest word will not fit ; Author ........: Melba23 ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ;=================================================================================================== Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0) Local $hWnd, $hFont, $hDC, $oFont, $tSize, $hGUI, $hText_Label, $sTest_Line Local $iLine_Count, $iLine_Width, $iWrap_Count, $iLast_Word Local $asLines[1], $avSize_Info[4], $aiPos[4] ; Check parameters are correct type If Not IsString($sText) Then Return SetError(1, 1, 0) If Not IsNumber($iSize) And $iSize <> Default Then Return SetError(1, 2, 0) If Not IsInt($iWeight) And $iWeight <> Default Then Return SetError(1, 3, 0) If Not IsInt($iAttrib) And $iAttrib <> Default Then Return SetError(1, 4, 0) If Not IsString($sName) And $sName <> Default Then Return SetError(1, 5, 0) If Not IsNumber($iWidth) Then Return SetError(1, 6, 0) ; Create GUI to contain test labels, set to passed font parameters $hGUI = GUICreate("", 1200, 500, 10, 10) If $hGUI = 0 Then Return SetError(2, 0, 0) GUISetFont($iSize, $iWeight, $iAttrib, $sName) ; Store unwrapped text $avSize_Info[0] = $sText ; Ensure EoL is @CRLF and break text into lines If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[x0a|x0d]", @CRLF) $asLines = StringSplit($sText, @CRLF, 1) ; Draw label with unwrapped lines to check on max width $hText_Label = GUICtrlCreateLabel($sText, 10, 10) $aiPos = ControlGetPos($hGUI, "", $hText_Label) GUICtrlDelete($hText_Label) ; Store line height for this font size after removing label padding (always 8) $avSize_Info[1] = ($aiPos[3] - 8)/ $asLines[0] ; Store width and height of this label $avSize_Info[2] = $aiPos[2] $avSize_Info[3] = $aiPos[3] - 4 ; Reduce margin ; Check if wrapping is required If $aiPos[2] > $iWidth And $iWidth > 0 Then ; Set returned text element to null $avSize_Info[0] = "" ; Set width element to max allowed $avSize_Info[2] = $iWidth ; Set line count to zero $iLine_Count = 0 ; Take each line in turn For $j = 1 To $asLines[0] ; Size this line unwrapped $hText_Label = GUICtrlCreateLabel($asLines[$j], 10, 10) $aiPos = ControlGetPos($hGUI, "", $hText_Label) GUICtrlDelete($hText_Label) ; Check wrap status If $aiPos[2] < $iWidth Then ; No wrap needed so count line and store $iLine_Count += 1 $avSize_Info[0] &= $asLines[$j] & @CRLF Else ; Wrap needed so need to count wrapped lines ; Create label to hold line as it grows $hText_Label = GUICtrlCreateLabel("", 0, 0) ; Initialise Point32 method $hWnd = ControlGetHandle($hGui, "", $hText_Label) $hFont = _SendMessage($hWnd, $WM_GETFONT) $hDC = _WinAPI_GetDC($hWnd) $oFont = _WinAPI_SelectObject($hDC, $hFont) If $oFont = 0 Then Return SetError(3, 0, 0) ; Zero counter $iWrap_Count = 0 While 1 ; Set line width to 0 $iLine_Width = 0 ; Initialise pointer for end of word $iLast_Word = 0 For $i = 1 To StringLen($asLines[$j]) ; Is this just past a word ending? If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1 ; Increase line by one character $sTest_Line = StringMid($asLines[$j], 1, $i) ; Place line in label GUICtrlSetData($hText_Label, $sTest_Line) ; Get line length $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sTest_Line) $iLine_Width = DllStructGetData($tSize, "X") ; If too long exit the loop If $iLine_Width >= $iWidth - Int($iSize / 2) Then ExitLoop Next ; End of the line of text? If $i > StringLen($asLines[$j]) Then ; Yes, so add final line to count $iWrap_Count += 1 ; Store line $avSize_Info[0] &= $sTest_Line & @CRLF ExitLoop Else ; No, but add line just completed to count $iWrap_Count += 1 ; Check at least 1 word completed or return error If $iLast_Word = 0 Then GUIDelete($hGUI) Return SetError(4, 0, 0) EndIf ; Store line up to end of last word $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF ; Strip string to point reached $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word) ; Trim leading whitespace $asLines[$j] = StringStripWS($asLines[$j], 1) ; Repeat with remaining characters in line EndIf WEnd ; Add the number of wrapped lines to the count $iLine_Count += $iWrap_Count ; Clean up _WinAPI_ReleaseDC($hWnd, $hDC) GUICtrlDelete($hText_Label) EndIf Next ; Convert lines to pixels and add reduced margin $avSize_Info[3] = ($iLine_Count * $avSize_Info[1]) + 4 EndIf ; Clean up GUIDelete($hGUI) ; Return array Return $avSize_Info EndFunc ; => _StringSize #cs ; StringSize Test example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; This Test code includes the fully commented StringSize code ; Hence the need for these include files #include <WindowsConstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> ; These include lines are contained in the code of the UDF itself Global $aFont[4] = ["Arial", "Tahoma", "Courier New", "Comic Sans MS"] Global $aSize[4] = [9, 12, 10, 15] Global $aWeight[4] = [200, 400, 600, 800] Global $aAttrib[4] = [0, 2, 4, 0] Global $aMaxWidth[4] = [250, 300, 400, 500] Global $aColour[4] = [0xFFFF88, 0xBBFF88, 0xBB88FF, 0xFF88FF] Global $aButMsg[4] = ["Press for next example", "Click here", "Please push", "And the next one please..."] $sLabelMsg = "This is a message with very long lines which are unlikely to fit within the maximum width specified. " & _ "This UDF will return the size of rectangle needed to display it in a selected font and size." & @CRLF & @CRLF & _ "The GUI can then be sized to fit and accurately placed on screen. Other controls, such as the automatically " & _ "sized button under this label, can also be accurately positioned relative to the text." GUICreate("String Sizing Test", 500, 500) GUISetState() While 1 $sFont = $aFont[Random(0, 3, 1)] $iSize = $aSize[Random(0, 3, 1)] $iWeight = $aWeight[Random(0, 3, 1)] $iAttrib = $aAttrib[Random(0, 3, 1)] $iMaxWidth = Random(200, 850, 1) $iColour = $aColour[Random(0, 3, 1)] $sButMsg = $aButMsg[Random(0, 3, 1)] $aButReturn = _StringSize($sButMsg) $aMsgReturn = _StringSize($sLabelMsg, $iSize, $iWeight, $iAttrib, $sFont, $iMaxWidth) $iError = @error If IsArray($aMsgReturn) = 1 Then WinMove("String Sizing Test", "", (@DesktopWidth - ($aMsgReturn[2] + 25)) / 2, (@DesktopHeight - ($aMsgReturn[3] + 85)) / 2, $aMsgReturn[2] + 25, $aMsgReturn[3] + 85 ) $hLabel = GUICtrlCreateLabel($aMsgReturn[0], 10, 10, $aMsgReturn[2], $aMsgReturn[3], 1) GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sFont) GUICtrlSetBkColor(-1, $iColour) $hNext = GUICtrlCreateButton($sButMsg, ($aMsgReturn[2] - $aButReturn[2]) / 2, $aMsgReturn[3] + 20, $aButReturn[2] + 20, 30) While 1 $iMsg = GUIGetMsg() If $iMsg = -3 Then Exit If $iMsg = $hNext Then ExitLoop WEnd GUICtrlDelete($hNext) GUICtrlDelete($hLabel) Else MsgBox(0, "Error", "Code = " & $iError) EndIf WEnd Exit ; End of example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #ceThe script is commented liberally, so I hope you can follow what is going on. To use it as a UDF just save it as StringSize.au3 and then use #include to load it into your script.Please ask if you want/need more information/help on how to use it.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Fr33b0w Posted October 28, 2009 Author Posted October 28, 2009 Freebow, I wrote a UDF a while ago to wordwrap text to fit in fixed width labels and GUIs. I hope it will do what you want. Here is the UDF with an example commented out at the end - just remove the #cs/#ce lines: [autoit] Please ask if you want/need more information/help on how to use it. M23 Hey! That was great! Yes it will help me a lot! I will try it later because I have a bad headache and all because of that problem I HAD. Thank you very much and also to Zedna from CZ which was reading and I guess also tried to help but You were faster. THANKS once again!
Fr33b0w Posted October 29, 2009 Author Posted October 29, 2009 Well I gotta be honest, it cant help me much with the thing I want to do... I must have on left and right side some decorative characters and I have to fit that to look good. So I have to insert spaces (blanks) on the left and right side so it will look nice. I didn't wanted to mention that because I think I can manage with that part. The trouble is that I cant get it done now. I have to count values I have for every single character from the text that must be inserted. What I need to do is like this: I have for example a "Please help me with this thing" sentence. I have to read "P" and then add "P" character value to the counter, then to read "l" and "e" and "a" and so on counting values for every character in the text. When counter hits boundary it means that text so far checked its to wide for certain font style and size and I have to check previous space character " " and all text until that one last space " " put in line 1. Then I have to see how much space I need to fill in the first line and to add " " spaces from both side equally so it will look good there where I want to put it. And then I need to go to the next line and next until all text is entered and counted properly. I will give You an example how that would look... "AutoIt is a freeware automation language for Microsoft Windows. In its earliest release, the software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs but has since grown to include enhancements in both programming language design and overall functionality." -#- AutoIt is a freeware automation language for Microsoft Windows. -#- -#- In its earliest release, the software was primarily intended to create -#- -#- automation scripts (sometimes called macros) for Microsoft Windows programs -#- -#- but has since grown to include enhancements in both programming language -#- -#- design and overall functionality. -#- I guess I wouldnt have problems to code how much space I need to insert on left and right side and then to add "-#-" at the start and end of every line if I manage to do counting part for every character that I want to insert. In this example there is too much space on left and right side for almost every sentence and script would made it to fit as much as it can so I dont have a problem with that. My problem is basicly how to count characters with my own value for every one and each from some text... an You help me a bit with that? I am stuck...
Moderators Melba23 Posted October 29, 2009 Moderators Posted October 29, 2009 Freebow, Well I gotta be honest, it cant help me much with the thing I want to doYou give up far too easily! Use a bit of lateral thinking and make the 3 elements - border, text, border - into 3 separate labels which you can use to compose the whole thing. It just needs a bit of a basic maths to do the calculations on where to place the labels: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringSize.au3> $sText = "AutoIt is a freeware automation language for Microsoft Windows." & @CRLF & "In its earliest release, the " & _ "software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs " & _ "but has since grown to include enhancements in both programming language design and overall functionality." $sBorder1 = "-#- " $sBorder2 = " -#-" $hGUI = GUICreate("Test", 500, 500) GUISetState() ; Let us assume that you want to fit in a label of 400 width total ; Find out how wide a border will be - they will both be the same as they have the same characters in a different order: $aBorder = _StringSize($sBorder1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is just to show the working as we go along ConsoleWrite($aBorder[2] & @CRLF) ; I get 24 as an answer ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; We need to get the text to fit in 400 less the 2 borders $iTextWidth = 400 - $aBorder[2] - $aBorder[2] ; Now fit the text into a label of the correct size $aMainText = _StringSize($sText, Default, Default, Default, Default, $iTextWidth) ; We need to know how many lines we use when the text is wrapped $iLineCount = Int($aMainText[3] / $aMainText[1]) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is just to show the working as we go along ConsoleWrite($iLineCount & @CRLF) MsgBox(0, "", $aMainText[0]) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; So we need to create a border with that many lines $sFullBorder1 = $sBorder1 ; First lines $sFullBorder2 = $sBorder2 For $i = 1 To $iLineCount - 1 $sFullBorder1 &= @CRLF & $sBorder1 ; Additional lines, each on a new line $sFullBorder2 &= @CRLF & $sBorder2 Next ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is just to show the working as we go along MsgBox(0, "", $sFullBorder1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Now put it all together using the values from the StringSize function GUICtrlCreateLabel($sFullBorder1, 10, 10, $aBorder[2], $aMainText[3]) GUICtrlSetBkColor(-1, 0xFF8888) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Just so you can see the label GUICtrlCreateLabel($aMainText[0], 10 + $aBorder[2], 10, $aMainText[2], $aMainText[3], $SS_CENTER) GUICtrlSetBkColor(-1, 0x88FF88) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Just so you can see the label GUICtrlCreateLabel($sFullBorder2, 10 + $aBorder[2] + $aMainText[2], 10, $aBorder[2], $aMainText[3]) GUICtrlSetBkColor(-1, 0x8888FF) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Just so you can see the label While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I hope that gives you enough to carry on with your project. Just remove all the <<<<<<<<<<<<<<< lines and it will be good to go! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Fr33b0w Posted October 29, 2009 Author Posted October 29, 2009 Oh man You are trying to help me a lot. When I saw this it was and it still is a science fiction for me. You did all this in one day? It would took me more then a month to get to even half of this You wrote and I am very very grateful to You! This code is incredible but, as You getting to know me, I still have one little problem. I need that text to paste into another application, so I need that text able to be copied. I did changed Your GUICtrlCreateLabel into GUICtrlCreateEdit at the end and I got text to be copied but what I am missing are physical spaces between -#- and text. I have to format text "WITH SPACES". That's why I created a values for every separate char (a=6, b=6, c=6 i=2). If the font would be fixed width then it would be easy just to calculate number of chars used in one line and rest would be filled with space chars and it would be perfect. Problem is that they are using one particular font and size which cant be changed to fixed width and I need to enter text that will be well formated. Chars have different pixel width so its not easy to calculate how wide text will be. I made a table with pixel width of every character that could be used so I can calculate text width. So if I wrote for example "this guy is helping me a lot" it would be counted like this: t=4 + h=6 + i=2 + s=5 and thats 17 so far then goes space between "this" and "guy" which is 3 so that's 20, and then for "guy" g=6 + u=6 + y=6 and thats previous 20 + 6 + 6 + 6 = 38... and so on and so on... Lets say I need width of 400 for every line and I got a score of 396 when all letter values are added I need to add one space " " after and one space " " before text -#- text -#-. In another example if I get 387 as a result then I need to fill space before and after text with 13 pixel spaces total. One space has 3 pixel width so it would fit 2x "space" before and 2x "space" after so its 12 in total. It can't be perfect so closest number I can get but to be lower then 400 which is max width! In another example if I get 365 as text width (last line at the bottom of whole text or something) I need 35 pixels to fill with space, half before and half after text. It would be 11 space chars which is 33 (11x3) and it would result as 5 spaces before and 6 spaces after the text. I really don't know how far is Your code from this problem I have. Maybe that what I wrote isn't a way for that problem to be solved. What I know is that I spent so many time trying to do it and I simply couldn't. I need to learn much more to be able to do it and I will also learn from Your code You gave me. Its of a big value to me because its great! What I did with AutoIt so far were basic scripts like script which will move a map with mouse and take screenshots with hypersnap to get parts of the map which I could join in photoshop (for my job at the field), Script for email which will store data in .ini file of every contact I have and in every mail it would write statistics (first mail and last mail with date and time, mail counter for every person, date and time when i started and finished writing an email [that would be added at the end of a email message), Script which would connect 3 programs together in order to record shows on the local radio and save them by name of the show, date and time. Scripts for searching the web, Script which will make folders from one text file: #include <string.au3> #include <date.au3> #include <file.au3> While 1 $cnt01 = 0 $file = "text.txt" $dir="Storage\" $CountLines = _FileCountLines("text.txt") Do $spath=FileReadLine($file,$cnt01) DirCreate($dir & $spath) $cnt01 = $cnt01 + 1 Until $cnt01 > $CountLines Exit WEnd I know this script is long and it can be coded in a few lines but thats just me, and the script is working so it helps me a lot. I did wrote more then 65 simple scripts so far, some are small some are very long but all with simple commands. My knowledge is very basic and I am stuck with this one. I wish I could easily reedit Your script and get what I want but I must say I can't. At least not this week... or even month or so... I hope that You do understand what the problem is and that there is better solution then counting chars width like I did try up above. What do You think? Thank You very very much for helping me so far!
Moderators Melba23 Posted October 29, 2009 Moderators Posted October 29, 2009 Freebow,Some people are never satisfied! This script will produce a single text string which includes the borders, so there is no problem pasting it into another application. However, there remains one small problem - with proportionally spaced fonts, you can never quite guarantee to make the exact line length when adding spaces, so the right margin can look a bit ragged sometimes:expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringSize.au3> $sText = "AutoIt is a freeware automation language for Microsoft Windows." & @CRLF & "In its earliest release, the " & _ "software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs " & _ "but has since grown to include enhancements in both programming language design and overall functionality." $sBorder1 = "-#- " $sBorder2 = " -#-" $hGUI = GUICreate("Test", 500, 500) GUISetState() ; Let us assume that you want to fit in a label of 400 width total $iLabelWidth = 400 ; Find out how wide a border will be - they will both be the same as they have the same characters in a different order: $aBorder = _StringSize($sBorder1) ; We need to get the text to fit in 400 less the 2 borders $iTextWidth = $iLabelWidth - $aBorder[2] - $aBorder[2] ; Now fit the text into a label of the correct size $aMainText = _StringSize($sText, Default, Default, Default, Default, $iTextWidth) ; Now get the wrapped text into separate lines $aLineCount = StringSplit($aMainText[0], @CRLF, 1) ; For each line, measure the size of the text and 2 borders and add spaces to fill to max size $sLabelText = "" For $i = 1 To $aLineCount[0] $sInterval1 = "" $sInterval2 = "" ; Check we actually have a line to work on - StringSplit with @CRLF can produce blanks! If $aLineCount[$i] = "" Then ContinueLoop ; Check if any padding needed - if not then skip the loop $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine) If $aLineSize[2] >= $iLabelWidth Then ContinueLoop While 1 ; Add a space to the first interval and try again $sInterval1 &= " " $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine) If $aLineSize[2] >= $iLabelWidth Then $sInterval1 = StringTrimRight($sInterval1, 1) ExitLoop EndIf ; Add a space to the second interval and try again $sInterval2 &= " " $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine) If $aLineSize[2] >= $iLabelWidth Then $sInterval2 = StringTrimRight($sInterval2, 1) ExitLoop EndIf WEnd ; We now have the right sized line, so add it to the final text string $sLabelText &= $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 & @CRLF Next ; Display the string GUICtrlCreateLabel($sLabelText, 10, 10, $iLabelWidth, $aMainText[3]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndIf you feel that this script is getting close to what you want, I will try to work on the right margin problem this evening.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Fr33b0w Posted October 30, 2009 Author Posted October 30, 2009 No, please don't feel that way, I am not unsatisfied! It also gets to look like I am torture You or something so I got minus reputation. I am really trying my best here to explain what the problem is and I am very grateful to You. In every post You answered me there is a lot of work, no one can denied. My problem is that this what I wanted to do looked simple at first and was thinking I could manage it somehow. But all the sudden I stuck because I am down with knowledge of AutoIt coding. You set me a new goal to achieve in coding and properly explain what is going on in a script. I just need time to understand that. This script is almost exact thing I wanted to get. I just don't know how it calculates the border and character width. I didn't even know that it can be done like this You did. I have tried to change font in Your script because I need tahoma sized 8.5 (no bold, no underline, no italic, just normal one) and font changed but calculating didn't. If there is a way to change font upon script calculates how width text have - problem is solved. Right border can't be perfect and it sometimes must have 2 or 1 pixel runaway because "space" (which we use to fix the width) is 3 pixels wide. I cant help You in Autoit... I cant help You in finance... I can give You reputation for Your help which I did and I could send You some postcards or something from my country which I would love to do. You contribute a lot to Autoit world by writing UDF stuff and helping out others. You don't need another idiot to deal with like me If this script annoys You or giving You hard time, just leave it, its not worth it! It don't have a value to You as it has to me. I will get it someday and I will not give up. You asked me to tell You if this script is getting close to thing I wanted... It is 99% of what I wanted to do! If script can calculate width in tahoma 8.5 size font then script is done! But I dont have a clue is changing font is a big deal or not... If it is please just drop it! You already spend much more of your valuable time then You should on this... THANK YOU!
Moderators Melba23 Posted October 30, 2009 Moderators Posted October 30, 2009 (edited) Fr33b0w, CHANGE YOUR AVATAR IMMEDIATELY, PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! If you need to change font, you need to tell Autoit which one you want to use - you can see where I have added the font information in this code: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringSize.au3> $sText = "AutoIt is a freeware automation language for Microsoft Windows." & @CRLF & "In its earliest release, the " & _ "software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs " & _ "but has since grown to include enhancements in both programming language design and overall functionality." $sBorder1 = "-#- " $sBorder2 = " -#-" $hGUI = GUICreate("Test", 500, 500) GUISetState() ; Let us assume that you want to fit in a label of 400 width total $iLabelWidth = 400 ; Find out how wide a border will be - they will both be the same as they have the same characters in a different order: $aBorder = _StringSize($sBorder1, 8.5, Default, Default, "tahoma") ; We need to get the text to fit in 400 less the 2 borders $iTextWidth = $iLabelWidth - $aBorder[2] - $aBorder[2] ; Now fit the text into a label of the correct size $aMainText = _StringSize($sText, 8.5, Default, Default, "tahoma", $iTextWidth) ; Now get the wrapped text into separate lines $aLineCount = StringSplit($aMainText[0], @CRLF, 1) ; For each line, measure the size of the text and 2 borders and add spaces to fill to max size $sLabelText = "" For $i = 1 To $aLineCount[0] $sInterval1 = "" $sInterval2 = "" ; Check we actually have a line to work on - StringSplit with @CRLF can produce blanks! If $aLineCount[$i] = "" Then ContinueLoop ; Check if any padding needed - if not then skip the loop $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine, 8.5, Default, Default, "tahoma") If $aLineSize[2] >= $iLabelWidth Then ContinueLoop ConsoleWrite($sFullLine & " - " & $aLineSize[2] & " - " & "Start" & @CRLF) While 1 ; Add a space to the first interval and try again $sInterval1 &= " " $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine, 8.5, Default, Default, "tahoma") ConsoleWrite($sFullLine & " - " & $aLineSize[2] & " - " & "Add 1" & @CRLF) If $aLineSize[2] >= $iLabelWidth Then $sInterval1 = StringTrimRight($sInterval1, 1) ExitLoop EndIf ; Add a space to the second interval and try again $sInterval2 &= " " $sFullLine = $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 $aLineSize = _StringSize($sFullLine, 8.5, Default, Default, "tahoma") ConsoleWrite($sFullLine & " - " & $aLineSize[2] & " - " & "Add 2" & @CRLF) If $aLineSize[2] >= $iLabelWidth Then $sInterval2 = StringTrimRight($sInterval2, 1) ExitLoop EndIf WEnd ; We now have the right sized line, so add it to the final text string $sLabelText &= $sBorder1 & $sInterval1 & $aLineCount[$i] & $sInterval2 & $sBorder2 & @CRLF Next ; Display the string GUICtrlCreateLabel($sLabelText, 10, 10, $iLabelWidth, $aMainText[3]) GUICtrlSetFont(-1, 8.5, Default, Default, "tahoma") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I have looked into the right border problem and I do not believe there is a solution - sorry. gets to look like I am torture You or somethingDo not worry - if I was unhappy I would just not answer you! M23 P.S. By the way, it was not me who made the -1 rep - I do not use that function. Edited October 30, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jvanegmond Posted October 30, 2009 Posted October 30, 2009 Hahaha, I laughed so hard about that avatar. xDDD github.com/jvanegmond
Moderators Melba23 Posted October 30, 2009 Moderators Posted October 30, 2009 Manadar, After the first moment of disbelief I must confess I laughed too! Although I still want it changed! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Fr33b0w Posted October 30, 2009 Author Posted October 30, 2009 (edited) Quick reply, sorry didn't meant no harm really. Just wanted to show You that I really appreciate that what You are doing to help me... I must check the script but I think It will save me a lot of time. Once again thanks and sorry for that avatar thing, it wasn't on purpose! Will make another reply a bit later...I have looked into the right border problem and I do not believe there is a solution - sorry. Script works perfectly!!! You are a... ... hmmm what to say here not to get You mad?! Eh... You did the script that works 100%! I asked for a little help but when I saw that You are compiling a script which I couldn't change my way all I had to do is just shut up because it would took me a months to try to reedit something. P.S. By the way, it was not me who made the -1 rep - I do not use that function.You could give 1000 minus reps I don't care! It did someone who even didn't want to help! 1000 minus reps would be worth it really for this! If I could code the script I would include some tables and stuff in to that script and I doubt it would ever work the way I wanted to. Also in Your script I can use any char I like because it will all be sorted out. For this right border sort thing - IT CANT BE DONE BETTER even if You do it manually! And that's the exact thing I wanted to GET! EXACT! I will sent You a PM later, don't want to write anything here. I have been funny enough And once again - sorry for the avatar, I really didn't want to disgrace You in any way! Edited October 30, 2009 by Fr33b0w
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now