Permalink
Browse files

Made the CJK language names display in their own language

A language_name_font is added which contains only characters used by any
language name, and this is used for the language_name labels, regardless
of locale.
  • Loading branch information...
1 parent db3632d commit 57b5008e386167e5210457ddc857123300297c6b @hagabaka hagabaka committed May 6, 2013
View
@@ -3,6 +3,7 @@
"@include data/number_font_large.cfg",
"@include data/outline_font.ja.cfg",
"@include data/label_font.ja.cfg",
- "@include data/dialog_font.ja.cfg"
+ "@include data/dialog_font.ja.cfg",
+ "@include data/language_name_font.cfg",
],
}
View
@@ -1,6 +1,7 @@
{
font: ["@flatten",
"@include data/number_font_large.cfg",
+ "@include data/language_name_font.cfg",
"@include data/outline_font.ko.cfg",
"@include data/label_font.ko.cfg",
"@include data/dialog_font.ko.cfg"
View
@@ -1,6 +1,7 @@
{
font: ["@flatten",
"@include data/number_font_large.cfg",
+ "@include data/language_name_font.cfg",
"@include data/outline_font.zh_CN.cfg",
"@include data/label_font.zh_CN.cfg",
"@include data/dialog_font.zh_CN.cfg"
View
@@ -0,0 +1,151 @@
+ {
+ kerning: 1,
+ id: "language_names",
+ texture: "gui/language_name_font.png",
+ pad: 0,
+ chars: [
+ {
+ chars: "G",
+ rect: [0,0,3,16]
+ },
+ {
+ chars: "E",
+ rect: [14,0,17,16]
+ },
+ {
+ chars: "a",
+ rect: [28,0,32,16]
+ },
+ {
+ chars: "",
+ rect: [42,0,54,16]
+ },
+ {
+ chars: "e",
+ rect: [56,0,59,16]
+ },
+ {
+ chars: "n",
+ rect: [70,0,73,16]
+ },
+ {
+ chars: "ê",
+ rect: [0,17,3,33]
+ },
+ {
+ chars: "h",
+ rect: [14,17,17,33]
+ },
+ {
+ chars: "",
+ rect: [28,17,40,33]
+ },
+ {
+ chars: "i",
+ rect: [42,17,42,33]
+ },
+ {
+ chars: "",
+ rect: [56,17,69,33]
+ },
+ {
+ chars: "o",
+ rect: [70,17,73,33]
+ },
+ {
+ chars: "",
+ rect: [0,34,13,50]
+ },
+ {
+ chars: "t",
+ rect: [14,34,16,50]
+ },
+ {
+ chars: "",
+ rect: [28,34,40,50]
+ },
+ {
+ chars: "d",
+ rect: [42,34,45,50]
+ },
+ {
+ chars: "g",
+ rect: [56,34,59,50]
+ },
+ {
+ chars: ")",
+ rect: [70,34,71,50]
+ },
+ {
+ chars: "s",
+ rect: [0,51,3,67]
+ },
+ {
+ chars: "p",
+ rect: [14,51,17,67]
+ },
+ {
+ chars: "",
+ rect: [28,51,41,67]
+ },
+ {
+ chars: "D",
+ rect: [42,51,45,67]
+ },
+ {
+ chars: "",
+ rect: [56,51,68,67]
+ },
+ {
+ chars: "l",
+ rect: [70,51,71,67]
+ },
+ {
+ chars: "à",
+ rect: [0,68,4,84]
+ },
+ {
+ chars: "ç",
+ rect: [14,68,17,84]
+ },
+ {
+ chars: "B",
+ rect: [28,68,31,84]
+ },
+ {
+ chars: "P",
+ rect: [42,68,45,84]
+ },
+ {
+ chars: "F",
+ rect: [56,68,59,84]
+ },
+ {
+ chars: "u",
+ rect: [70,68,73,84]
+ },
+ {
+ chars: "r",
+ rect: [0,85,2,101]
+ },
+ {
+ chars: " ",
+ rect: [14,85,17,101]
+ },
+ {
+ chars: "ñ",
+ rect: [28,85,31,101]
+ },
+ {
+ chars: "(",
+ rect: [42,85,43,101]
+ },
+ {
+ chars: "c",
+ rect: [56,85,59,101]
+ },
+ {
+ chars: "I",
+ rect: [70,85,72,101]
+ },
+] }
View
@@ -1,18 +1,17 @@
{
"de": "Deutsch",
-// "el": "Ελληνικά (Ellinika)",
+# "el": "Ελληνικά (Ellinika)",
"en": "English",
-// "eo": "Esperanto",
+# "eo": "Esperanto",
"es": "Español",
"fr": "Français",
"gd": "Gàidhlig",
"it": "Italiano",
-// "ja": "日本語 (Nihongo)",
-// "pl": "Polski",
+# "ja": "日本語",
+# "pl": "Polski",
"pt_BR": "Português (Brasil)",
-// "ru": "Русский (Russkij)",
-// "sk": "Slovenčina",
-// "zh_CN": "简体中文 (Jiăntĭ Zhōngwén)",
- "zh_CN": "Simplified Chinese",
- "ko": "Korean"
+# "ru": "Русский",
+# "sk": "Slovenčina",
+ "zh_CN": "简体中文",
+ "ko": "한국말",
}
@@ -3,6 +3,7 @@ font: ["@flatten",
"@include data/number_font_large.cfg",
"@include data/outline_font.cfg",
"@include data/label_font.cfg",
- "@include data/dialog_font.cfg"
+ "@include data/dialog_font.cfg",
+ "@include data/language_name_font.cfg",
],
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,104 @@
+#!/usr/bin/env ruby
+
+require './image_size.rb'
+images_gui_path = File.expand_path('../../images/gui')
+
+help = <<"HELP"
+ This script builds a font cfg and texture from a list of glyphs.
+
+Usage
+
+ #$0 GLYPH-DIRECTORY FONT-NAME FONT-ID [PADDING [KERNING]]
+
+ FONT-NAME
+ The path of the .cfg file to create. The basename of this path also
+ determines the basename of the texture to create, which is saved
+ in #{images_gui_path}.
+
+ FONT-ID, PADDING, KERNING
+ Values of the id, padding and kerning attributes in the created .cfg file.
+
+ GLYPH-DIRECTORY
+ Directory containing glyph .png images, the basenames of which are
+ codepoints of their characters.
+HELP
+
+# Quote a character in FML
+def fml_quote(character)
+ case character
+ when '"'
+ %("\\"")
+ when "'"
+ %("'")
+ else
+ %("#{character}")
+ end
+end
+
+abort help unless ARGV.length == 3
+
+glyph_directory = ARGV[0]
+font_cfg_path = ARGV[1]
+font_id, padding, kerning = ARGV[2..4]
+
+texture_name = "#{File.basename(font_cfg_path, '.cfg')}.png"
+texture_path = File.join images_gui_path, texture_name
+characters = []
+glyphs = Dir.new(glyph_directory).select do |name|
+ codepoint = Integer(File.basename(name, '.png')) rescue nil
+ if codepoint
+ characters << codepoint.chr(Encoding::UTF_8)
+ end
+end
+glyphs.map! {|basename| "#{glyph_directory}/#{basename}"}
+
+abort help if glyphs.empty?
+
+puts "Saving #{texture_path}"
+# Montage the font texture
+system 'montage', '-background', 'transparent', '-gravity', 'SouthWest', *glyphs,
+ '-geometry', '1x1+0+0<', "png32:#{texture_path}"
+
+# For iOS optimization, the textures need to have even width and height
+(texture_width, texture_height) = image_size(texture_path).map {|length| length + length % 2}
+system 'convert', texture_path, '-gravity', 'NorthWest', '-background', 'transparent',
+ '-extent', "#{texture_width}x#{texture_height}", "png32:#{texture_path}"
+
+# Generate .cfg file
+glyph_width = {}
+glyph_height = {}
+
+characters.each_with_index do |character, index|
+ (glyph_width[character], glyph_height[character]) = image_size(glyphs[index])
+end
+
+(grid_width, grid_height) = [glyph_width, glyph_height].map {|h| h.values.max}
+columns = texture_width / grid_width
+
+File.open(font_cfg_path, 'w') do |cfg|
+ cfg.write <<-HEAD
+ {
+ kerning: #{kerning || 1},
+ id: "#{font_id}",
+ texture: "gui/#{texture_name}",
+ pad: 0,
+ chars: [
+ HEAD
+
+ characters.each_slice(columns).each_with_index do |row, row_index|
+ row.each_with_index do |character, column_index|
+ left = column_index * grid_width
+ top = row_index * grid_height
+ right = left + glyph_width[character] - 1
+ bottom = top + grid_height - 1
+ cfg.write <<-CHARS
+ {
+ chars: #{fml_quote(character)},
+ rect: [#{left},#{top},#{right},#{bottom}]
+ },
+ CHARS
+ end
+ end
+ cfg.write '] }'
+end
+
Oops, something went wrong.

0 comments on commit 57b5008

Please sign in to comment.