This file is indexed.

/usr/bin/unifont-viewer is in unifont-bin 1:10.0.07-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#!/usr/bin/perl

use strict;
use warnings;
use Wx;

package Unifont;

use GD qw (:DEFAULT :cmp);

sub LoadHexFile {
	my ($input) = @_;
	my %hexlist = ();

	open (HEXFILE, "$input") or die ("Cannot open hex file for input\n");

	while (<HEXFILE>) {
		chomp;
		my @data = split (':', $_);

		my $codepoint = hex ($data[0]);
		my $char = $data[1];
#		my $display_width = $codepoint > 0xFFFF ? 6 : 4;
		# Use 6-digit codepoint for all glyphs for now
		my $display_width = 6;

		$hexlist{sprintf ("%0*X", $display_width, $codepoint)} = $char;
	}

	return %hexlist;
}

sub Hex2PNG {
	my ($hexlist_ref, $pagenum, $charheight) = @_;
	my %hexlist = %$hexlist_ref;

	if ($pagenum > 0x10FF) {
		die ("Invalid page.\n");
	}

	my $charxoffset = 4;
	my $gridxoffset = 48;
	my $gridyoffset = 32;
	my ($charyoffset, $boxsize, $xmax, $ymax, $charmaxwidth);

	if (not $charheight) {
		$charheight = 16;
	}

	if ($charheight == 16) {
		$charyoffset = 7;
		$boxsize = 32;
		$xmax = 2;
		$ymax = 1;
		$charmaxwidth = 6;
	} elsif ($charheight == 24) {
		$charyoffset = 4;
		$boxsize = 32;
		$xmax = 2;
		$ymax = 2;
		$charmaxwidth = 6;
	} elsif ($charheight == 32) {
		$charyoffset = 4;
		$boxsize = 40;
		$xmax = 3;
		$ymax = 3;
		$charmaxwidth = 8;
	} else {
		die ("Invalid height.\n");
	}

	# Create box and set as tile pattern

	my $box = new GD::Image ($boxsize, $boxsize);

	my $black = $box->colorAllocate (0, 0, 0);
	my $white = $box->colorAllocate (255, 255, 255);

	$box->filledRectangle (1, 1, $boxsize - 1, $boxsize - 1, $white);

	# Draw dots at 8 pixel boundaries
	 for (my $count = 0; $count <= $xmax; $count++) {
		$box->setPixel (($count * 8) + $charxoffset + 1, 0, $white);
		$box->setPixel (($count * 8) + $charxoffset + 8, 0, $white);
	}

	for (my $count = 0; $count <= $ymax; $count++) {
		$box->setPixel (0, ($count * 8) + $charyoffset + 1, $white);
		$box->setPixel (0, ($count * 8) + $charyoffset + 8, $white);
	}

	# Draw grid

	my $im = new GD::Image ($boxsize * 16 + $gridxoffset, $boxsize * 16 + $gridyoffset);

	$black = $im->colorAllocate (0, 0, 0);
	$white = $im->colorAllocate (255, 255, 255);

	$im->fill (0, 0, $white);

	for (my $xcount = 0; $xcount <= 16; $xcount++) {
		for (my $ycount = 0; $ycount <= 16; $ycount++) {
			$im->copy ($box, $xcount * $boxsize + $gridxoffset - 1, $ycount * $boxsize + $gridyoffset - 1, 0, 0, $boxsize, $boxsize);
		}
	}

	# Print plane
	$im->string (gdLargeFont, 8, 9, sprintf ('U+%02X', $pagenum >> 8), $black);

	# Print row headers
	for (my $count = 0; $count <= 15; $count++) {
		$im->string (gdLargeFont, 32, ($count * $boxsize) + (($boxsize - 16) / 2) + $gridyoffset, sprintf ('%X', $count), $black);
	}

	# Print column headers
	for (my $count = 0; $count <= 15; $count++) {
		$im->string (gdLargeFont, ($count * $boxsize) + (($boxsize - 24) / 2) + $gridxoffset, 9, sprintf ('%03X', (($pagenum & 0xFF) << 4) + $count), $black);
	}

	while ((my $codepoint, my $char) = each %hexlist) {
		if ($codepoint and $codepoint =~ m/^[0-9A-F]{4,6}$/) {
			my $cp = hex ($codepoint);

			# Calculate if codepoint is within page
			if ($cp >> 8 == $pagenum) {
				# Calculate character width, column and row
				my $charwidth = length ($char) / $charheight;

				if ($charwidth <= $charmaxwidth) {
					my $col = ($cp >> 4) & 0xF;
					my $row = $cp & 0xF;

					for (my $j = 0; $j < $charheight; $j++) {
						# Get character row
						my $r = hex (substr ($char, $j * $charwidth, $charwidth));

						# Draw character
						for (my $i = 0; $i < $charwidth * 4; $i++) {
							if ($r & 1 << $i) {
								$im->setPixel (($col * $boxsize) + ($charwidth * 4 - $i) + $charxoffset + $gridxoffset - 1, ($row * $boxsize) + $j + $charyoffset + $gridyoffset, $black);
							}
						}
					}
				}
			}
		}
	}

	return $im;
}

package UnifontViewer;

use base qw (Wx::App);
use Wx qw (wxMINIMIZE_BOX wxSYSTEM_MENU wxCAPTION wxCLOSE_BOX wxCLIP_CHILDREN);

sub OnInit {
	my $self  = shift;
	my $frame = UnifontViewerFrame->new (
		undef,
		-1,
		'Unifont Viewer',
		[-1, -1],
		[-1, -1],
		wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN
	);

	$frame->Show (1);
	$self->SetTopWindow ($frame);

	return 1;
}

package ImagePanel;

use base qw (Wx::Panel);
use fields qw (memdc);
use Wx qw (wxCOPY);
use Wx::Event qw (EVT_PAINT);

sub new {
	my $class = shift;
	my $self  = $class->SUPER::new (@_);

	$self->{memdc} = Wx::MemoryDC->new ();

	EVT_PAINT($self, \&OnPaint);

	return $self;
}

sub clear {
	my $self = shift;

	$self->{memdc}->Clear ();
	$self->Refresh ();
}

sub load {
	my ($self, $filename) = @_;

	my $file = IO::File->new ($filename, 'r');
	binmode $file;
	my $handler = Wx::PNGHandler->new ();
	my $image = Wx::Image->new ();
	my $bitmap;
	$handler->LoadFile ($image, $file);
	$bitmap = Wx::Bitmap->new ($image);

	if ($bitmap->Ok ()) {
		$self->{memdc}->SelectObject ($bitmap);
		$self->Refresh ();
	}
}

sub load_gd {
	my ($self, $gd) = @_;
	my $png = $gd->png;

	open my $fh, '<', \$png or die ("Cannot create PNG file for viewing.\n");
	my $handler = Wx::PNGHandler->new ();
	my $image = Wx::Image->new ();
	my $bitmap;
	$handler->LoadFile ($image, $fh);
	close $fh or die ("Cannot properly close output file.\n");
	$bitmap = Wx::Bitmap->new ($image);

	if ($bitmap->Ok ()) {
		$self->{memdc}->SelectObject ($bitmap);
		$self->Refresh ();
	}
}

sub OnPaint {
	my ($self, $event) = @_;
	my $size = $self->GetClientSize ();

	my $dcPaint = Wx::PaintDC->new ($self);
	$dcPaint->Blit (0, 0, $size->x, $size->y, $self->{memdc}, 0, 0, wxCOPY, 0);
}

package UnifontViewerFrame;

use base qw (Wx::Frame);
use fields qw (filename hexlist charheight listbox imagepanel);
use Wx::Event qw (EVT_MENU EVT_LISTBOX);
use Wx qw (wxBORDER_SIMPLE wxID_OPEN wxID_SAVE wxID_EXIT wxID_OK wxHORIZONTAL wxEXPAND wxALL wxLB_SORT wxFD_OPEN wxFD_SAVE wxFD_FILE_MUST_EXIST wxFD_CHANGE_DIR);

our @id = (0 .. 100);

sub new {
	my $class = shift;
	my $self  = $class->SUPER::new (@_);
	$self->{filename} = '';
	$self->{charheight} = 16;

	my $boxsizer = Wx::BoxSizer->new (wxHORIZONTAL);

	$self->{listbox} = Wx::ListBox->new (
		$self,
		-1,
		[-1, -1],
		[64, -1],
		[],
		wxLB_SORT
	);

	$self->{imagepanel} = ImagePanel->new (
		$self,
		-1,
		[-1, -1],
		[-1, -1],
		wxBORDER_SIMPLE
	);

	SetCharHeight ($self, $self->{charheight});

	$boxsizer->Add (
		$self->{listbox},
		0,
		wxEXPAND | wxALL,
		0
	);

	$boxsizer->Add (
		$self->{imagepanel},
		0,
		wxALL,
		1
	);

	EVT_LISTBOX ($self->{listbox}, -1, sub {
		my $selection = $self->{listbox}->GetStringSelection ();
		SetPage ($self, $selection);
	});

	my $menubar = Wx::MenuBar->new ();
	my $menu = Wx::Menu->new ();

	$menu->Append (wxID_OPEN, "O&pen...\tCtrl+O");
	$menu->Append (wxID_SAVE, "S&ave As...\tCtrl+S");
	$menu->AppendSeparator ();
	$menu->AppendRadioItem ($id[0], "Glyph Height 16");
	$menu->AppendRadioItem ($id[1], "Glyph Height 24");
	$menu->AppendRadioItem ($id[2], "Glyph Height 32");
	$menu->AppendSeparator ();
	$menu->Append (wxID_EXIT, "E&xit\tCtrl+X");
	$menubar->Append ($menu, 'File');

	$self->SetMenuBar ($menubar);

	EVT_MENU ($self, wxID_OPEN, \&OpenFile);
	EVT_MENU ($self, wxID_SAVE, \&SaveFile);
	EVT_MENU ($self, $id[0], sub {SetCharHeight ($self, 16)});
	EVT_MENU ($self, $id[1], sub {SetCharHeight ($self, 24)});
	EVT_MENU ($self, $id[2], sub {SetCharHeight ($self, 32)});
	EVT_MENU ($self, wxID_EXIT, sub {$_[0]->Close (1)});

	$self->SetSizerAndFit ($boxsizer);

	return $self;
}

sub OpenFile {
	my ($self, $event) = @_;

	my $dlg = Wx::FileDialog->new (
		$self,
		'Open File',
		'',
		'',
		'Hex files (*.hex)|*.hex',
		wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR
	);

	if ($dlg->ShowModal == wxID_OK) {
		$self->{imagepanel}->clear ();

		my %pages = ();

		$self->{filename} = $dlg->GetPath ();
		$self->SetTitle ("Unifont Viewer - " . $dlg->GetFilename ());

		open HEXFILE, "<$self->{filename}" || die "Cannot open $self->{filename}.\n";

		while (<HEXFILE>) {
			chomp;
			my ($codepoint, $char) = (split (':', $_));
			# For now, list page numbers as 4 digits even for Plane 0 for sorting
			if (length ($codepoint) == 4) {
				$codepoint = "00" . $codepoint;
			}

			if ($codepoint and $codepoint =~ m/^[0-9A-F]{4,6}$/) {
				if (!($char eq '00542A542A542A542A542A542A542A00' || $char eq 'FFB9C5EDD5D5D5D5D5D5D5D5EDB991FF')) {
					my $page = substr ($codepoint, 0, -2);
					$pages{$page} = 1;
				}
			}
		}

		$self->{listbox}->Clear ();
		for (keys %pages) {
			$self->{listbox}->Append ($_, hex ($_));
		}

		my %hexlist = Unifont::LoadHexFile ($self->{filename});
		$self->{hexlist} = \%hexlist;

		$self->{listbox}->Select (0);
		my $selection = $self->{listbox}->GetStringSelection ();
		SetPage ($self, $selection);
	};
}

sub SaveFile {
	my ($self, $event) = @_;

	my $selection = $self->{listbox}->GetStringSelection ();

	if ($selection) {
		my $dlg = Wx::FileDialog->new (
			$self,
			'Save File',
			'',
			"$selection.png",
			'PNG files (*.png)|*.png',
			wxFD_SAVE
		);

		if ($dlg->ShowModal == wxID_OK) {
			my $im = Unifont::Hex2PNG ($self->{hexlist}, hex ($selection), $self->{charheight});

			my $filename = $dlg->GetPath ();

			$self->{imagepanel}->load_gd ($im);

			open (PICTURE, ">$filename") or die ("Cannot save image.\n");
			binmode PICTURE;
			print PICTURE $im->png or die;
			close PICTURE or die ("Cannot properly close output file.\n");
		}
	}
}

sub SetPage {
	my ($self, $selection) = @_;

	if ($selection) {
		my $im = Unifont::Hex2PNG ($self->{hexlist}, hex ($selection), $self->{charheight});
		$self->{imagepanel}->load_gd ($im);
	} else {
		$self->{imagepanel}->clear ();
	}
}

sub SetCharHeight {
	my ($self, $charheight) = @_;
	my ($x, $y);
	my $selection = $self->{listbox}->GetStringSelection ();

	$self->{charheight} = $charheight;

	if ($charheight == 16 || $charheight == 24) {
		$x = 562;
		$y = 544;
	} elsif ($charheight == 32) {
		$x = 688;
		$y = 672;
	}

	$self->{imagepanel}->SetMinSize ([-1, -1]);
	$self->{imagepanel}->SetClientSize ($x, $y);
	$self->{imagepanel}->SetMinSize ($self->{imagepanel}->GetSize ());
	$self->Fit ();

	SetPage ($self, $selection);
}

package main;

my ($app) = UnifontViewer->new ();

$app->MainLoop ();