Skip to content

Commit

Permalink
Improve the support for replacing nonexistent characters
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Jul 9, 2013
1 parent 19e7ac9 commit c38d897
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions decoder/mf_justify.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void render_left(const struct mf_font_s *font,
if (c2 == '\t')
{
x = mf_round_to_tab(font, x0, x);
c1 = c2;
c1 = ' ';
continue;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ static void render_right(const struct mf_font_s *font,
if (c1 == '\t')
{
x = mf_round_to_prev_tab(font, x0, x);
c2 = c1;
c2 = ' ';
continue;
}

Expand Down
30 changes: 29 additions & 1 deletion encoder/c_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cctype>
Expand Down Expand Up @@ -222,6 +223,33 @@ static void encode_character_range(std::ostream &out, const DataFile &datafile,
write_table(out, offsets, "uint16_t", "glyph_offsets_" + std::to_string(range_index), 4);
}

// Select the character to use as a fallback.
static int select_fallback_char(const DataFile &datafile)
{
std::set<int> chars;

size_t i = 0;
for (const DataFile::glyphentry_t &g: datafile.GetGlyphTable())
{
for (size_t c: g.chars)
{
chars.insert(c);
}
i++;
}

if (chars.count(0xFFFD))
return 0xFFFD; // Unicode replacement character

if (chars.count(0))
return 0; // Used by many BDF fonts as replacement char

if (chars.count('?'))
return '?';

return ' ';
}

void write_source(std::ostream &out, std::string name, const DataFile &datafile)
{
name = to_identifier(name);
Expand Down Expand Up @@ -268,7 +296,7 @@ void write_source(std::ostream &out, std::string name, const DataFile &datafile)
out << " " << datafile.GetFontInfo().baseline_x << ", /* baseline x */" << std::endl;
out << " " << datafile.GetFontInfo().baseline_y << ", /* baseline y */" << std::endl;
out << " " << datafile.GetFontInfo().line_height << ", /* line height */" << std::endl;
out << " " << "0, /* fallback character */" << std::endl;
out << " " << select_fallback_char(datafile) << ", /* fallback character */" << std::endl;
out << " " << "&mf_rlefont_character_width," << std::endl;
out << " " << "&mf_rlefont_render_character," << std::endl;
out << " }," << std::endl;
Expand Down
1 change: 1 addition & 0 deletions tests/example_text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Very_long_words_that_just_keep_going_and_going_for_many_lines_at_a_time_causing_

Non breaking spaces — they will prevent line wrapping just as efficiently and cause cutoffs at random points of the line.

Unknown characters: ㎔☠
Binary file modified tests/layout/fixed_7x14_left_600.bmp.expected
Binary file not shown.
Binary file modified tests/layout/serif16_center_500.bmp.expected
Binary file not shown.
Binary file modified tests/layout/serif16_justified_500.bmp.expected
Binary file not shown.
Binary file modified tests/layout/serif16_left_500.bmp.expected
Binary file not shown.
Binary file modified tests/layout/serif16_right_500.bmp.expected
Binary file not shown.

0 comments on commit c38d897

Please sign in to comment.