Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 57b5008e386167e5210457ddc857123300297c6b 1 parent db3632d
@hagabaka hagabaka authored
View
3  data/fonts.ja.cfg
@@ -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  data/fonts.ko.cfg
@@ -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  data/fonts.zh_CN.cfg
@@ -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
151 data/language_name_font.cfg
@@ -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
17 data/languages.cfg
@@ -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": "한국말",
}
View
3  modules/frogatto/data/fonts.cfg
@@ -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",
],
}
View
BIN  modules/frogatto/images/gui/language_name_font.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
104 modules/frogatto/utils/font_generation/build_font.rb
@@ -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
+
View
92 modules/frogatto/utils/font_generation/extract_glyphs.rb
@@ -0,0 +1,92 @@
+#!/usr/bin/env ruby
+
+images_paths = ['../../../../images/', '../../images/'].map(&File.method(:expand_path))
+
+help = <<"HELP"
+ This script extracts glyphs from Frogatto fonts
+
+USAGE
+
+ #$0 OUTPUT-DIR INPUT-FONT.cfg.. < CHARACTERS
+
+ or
+
+ echo 'abcdefg' | #$0 OUTPUT-DIR INPUT-FONT.cfg..
+
+ INPUT-FONT.cfg..
+ The script will extract glyphs from the fonts defined in these .cfg files.
+
+ CHARACTERS
+ The script reads a list of characters to be extracted from stdin. If
+ a character is not defined in the first input font, the script looks
+ for it in the second intput font, and so forth.
+
+ OUTPUT-DIR
+ The script will store glyphs under , where the base name of
+ each .png file is the codepoint of its character.
+
+EXAMPLE FONT.cfg
+
+ {
+ texture: "texture.png" # path relative to #{images_paths.join(' or ')}
+ pad: 1,
+ chars: [
+ {
+ chars: "a",
+ rect: [2,1,8,20], # left, top, right, bottom
+ }
+ {
+ chars: "bc",
+ width: 6, # left + pad + width, top, right + pad + width, bottom
+ }
+ ]
+ }
+HELP
+
+require 'psych'
+require 'fileutils'
+require 'set'
+
+abort help unless ARGV.length >= 2
+
+output_dir = ARGV[0]
+input_fonts = ARGV[1..-1]
+output_characters = $stdin.read.chars.to_set
+
+FileUtils.mkdir_p output_dir
+
+input_fonts.each_with_index do |font_file, index|
+ font = Psych.load IO.read(font_file)
+ texture = images_paths.map {|path| File.join(path, font['texture'])}.find(&File.method(:exist?))
+ padding = font['pad'] || 2
+ characters = {}
+
+ left = 1
+ top = 1
+ width = 0
+ height = 0
+
+ font['chars'].each do |group|
+ if group['rect']
+ left, top, right, bottom = group['rect']
+ height, width = bottom - top + 1, right - left + 1
+
+ elsif group['width']
+ width = group['width']
+ end
+
+ group['chars'].chars.each do |character|
+ if output_characters.include? character
+ glyph_file = File.join(output_dir, "#{character.codepoints.first}.png")
+ puts "extracting glyph of '#{character}' from #{texture} at #{width}x#{height}+#{left}+#{top} to #{glyph_file}"
+ system 'convert', '-extract', "#{width}x#{height}+#{left}+#{top}",
+ texture, glyph_file
+ output_characters.delete character
+ end
+
+ # advance to the right for the next character
+ left = left + width + padding
+ end
+ end
+end
+
View
5 modules/frogatto/utils/font_generation/image_size.rb
@@ -0,0 +1,5 @@
+# Width and height of an image
+def image_size(path)
+ `file #{path}` =~ /(\d+)\s*x\s*(\d+)/
+ [$1, $2].map(&method(:Integer))
+end
View
18 modules/frogatto/utils/font_generation/make-language-name-font.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+require 'psych'
+
+tmpdir = 'tmp/language_name_font'
+
+Psych.load(File.read('../../../../data/languages.cfg')).each_pair do |code, name|
+ font = "../../../../data/label_font.#{code}.cfg"
+ if !File.exist? font
+ font = "../../../../data/label_font.cfg"
+ end
+
+ IO.popen(['./extract_glyphs.rb', tmpdir, font], 'w') do |io|
+ io.write name
+ end
+end
+
+system "./build_font.rb #{tmpdir} ../../../../data/language_name_font.cfg language_names"
View
2  src/language_dialog.cpp
@@ -85,7 +85,7 @@ void show_language_dialog()
int index = 0;
foreach(variant_map::value_type pair, languages) {
widget_ptr b(new button(
- widget_ptr(new graphical_font_label(pair.second.as_string(), "door_label", 2)),
+ widget_ptr(new graphical_font_label(pair.second.as_string(), "language_names", 2)),
boost::bind(set_locale, pair.first.as_string()),
BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
b->set_dim(button_width, button_height);
Please sign in to comment.
Something went wrong with that request. Please try again.