#Letter spacing

21 messages · Page 1 of 1 (latest)

exotic zodiac
#

Is it possible to add letter spacing(space between each character) to characters in a text string?

inner bough
#

yourString:gsub("%w-", "%1 ")

exotic zodiac
#

It did the trick but it also turned special letters into squares :/

exotic zodiac
#

I managed to fix that now. But it will not add space after special characters like æ ø å

#

Like when my characters name is "VEKSELSTRØM" it prints it as "V E K S E L S T R ØM" do you knoiw how to fix that? 😛

inner bough
#

That would be more complex

exotic zodiac
#

I was afraid that you would say that

inner bough
#

If you want to pursue it then look up the WA UTF8sub function and use that as a guide.

exotic zodiac
#

Where do i find that ?

exotic zodiac
#

I see what you mean when you say more complex.

blissful hollow
#
local UTF8split = function(str) 
   local charArray = {}
   local iStart = 0
   local strLen = str:len()
   
   local function bit(b) 
      return 2 ^ (b - 1)
   end 
   
   local function hasbit(w, b) 
      return w % (b + b) >= b
   end 
   
   local checkMultiByte = function(i) 
      if (iStart ~= 0) then 
         charArray[#charArray + 1] = str:sub(iStart, i - 1)
         iStart = 0
      end 
   end 
   
   for i = 1, strLen do 
      local b = str:byte(i)
      local multiStart = hasbit(b, bit(7)) and hasbit(b, bit(8))
      local multiTrail = not hasbit(b, bit(7)) and hasbit(b, bit(8))
      if (multiStart) then
          checkMultiByte(i)
          iStart = i
      elseif (not multiTrail) then 
         checkMultiByte(i)
         charArray[#charArray + 1] = str:sub(i, i)
      end 
   end 
   
   checkMultiByte(strLen + 1)
   return charArray
end 

local chars = UTF8split("VEKSELSTRØM")
local letter_spaced = table.concat(chars, " ")
print(letter_spaced)

Output: V E K S E L S T R Ø M

blissful hollow
#

@exotic zodiac

exotic zodiac
#

Wow! i would have never arrived at this! 😛

hmm it gives me this error:

[string "return local UTF8split = function(str) ..."]:1 unexpected symbol near 'local'

blissful hollow
# exotic zodiac Wow! i would have never arrived at this! 😛 hmm it gives me this error: ```[s...

if you put this in the %c custom text, then you should wrap the whole thing in a function.

function()
local UTF8split = function(str) 
   local charArray = {}
   local iStart = 0
   local strLen = str:len()
   
   local function bit(b) 
      return 2 ^ (b - 1)
   end 
   
   local function hasbit(w, b) 
      return w % (b + b) >= b
   end 
   
   local checkMultiByte = function(i) 
      if (iStart ~= 0) then 
         charArray[#charArray + 1] = str:sub(iStart, i - 1)
         iStart = 0
      end 
   end 
   
   for i = 1, strLen do 
      local b = str:byte(i)
      local multiStart = hasbit(b, bit(7)) and hasbit(b, bit(8))
      local multiTrail = not hasbit(b, bit(7)) and hasbit(b, bit(8))
      if (multiStart) then
          checkMultiByte(i)
          iStart = i
      elseif (not multiTrail) then 
         checkMultiByte(i)
         charArray[#charArray + 1] = str:sub(i, i)
      end 
   end 
   
   checkMultiByte(strLen + 1)
   return charArray
end 

local chars = UTF8split("VEKSELSTRØM")
local letter_spaced = table.concat(chars, " ")
return letter_spaced
end
inner bough
#

...only, don't put functions inside WA custom code blocks. Put them in Init and place them in the aura_env table so they're not recreated and junked constantly

exotic zodiac
#

Thanks guys - i think i made it work as intended.

Is there a way to do it for numbers as well ? I don't expect it to be as easy as changing all "str" to "int" no ? 😛

exotic zodiac
#

Hey boneschock

I got a question. I figured out how to make it work with UnitName("Player") but i keep getting errors on target, targettarget and focus. Do you think you can help me out?

The code for the target is this:

function()
    local UTF8split = function(str) 
        local charArray = {}
        local iStart = 0
        local strLen = str:len()
        
        local function bit(b) 
            return 2 ^ (b - 1)
        end 
        
        local function hasbit(w, b) 
            return w % (b + b) >= b
        end 
        
        local checkMultiByte = function(i) 
            if (iStart ~= 0) then 
                charArray[#charArray + 1] = str:sub(iStart, i - 1)
                iStart = 0
            end 
        end 
        
        for i = 1, strLen do 
            local b = str:byte(i)
            local multiStart = hasbit(b, bit(7)) and hasbit(b, bit(8))
            local multiTrail = not hasbit(b, bit(7)) and hasbit(b, bit(8))
            if (multiStart) then
                checkMultiByte(i)
                iStart = i
            elseif (not multiTrail) then 
                checkMultiByte(i)
                charArray[#charArray + 1] = str:sub(i, i)
            end 
        end 
        
        checkMultiByte(strLen + 1)
        return charArray
    end 
    
    local chars = UTF8split(UnitName("target"):upper())
    local letter_spaced = table.concat(chars, " ")
    return letter_spaced
end```

It gives me this errior message:
```lua
26x Lua error in aura 'Target Name Text': Name Function (fallback state)
WeakAuras Version: 5.3.4
[string "return function()"]:39: attempt to index a nil value
[string "return function()"]:39: in function <[string "return function()"]:1>
[string "=[C]"]: in function `xpcall'
[string "@WeakAuras/GenericTrigger.lua"]:4170: in function `CreateFallbackState'
[string "@WeakAuras/GenericTrigger.lua"]:831: in function `CreateFakeStates'
[string "@WeakAuras/WeakAuras.lua"]:4193: in function `UpdateFakeStatesFor'
[string "@WeakAuras/WeakAuras.lua"]:4169: in function `FakeStatesFor'
[string "@WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua"]:1445: in function `SyncVisibility'
[string "@WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua"]:1471: in function `PriorityShow'
[string "@WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua"]:1429: in function `Pick'
[string "@WeakAurasOptions/OptionsFrames/OptionsFrame.lua"]:1316: in function `PickDisplay'
[string "@WeakAurasOptions/WeakAurasOptions.lua"]:1183: in function `PickDisplay'
[string "@WeakAurasOptions/AceGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua"]:516: in function <...eGUI-Widgets/AceGUIWidget-WeakAurasDisplayButton.lua:467>```
#

I literally only changed "player" to "target"

blissful hollow
#

Do you have a target?

exotic zodiac
#

It happens when i open /wa with and without a target