Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

truetype font: problem with size

Discussion
2006-04-05
2013-04-09
  • Professor_x
    Professor_x
    2006-04-05

    size work! But you can't use size.h or size.w

    solution: use size[0] and size[1]....

     
    • Renne Nissinen
      Renne Nissinen
      2006-04-05

      The Array#w and Array#h methods actually return elements [2] and [3] (as in a [x,y,w,h] array). You could use size.x and size.y, if you think it improves readability over size[0] :)

       
    • Professor_x
      Professor_x
      2006-04-11

      this is my test:

      require "RUDL"
      include RUDL
      include Constant

      # open a window

      window= RUDL::DisplaySurface.new([640, 480])
      # set window title

      window.set_caption "Aligne Truetype font program"

      font=TrueTypeFont.new('media/goose.ttf', 16)
      str= 'Hello world'
      text=[]
      maxchar = 48
      txtRef=Array.new(48,'r').to_s

      txtRefDim=font.size(txtRef)
      txtRefWidth= txtRefDim[0].to_i
      txtRefHeight=txtRefDim[1].to_i
      #$stderr.puts(txtRefWidth.to_s )
      #$stderr.puts(txtRefHeigh.to_s )

      text.push(str.rjust(maxchar))
      text.push(str.ljust(maxchar))
      text.push(str.center(maxchar))
      text.push(str.ljust(maxchar/2) + str.rjust(maxchar/2))

      border = 3
      x = txtRefWidth+ border * 2
      y = (txtRefHeight + txtRefHeight/3) * 4

      text_buffer = Surface.new([x,y])
      text_buffer.filled_rectangle([0, 0, x, y], [0, 20, 255])

      text_buffer.filled_rectangle([border, border, x - border * 2, y - border * 2], [255, 0, 0])
      yy = border
      text.each do |data|
           textsize=font.size(data)
          xx = (textsize[0].to_i )/ 2 + border
          text_buffer.blit(font.render(data, true, [255,255,255]),[xx,yy])
          yy = (txtRefHeight + txtRefHeight/3) +yy
      end
      window.blit(text_buffer,[ (640-x)/2, y])
      window.flip
      #gets
      loop do
          # wait for an input event
          ev = EventQueue.wait

          # exit if the window was closed
          break if ev.is_a? QuitEvent
      end

      It's work as it is (not as i was hoping...)

      I made many attemp to use size.h and size.w, without success. How would you modified it?