Advertisement
Zetu

Text2IMG

Jun 8th, 2011
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.74 KB | None | 0 0
  1.                           #=====================#
  2.                           # Text to Image v1.04 #
  3.                           #=====================#
  4. module Z_Systems
  5.   module ImgText
  6.     DEFAULT = "charset"
  7.     TABLE = {
  8.     "Full" =>    [["A", "B", "C", "D", "E", "F", "G", "H"],
  9.                   ["I", "J", "K", "L", "M", "N", "O", "P"],
  10.                   ["Q", "R", "S", "T", "U", "V", "W", "X"],
  11.                   ["Y", "Z", "1", "2", "3", "4", "5", "6"],
  12.                   ["7", "8", "9", "0", "+", "-", "$", "/"]],
  13.                  
  14.     "Numbers" => [["0", "1", "2", "3", "4"],
  15.                   ["5", "6", "7", "8", "9"]]
  16.     }
  17.     DEFAULT_FONT = "Default"
  18.     FONTS = {
  19.     #Font Name => [TABLE layout, IMG Name(-.png)],
  20.     "Default"  => ["Full", "charset"],
  21.     "Numbers"  => ["Numbers", "numset"]
  22.     }
  23.   end
  24. end
  25.  
  26. #==============================================================================#
  27. # Imput: draw_img_text(string, x, y, spacing, allign, font)                    #
  28. #  string            = Contents to Convert                                     #
  29. #  x, y              = Coordinates to place Image                              #
  30. #  spacing(Def:0)    = Space between characters in string image                #
  31. #  allign(Def:0)     = 0 => Left, 1 => Right, 2 => Center                      #
  32. #  font(Def:Default) = Font to use (Includes Image and Table Layout)           #
  33. #==============================================================================#
  34.  
  35. class Window_Base
  36.   include Z_Systems::ImgText
  37.  
  38.   def draw_img_text(string, x, y, spacing = 0, allign = 0, font = DEFAULT_FONT)
  39.     string = string.to_s
  40.     return if string.length == 0
  41.     tablename, filename = FONTS[font]
  42.     move = (Cache.picture(filename).width / TABLE[tablename][0].size) + spacing
  43.     fsx = move*string.length - spacing
  44.     case allign
  45.     when 0 #Left Allign
  46.       tx = x
  47.     when 1 #Right Allign
  48.       tx = x - fsx
  49.     when 2 #Center Allign
  50.       tx = x - fsx/2
  51.     end
  52.     for char in string.upcase.split(//)
  53.       next if char == " "
  54.       for row in TABLE[tablename]
  55.         if row.include?(char)
  56.           row = TABLE[tablename].index(row)
  57.           break
  58.         end
  59.       end
  60.       col = TABLE[tablename][row].index(char)
  61.       draw_char(tx, y, row, col, font)
  62.       tx += move
  63.     end
  64.   end
  65.  
  66.   def draw_char(x, y, row, col, font)
  67.     tablename, filename = FONTS[font]
  68.     bitmap = Cache.picture(filename)
  69.     size_x = bitmap.width / TABLE[tablename][0].size
  70.     size_y = bitmap.height / TABLE[tablename].size
  71.     rect = Rect.new(0, 0, 0, 0)
  72.     rect.x = size_x*col
  73.     rect.y = size_y*row
  74.     rect.width = size_x
  75.     rect.height = size_y
  76.     self.contents.blt(x, y, bitmap, rect)
  77.     bitmap.dispose
  78.   end
  79.  
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement