Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how can i get charpos use variable a? — Gideros Forum

how can i get charpos use variable a?

luyimoonluyimoon Member
edited December 2021 in General questions
local f = TTFont.new("simhei.ttf",40)
local str = "一二三四五"
local tf = TextField.new(f,str)
local a,b,c = tf:getTextPositionFromPoint(0,tf:getWidth())
-----------------------------------------------
how can i get chinese char position use variable a ?
-----------------------------------------------

my description is wrong, i need "rich text" or "text area" or "multiline text", emm... how to achieve it

Comments

  • MoKaLux said:
    thanks but "getTextPositionFromPoint()" can not get chinese char position.
  • MoKaLuxMoKaLux Member
    Accepted Answer
    did you add the harfbuzz plugin?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • Like this?


    local px = Pixel.new(0xff0000, 1, 8, 8)
    px:setAnchorPoint(0.5, 0.5)
    stage:addChild(px)
     
    local f = TTFont.new("simhei.ttf",40)
    local str = "一二三四五一二三四五"
    local tf = TextField.new(f,str)
    tf:setPosition(100, 100)
    stage:addChild(tf)
     
    local len = utf8.len(str)
    local b = tf:getTextPositionFromPoint(0, tf:getWidth()) / len
     
    for i = 0, len do 
    	Timer.delayedCall(i * 400, function()
    		local x, y = tf:getPointFromTextPosition(i * b)
    		px:setPosition(tf:getX() + x, tf:getY() + y)
    	end)
    end
  • luyimoonluyimoon Member
    edited December 2021
    MoKaLux said:

    did you add the harfbuzz plugin?

    yes ,but i do not know how to use it...
  • luyimoonluyimoon Member
    edited December 2021
    rrraptor said:

    Like this?


    local px = Pixel.new(0xff0000, 1, 8, 8)
    px:setAnchorPoint(0.5, 0.5)
    stage:addChild(px)
     
    local f = TTFont.new("simhei.ttf",40)
    local str = "一二三四五一二三四五"
    local tf = TextField.new(f,str_1)
    tf:setPosition(100, 100)
    stage:addChild(tf)
     
    local len = utf8.len(str)
    local b = tf:getTextPositionFromPoint(0, tf:getWidth()) / len
     
    for i = 0, len do 
    	Timer.delayedCall(i * 400, function()
    		local x, y = tf:getPointFromTextPosition(i * b)
    		px:setPosition(tf:getX() + x, tf:getY() + y)
    	end)
    end
    emm....
    my mistake...
    i want get offset from mixed string.(like this "12取3a一sgواحدao上年")
    and use "utf8.sub()" get char or substring.
    like this
    -------------------------
    local f = TTFont.new("simhei.ttf",40)
    local str_1 = "123456"
    local tf = TextField.new(f,str)
    tf:setPosition(100, 100)
    stage:addChild(tf)

    local offset_1 = tf:getTextPositionFromPoint(tf:getWidth(),0)
    local char_1 = utf8.sub(str_1,offset_1,offset_1) -- but if "str_1" is mixed string, i cant get right offset.
  • luyimoon said:

    MoKaLux said:

    did you add the harfbuzz plugin?

    yes ,but i do not know how to use it...
    it is automatic, textfield and ttf will use it if present in the plugins :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.