Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. local testGui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
  2. local testLabel = Instance.new("TextLabel", testGui)
  3. testLabel.Position = UDim2.new(1,0,1,0)
  4. testLabel.Transparency = 1
  5. testLabel.TextWrapped = true
  6.  
  7. local cache = {} --cache table is as follows: cache -> font -> fontSize -> frameSize -> text
  8. for _,font in next,Enum.Font:GetEnumItems() do
  9.     local c = {}
  10.     for _,fontSize in next,Enum.FontSize:GetEnumItems() do
  11.         c[fontSize] = {}
  12.     end
  13.     cache[font] = c
  14. end
  15.  
  16. local TextService = {}
  17.  
  18. function TextService:GetTextSize(text, font, fontSize, frameSize)
  19.     frameSize = frameSize or Vector2.new(0,0)
  20.     local frameSizeString = tostring(frameSize)
  21.     cache[font][fontSize][frameSizeString] = cache[font][fontSize][frameSizeString] or {}
  22.    
  23.     if not cache[font][fontSize][frameSizeString][text] then
  24.         testLabel.Size = UDim2.new(0,frameSize.X,0,frameSize.Y)
  25.         testLabel.Font = font
  26.         testLabel.FontSize = fontSize
  27.         testLabel.Text = text
  28.        
  29.         cache[font][fontSize][frameSizeString][text] = testLabel.TextBounds
  30.     end
  31.    
  32.     return cache[font][fontSize][frameSizeString][text]
  33. end
  34.  
  35. return TextService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement