layout/reftests/fonts/generate-bitpattern-font.pl
author Alexis Beingessner <a.beingessner@gmail.com>
Thu, 10 Oct 2019 23:10:28 +0000
changeset 552383 b6d82b1a6b027461055a92f052d6d0511086a5bb
parent 114718 6786b5f4ee4a79d22df9cc6931a36f1f99ca81be
permissions -rw-r--r--
Bug 1587155 - Block all hardware acceleration for AMD driver 22.19.162.4. r=jrmuizel a=lizzard Driver's Haunted. Differential Revision: https://phabricator.services.mozilla.com/D48900

#!/usr/bin/perl -w

# Generates an SVG Font where each glyph (identified on stdin by four
# hex characters) consists of a bit pattern representing the Unicode
# code point it is the glyph for.

use strict;

print <<EOF;
<svg xmlns="http://www.w3.org/2000/svg">
<font id="BitPattern" horiz-adv-x="1000">
  <font-face font-family="BitPattern" units-per-em="1000" ascent="800"/>
EOF

while (<>) {
  chomp;
  next if /^\s*$/;
  die unless /^[0-9A-Fa-f]{4}$/;
  my $c = hex;
  my $s = "  <glyph unicode='&#x$_;' d='";
  for (my $i = 0; $i < 32; $i++) {
    if ($c & (1 << $i)) {
      my $x = 100 * (7 - ($i % 8));
      my $y = 100 * int($i / 8);
      $s .= "M$x,$y v80h80v-80z ";
    }
  }
  $s .= "'/>\n";
  print $s;
}

print <<EOF;
</font>
</svg>
EOF