.fnt file to image labels (Custom fonts in Studio)

May I know how? Thank you. ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

hold on, I will send how at some point

1 Like

please note that the renderer section of the code is cut because I heavily modified it for something else…

local s = [[]]

local fontMap = ''

-----

local info = {}

info.fontInfo = {}
info.characterTable = {}
info.kernings = {}

local init, _ = s:find('kernings')
if init then
	local kernings = s:sub(init, s:len()):split('\n')

	local kerningsTable = info.kernings

	for i,v in ipairs(kernings) do
		local first, second, amount = v:match('kerning first=([%-?%.?%d?]+) second=([%-?%.?%d?]+) amount=([%-?%.?%d?]+)')
		if first then
			kerningsTable[utf8.char(first)] = kerningsTable[utf8.char(first)] or {}
			kerningsTable[utf8.char(first)][utf8.char(second)] = amount
		end
	end
	s = s:sub(1, init - 1)
end
local split = s:split('\n')

local characterTable = info.characterTable

for i = 3, 1, -1 do
	local infoThisIteration = split[i]:split(' ')
	for i,v in ipairs(infoThisIteration) do
		local field, value = unpack(v:split('='))
		if field and value then
			field, value = field:gsub('"', ''), value:gsub('"', '')
			info.fontInfo[field] = tonumber(value) or value
		end
	end
	table.remove(split, i)
end
table.remove(split, 1)

for i = #split, 1, -1 do
	local v = split[i]
	local charId, x, y, width, height, xOffset, yOffset, xAdvance, page, chnl = v:match('char id=([%-?%.?%d?]+) x=([%-?%.?%d?]+) y=([%-?%.?%d?]+) width=([%-?%.?%d?]+) height=([%-?%.?%d?]+) xoffset=([%-?%.?%d?]+) yoffset=([%-?%.?%d?]+) xadvance=([%-?%.?%d?]+) page=([%-?%.?%d?]+) chnl=([%-?%.?%d?]+)')
	if charId then
		table.remove(split,i)
		table.insert(characterTable, {
			charId = charId;
			x = x;
			y = y;
			width = width;
			height = height;
			xOffset = xOffset;
			yOffset = yOffset;
			xAdvance = xAdvance;
			page = page;
			chnl = chnl
		})
	end
end

local size = 0.16 ------------------SIZE IS RIGHT HERE!!!--------------------

local stringFolder = Instance.new('Folder')
stringFolder.Name = info.fontInfo.face
stringFolder.Parent = script

for i,v in ipairs(characterTable) do
	local mainFrame = Instance.new('Frame')
	mainFrame.Size = UDim2.fromOffset(v.xAdvance*size or v.width*size, size)
	mainFrame.BackgroundTransparency = 1
	mainFrame.Name = utf8.char(v.charId)
	mainFrame.BackgroundTransparency = 1
	local newLabel = Instance.new('ImageLabel')
	newLabel.Image = fontMap
	newLabel.Size = UDim2.fromOffset(v.width*size, v.height*size)
	newLabel.Parent = mainFrame
	newLabel.Name = utf8.char(v.charId)
	newLabel.Position = UDim2.fromOffset(v.xOffset*size, v.yOffset*size)
	newLabel.ImageRectSize = Vector2.new(v.width, v.height)
	newLabel.ImageRectOffset = Vector2.new(v.x, v.y)
	newLabel.Parent = mainFrame
	newLabel.BackgroundTransparency = 1
	newLabel.ScaleType = Enum.ScaleType.Fit
	newLabel.BackgroundTransparency = 1
	mainFrame.Parent = stringFolder
end

you can find the size variable at a little below the middle of the code

This is very nice but, doesnt come useful in a mobile situation., it would be nice if you could at size support between all screens, (mobile), please.

image
can’t say i will use it, but it is super cool !! thanks for the resource

Anyone know how to drop a line using this resource? It’s really easy to use but the only issue i’m facing is the fact that I can’t go down a line. I’ve tried using a UiGridLayout but realized that the size for each of the letters aren’t the same so this method won’t work.

Edit:
I’ve tried using \n in my strings but it doesn’t seem to work. I’ve also tried using spaces to go to the next line but it either creates excessive or too little amount of space.