Python1320

Font Lister Garry's Mod

Jun 23rd, 2011
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.57 KB | None | 0 0
  1. -- By Python1320 | Do whatever you want..
  2. -- Goes to garrysmod/lua/includes/extensions/CreateFont.lua
  3.  
  4. local temp=string.Explode("\n",
  5. [[DebugFixed
  6. DebugFixedSmall
  7. DefaultFixedOutline
  8. MenuItem
  9. Default
  10. TabLarge
  11. DefaultBold
  12. DefaultUnderline
  13. DefaultSmall
  14. DefaultSmallDropShadow
  15. DefaultVerySmall
  16. DefaultLarge
  17. UiBold
  18. MenuLarge
  19. ConsoleText
  20. Marlett
  21. Trebuchet18
  22. Trebuchet19
  23. Trebuchet20
  24. Trebuchet22
  25. Trebuchet24
  26. HUDNumber
  27. HUDNumber1
  28. HUDNumber2
  29. HUDNumber3
  30. HUDNumber4
  31. HUDNumber5
  32. HudHintTextLarge
  33. HudHintTextSmall
  34. CenterPrintText
  35. HudSelectionText
  36. DefaultFixed
  37. DefaultFixedDropShadow
  38. CloseCaption_Normal
  39. CloseCaption_Bold
  40. CloseCaption_BoldItalic
  41. TitleFont
  42. TitleFont2
  43. ChatFont
  44. TargetID
  45. TargetIDSmall
  46. HL2MPTypeDeath
  47. BudgetLabel]])
  48.    
  49. local fontvalues={
  50.     "font_name",
  51.     "size",
  52.     "weight",
  53.     "antialiasing",
  54.     "additive",
  55.     "new_font_name",
  56.     "drop_shadow",
  57.     "outlined",
  58.     "blur",
  59.     "ext1",
  60.     "ext2",
  61.     "ext3",
  62.     "ext4",
  63. }  
  64. local fontvalues_print={
  65.     "Base",
  66.     "Size",
  67.     "Boldness",
  68.     "Aliased",
  69.     "Additive",
  70.     "Font name",
  71.     "Shadow",
  72.     "Outlined",
  73.     "Blurred",
  74.     "ext1",
  75.     "ext2",
  76.     "ext3",
  77.     "ext4",
  78. }
  79. local function fontvalues_toprint(name)
  80.     for k,v in pairs(fontvalues) do
  81.         if v==name then
  82.             return fontvalues_print[k]
  83.         end
  84.     end
  85.     return name
  86. end
  87.  
  88. surface.fonts=surface.fonts or {}
  89. function surface.GetFonts() return surface.fonts end
  90.  
  91. -- add default fonts
  92. for _,new_font_name in pairs(temp) do
  93.     surface.fonts[new_font_name]=surface.fonts[new_font_name] or {new_font_name=new_font_name}
  94. end
  95.  
  96. local oldCreateFont=surface.CreateFont
  97. surface.CreateFont=function( ... )
  98.    
  99.    local data={}
  100.    
  101.    for id,value in pairs{...} do
  102.       data[ fontvalues[id] ] = value
  103.    end
  104.    
  105.    local name = data.new_font_name
  106.    if name then
  107.       surface.fonts[name]=data
  108.    end
  109.    
  110.    return oldCreateFont( ... )
  111. end
  112.  
  113.  
  114.  
  115. concommand.Add('gm_showfonts',function()
  116.  
  117.    local fonts={}
  118.    for k,v in pairs( surface.GetFonts() ) do
  119.       table.insert( fonts, {
  120.          name=k,
  121.          values=v
  122.       })
  123.    end
  124.    table.SortByMember(fonts,"name",function(a,b) return a>b end)
  125.    
  126.    local a=vgui.Create'DFrame'
  127.       a:SetSizable(true)
  128.       a:SetSize(ScrW()*0.3,ScrH()*0.6)
  129.       a:DockPadding(3,21+3,3,3)
  130.       a:SetDraggable(true)
  131.       --a:DeleteOnRemove(true)
  132.       a:MakePopup()
  133.       a:SetTitle("Font Lister")
  134.  
  135.    local b=vgui.Create('DPanelList',a)
  136.       b:EnableVerticalScrollbar(true)
  137.       b:Dock(FILL)
  138.       b:SetAutoSize(false)
  139.       b:SetPadding(0)
  140.       b:SetSpacing(3)
  141.    
  142.    local c=vgui.Create('DTextEntry',a)
  143.       c:Dock(BOTTOM)
  144.       c:SetMultiline(true)
  145.       c:SetTall(a:GetTall()*0.2)
  146.       c:SetText"testing the text\ngo go go"
  147.       c:SetAllowNonAsciiCharacters(true)
  148.          
  149.    for _,v in pairs( fonts ) do
  150.  
  151.       local font      = v.name
  152.       local values   = v.values
  153.      
  154.       surface.SetFont(font)
  155.       local w,h=surface.GetTextSize"."
  156.       local w2,h2=surface.GetTextSize"W"
  157.      
  158.       local monospace=w==w2
  159.       local tall=h
  160.       local wide=w
  161.    
  162.       local cat = vgui.Create("DCollapsibleCategory",b)
  163.       cat:SetExpanded(tall<40)
  164.       cat:SetPadding(3)
  165.      
  166.       do -- WOHA
  167.          
  168.          txt =    font.. ' | ' ..tall ..' tall'..
  169.                (monospace and ", monospace, "..wide..' wide' or "")
  170.          
  171.          local bad={
  172.             ["size"]=true,
  173.             ["new_font_name"]=true,
  174.          }
  175.          
  176.          for valuename,value in pairs(values) do
  177.            
  178.             if not bad[valuename] then
  179.                txt=txt..' | '
  180.                local printable = tostring( fontvalues_toprint( valuename ) )
  181.                if value==true then
  182.                   txt=txt..printable
  183.                elseif value==false then
  184.                else
  185.                   txt=txt..printable..': '..tostring(value)
  186.                end
  187.             end
  188.            
  189.          end
  190.          
  191.       end
  192.       cat:SetLabel(txt)
  193.    
  194.       --label:SetColor(Color(255,100,100,255))
  195.       b:AddItem(cat)
  196.       local label = vgui.Create("DLabel",cat)
  197.       label:SetFont(font)
  198.       function label:OnMouseReleased(but)
  199.         c:SetFont(font)
  200.       end
  201.       label:SetText(   "Lorem ipsum dolor sit amet, consectetur adipiscing elit.".."\n"..
  202.                   "Unicode: öäåá,®©,«,²³¹,◄►,█▓▒░,←↑→↓")
  203.       label:SetWrap(true)
  204.       cat:SetContents(label)
  205.       label:SizeToContents()
  206.       --   label:InvalidateLayout()
  207.       --   label:TellParentAboutSizeChanges()
  208.       timer.Simple(0,label.SizeToContents,label)  -- wtf hax
  209.    end
  210.    
  211. end)
Advertisement
Add Comment
Please, Sign In to add comment