E1M1 Posted October 31, 2010 Share Posted October 31, 2010 (edited) Could anyone help me making function that would take max height, max width and stringlen as arguments and then return max fontsize that fits with in given size? I have no idea where to start. My solution for width is something like that. $MaxFontSize = $Width/$StringLen But with this method I may still get font which height is too much. What calcus I could do for height? Edited October 31, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
JohnOne Posted November 1, 2010 Share Posted November 1, 2010 I think this thread by M23 might give you some ideas, althoug it might be the other way around. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 1, 2010 Moderators Share Posted November 1, 2010 E1M1, Look at the final posts in the thread JohnOne linked to - they are exactly what you are looking for. 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 Link to comment Share on other sites More sharing options...
E1M1 Posted November 1, 2010 Author Share Posted November 1, 2010 (edited) That's much code. I found that max char height is 1.29 or 1.25 * font size. But i am not sure if my idea works. This didn't work. $fontsizex = $rndw /StringLen($word) $fontsizey = $rndh/$fontsizex If $fontsizey > 1.2 Then $fontsizey = $fontsizey - ($fontsizey/1.3) EndIf $fontsize =4 If $fontsizey > $fontsizex Then $fontsize = $fontsizex Else $fontsize = $fontsizey EndIf Your's code is nice, but i am looking for something that would return fontsize as int. Edited November 1, 2010 by E1M1 edited Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 1, 2010 Moderators Share Posted November 1, 2010 E1M1,That's much codeBut it already written for you! 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 Link to comment Share on other sites More sharing options...
E1M1 Posted November 1, 2010 Author Share Posted November 1, 2010 ; |$array[2] = Width of rectangle required to hold formatted string ; |$array[3] = Height of rectangle required to hold formatted string That does return w,h; but i have w,h given. edited Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 1, 2010 Moderators Share Posted November 1, 2010 E1M1, So use a little initiative and run a loop to see which font size will fit within those dimensions: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StringSize.au3> Global $hlabel = 9999 $hGUI = GUICreate("Test", 500, 500) GUICtrlCreateLabel("Enter required text", 10, 10, 200, 20) $hEdit = GUICtrlCreateEdit("", 10, 30, 480, 200, $ES_WANTRETURN) GUICtrlCreateLabel("Enter available width", 10, 250, 200, 20) $hWidth = GUICtrlCreateInput("", 10, 270, 230, 20) GUICtrlCreateLabel("Enter available height", 260, 250, 200, 20) $hHeight = GUICtrlCreateInput("", 260, 270, 230, 20) $hButton = GUICtrlCreateButton("Go", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $sText = GUICtrlRead($hEdit) $iWidth = Int(Number(GUICtrlRead($hWidth))) $iHeight = Int(Number(GUICtrlRead($hHeight))) For $iTextSize = 100 To 1 Step -1 $aSize = _StringSize($sText, $iTextSize, Default, Default, "Tahoma") ; Allow for the label margins or you might loose the edges of italic fonts If $aSize[2] < $iWidth + 8 And $aSize[3] < $iHeight + 8 Then ExitLoop Next MsgBox(0, "Max Font Size", $iTextSize) _Demo() EndSwitch WEnd Func _Demo() $hLabel_1 = GUICtrlCreateLabel($sText, 10, 350, $iWidth, $iHeight) GUICtrlSetBkColor(-1, 0xC0FFC0) GUICtrlSetFont(-1, $iTextSize, Default, Default, "Tahoma") $hLabel_2 = GUICtrlCreateLabel($sText, 260, 350, $iWidth, $iHeight) GUICtrlSetBkColor(-1, 0xFFC0C0) GUICtrlSetFont(-1, $iTextSize + 1, Default, Default, "Tahoma") Sleep(5000) GUICtrlDelete($hLabel_1) GUICtrlDelete($hLabel_2) EndFunc The green label uses the calculated max font size - the red one the one above. Some fonts might still appear to fit at the larger size, but you must allow for the possibility of using italic letters - because these are sloped, you risk losing the edges if you do not allow a small margin (look for the comment in the script). Does that do what you want? 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 Link to comment Share on other sites More sharing options...
E1M1 Posted November 1, 2010 Author Share Posted November 1, 2010 For $i = 1 To 100 $sText = "0" $iWidth = 13 $iHeight = 11 For $iTextSize = 100 To 1 Step -1 $aSize = _StringSize($sText, $iTextSize, Default, Default, "Tahoma") ; Allow for the label margins or you might loose the edges of italic fonts If $aSize[2] < $iWidth + 8 And $aSize[3] < $iHeight + 8 Then ExitLoop Next Next that takes some cpu. This Get's it dont faster, but might not be so nice. $fontsizex = $rndw /StringLen($word) $fontsizey = max($fontsizex,$rndh*.80) GUICtrlSetFont(-1, $fontsizey, Random(0, 800, 1), Random(0, 14, 1), $aFonts[Random(1, $aFonts[0], 1)]) edited Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 1, 2010 Moderators Share Posted November 1, 2010 E1M1,that takes some cpuWhat is your machine powered by? A hamster in a wheel? But if you are happy with your solution..... 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 Link to comment Share on other sites More sharing options...
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