私は、文字列の合計幅の割合として、文字列の文字幅のそれぞれを決定するためにRubygameを使用しようとしている...Rubygame :: TTF - 文字列の幅と全ての幅がそれの文字の違い
上記の文字列のためのrequire "rubygems" require "rubygame" include Rubygame TTF.setup $font = TTF.new "/Library/Fonts/Times New Roman.ttf", 40 total = 0 "Hello TrueType text! My name is Davide".each_char do |c| size = $font.size_text c #puts "Char: #{c} - #{size[0]}/#{total}" total = total + size[0] end puts "Size: #{$font.size_text('Hello TrueType text! My name is Davide')[0]}" puts "Total: #{total}" puts "Difference: #{total - $font.size_text('Hello TrueType text! My name is Davide')[0]}"
プログラムの出力は...
Size: 642 Total: 650 Difference: 8
です...そして、文字列の長さと内容によって異なります。
結果は近いですが...文字の幅の合計と文字列の幅の間に8の違いがある理由は誰にも分かりますか?
任意の助けをいただければ幸いです...
乾杯...
ダヴィデ私もこれを行うための他の/より良い方法についての提案を開いてる
PS。