Fix various UTF-8 handling bugs; properly re-space month and day names.

This commit is contained in:
Dianne Skoll
2022-01-30 12:31:38 -05:00
parent 4c30db06c0
commit 835af9ad6a
7 changed files with 49 additions and 17 deletions

View File

@@ -340,6 +340,10 @@ month (0 = Sunday, 1 = Monday, 6 = Saturday.) And \fImonday_first\fR is
1 if the \fB\-m\fR flag was supplied to \fBRemind\fR, or 0 if it was not.
All this information is supplied so back-ends don't need any date calculation
facilities.
Note that all spaces in \fImonth_name\fR will be replaced with
underscores. Back-ends should undo this replacement.
.TP
\fIsun mon tue wed thu fri sat\fR
This line consists of
@@ -347,6 +351,9 @@ space-separated names of days in whatever language \fBRemind\fR was
compiled for. This information can be used by back-ends to annotate
calendars, and means they don't have to be created for a specific
language.
Note that all spaces in day names will be replaced with
underscores. Back-ends should undo this replacement.
.TP
\fInext_mon next_days\fR
The name of the next month and the number of days in it.

View File

@@ -248,12 +248,14 @@ sub parse_input
return 0 unless $line;
chomp($line);
($Prevmon, $Prevlen) = split(' ', $line);
$Prevmon =~ s/_/ /g;
# Nextmon nextlen
$line = <STDIN>;
return 0 unless $line;
chomp($line);
($Nextmon, $Nextlen) = split(' ', $line);
$Nextmon =~ s/_/ /g;
$found_data = 1;
my $class;

View File

@@ -120,7 +120,6 @@ sub read_one_month
# Month Year Days FirstWkday MondayFirst
if ($line =~ /^(\S+) (\d+) (\d+) (\d+) (\d+)/) {
$self->{monthname} = $1;
$self->{monthname} =~ s/_/ /g;
$self->{year} = $2;
$self->{daysinmonth} = $3;
$self->{firstwkday} = $4;
@@ -129,6 +128,7 @@ sub read_one_month
return (undef, "Cannot interpret line: $line");
}
$self->{monthname} =~ s/_/ /g;
# Day names
$line = $in->getline();
chomp($line);
@@ -155,6 +155,9 @@ sub read_one_month
return (undef, "Cannot interpret line: $line");
}
$self->{prevmonthname} =~ s/_/ /g;
$self->{nextmonthname} =~ s/_/ /g;
if ($first_line eq '# rem2ps2 begin') {
# remind -pp format
return $self->read_one_month_pp($in, $specials_accepted);
@@ -248,7 +251,7 @@ sub read_one_month_pp
{
my ($self, $in, $specials_accepted) = @_;
my $json = JSON::MaybeXS->new(utf8 => 1);
my $json = JSON::MaybeXS->new(utf8 => 0);
my $line;
while ($line = $in->getline()) {
chomp($line);
@@ -885,7 +888,7 @@ an error message.
sub create_from_json
{
my ($class, $json, $specials_accepted) = @_;
my $parser = JSON::MaybeXS->new(utf8 => 1);
my $parser = JSON::MaybeXS->new(utf8 => 0);
my $array;
eval {
@@ -904,12 +907,6 @@ sub create_from_json
if (!$e) {
return (undef, $error);
}
# Re-encode our day names as utf-8
my $new_day_names = [];
foreach my $d (@{$e->{daynames}}) {
push(@$new_day_names, Encode::encode('UTF-8', $d));
}
$e->{daynames} = $new_day_names;
push(@{$self->{entries}}, $e);
}
return ($self, undef);

View File

@@ -76,7 +76,7 @@ sub render
$layout->set_width(1024 * ($x2 - $x1 - 2 * $settings->{border_size}));
$layout->set_wrap('word-char');
$layout->set_text($self->{body});
$layout->set_text(Encode::decode('UTF-8', $self->{body}));
my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $settings->{entry_size} . 'px');
$layout->set_font_description($desc);
my ($wid, $h) = $layout->get_pixel_size();
@@ -114,7 +114,7 @@ sub render
my ($x1, $y1, $x2, $y2) = $pdf->col_box_coordinates($so_far, $col, $height, $settings);
my $layout = Pango::Cairo::create_layout($cr);
$layout->set_text($self->{body});
$layout->set_text(Encode::decode('UTF-8', $self->{body}));
my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . int(0.75 * $settings->{entry_size}) . 'px');
$layout->set_font_description($desc);
my ($wid, $h) = $layout->get_pixel_size();
@@ -167,7 +167,7 @@ sub render
if ($self->{body} ne '') {
$layout = Pango::Cairo::create_layout($cr);
$layout->set_text($self->{body});
$layout->set_text(Encode::decode('UTF-8', $self->{body}));
my $desc = Pango::FontDescription->from_string($settings->{entry_font} . ' ' . $self->{fontsize} . 'px');
$layout->set_font_description($desc);
($bodywidth, undef) = $layout->get_pixel_size();
@@ -269,7 +269,7 @@ sub render
$layout->set_width(1024 * ($x2 - $x1 - 2 * $settings->{border_size}));
$layout->set_wrap('word-char');
$layout->set_markup($self->{body});
$layout->set_markup(Encode::decode('UTF-8', $self->{body}));
if (($layout->get_text() // '') eq '') {
# Invalid markup

View File

@@ -783,7 +783,7 @@ static void DoCalendarOneMonth(void)
} else yy=y;
if (PsCal < PSCAL_LEVEL3) {
printf("%s %d\n", get_month_name(mm), DaysInMonth(mm,yy));
printf("%s %d\n", despace(get_month_name(mm)), DaysInMonth(mm,yy));
} else {
PrintJSONKeyPairString("prevmonthname", get_month_name(mm));
PrintJSONKeyPairInt("daysinprevmonth", DaysInMonth(mm, yy));
@@ -794,7 +794,7 @@ static void DoCalendarOneMonth(void)
mm = 0; yy = y+1;
} else yy=y;
if (PsCal < PSCAL_LEVEL3) {
printf("%s %d\n", get_month_name(mm), DaysInMonth(mm,yy));
printf("%s %d\n", despace(get_month_name(mm)), DaysInMonth(mm,yy));
} else {
PrintJSONKeyPairString("nextmonthname", get_month_name(mm));
PrintJSONKeyPairInt("daysinnextmonth", DaysInMonth(mm, yy));

View File

@@ -424,6 +424,19 @@ void DoPsCal(void)
sscanf(DBufValue(&buf), "%s %d", prevm, &prevdays);
DBufGets(&buf, stdin);
sscanf(DBufValue(&buf), "%s %d", nextm, &nextdays);
/* Replace underscores with spaces in names of next/prev month */
s = prevm;
while(*s) {
if (*s == '_') *s = ' ';
s++;
}
s = nextm;
while(*s) {
if (*s == '_') *s = ' ';
s++;
}
DBufFree(&buf);
MaxDay = days;
FirstWkDay = wkday;

View File

@@ -9,7 +9,20 @@ SET $Tuesday "mardi"
SET $Wednesday "水曜日"
SET $Thursday "четвер"
SET $Friday "piątek"
Set $Saturday "שבת"
SET $Saturday "יום שבת"
SET $January "January"
SET $February "février"
SET $March "März"
SET $April "אַפּרִיל"
SET $May "ግንቦት"
SET $June "Чэрвень"
SET $July "تموز"
SET $August "Наймдугаар сар"
SET $September "Вересень"
SET $October "październik"
SET $November "נאוועמבער"
SET $December "दिसंबर"
REM 1 MSG Përkujtues
REM 2 SPECIAL SHADE 192 192 255
@@ -18,7 +31,7 @@ REM 3 MSG 提醒
REM 4 MSG રીમાઇન્ડર
REM 5 MSG Emlékeztető
REM 6 MSG Áminning
REM 7 MSG תִזכּוֹרֶת
REM 7 SPECIAL PANGO <u>תִזכּוֹרֶת</u>
REM 8 MSG अनुस्मारक
REM 9 SPECIAL COLOR 0 0 192 Эскертүү
REM 10 SPECIAL COLOR 0 192 0 Напоминание