about summary refs log tree commit diff stats
path: root/t/01-hex2rgb.rakutest
blob: ca8bd59783889dd77945fefe0e8718451a0e8bd7 (plain) (blame)
1
2
3
4
5
6
7
8
use Test;
use Fornax::Hex2RGB;

plan 3;

is hex2rgb("#000000"), (0, 0, 0), "#000000";
is hex2rgb("#b753db"), (183, 83, 219).map(* / 255), "#b753db";
is hex2rgb("#ffffff"), (1, 1, 1), "#ffffff";
.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Demo of combining-character support in Mu, which can be summarized as, "the
# old typewriter-based approach of backing up one character and adding the
# accent or _matra_ in."
#   https://en.wikipedia.org/wiki/Combining_character
#
# Mu uses this approach for both accents in Latin languages and vowel
# diacritics in Abugida scripts.
#   https://en.wikipedia.org/wiki/Diacritic
#   https://en.wikipedia.org/wiki/Abugida
#
# Steps for trying it out:
#   1. Translate this example into a disk image code.img.
#       ./translate apps/ex15.mu
#   2. Run:
#       qemu-system-i386 -hda code.img -hdb data.img
#
# Expected output, showing off what this approach can and cannot do:
#   'à' in green in a few places near the top-left corner of screen, with
#   other letters nearby showing cases where characters blend to the eye.
#
#   A few Devanagari letter combinations. Devanagari works well except for
#   characters blending together.
#
#   A few Tamil letter combinations. Tamil often doesn't look right, and
#   requires ligatures for many letter combinations.
#
#   Others? (Patches welcome.) I suspect Tibetan in particular will not work
#   well with this approach. But I need native readers to assess quality.

fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
  # at the top of screen, the accent is almost cropped
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       0/x 0/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  0/x 0/y, 3/fg 0/bg

  # below a code-point-utf8 with a descender, the accent uglily overlaps
  #   https://en.wikipedia.org/wiki/Descender
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x67/g,                       4/x 3/y, 3/fg 0/bg
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       4/x 4/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  4/x 4/y, 3/fg 0/bg

  # beside a code-point-utf8 with a descender, it becomes more obvious that monowidth fonts can't make baselines line up
  #   https://en.wikipedia.org/wiki/Baseline_(typography)
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x67/g,                       8/x 3/y, 3/fg 0/bg
  var dummy/eax: int <-    draw-code-point-on-real-screen   0x61/a,                       9/x 3/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0300/combining-grave-accent,  9/x 3/y, 3/fg 0/bg

  # a single devanagari letter combined with different vowel _matras_
  # ka
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 4/x 8/y, 3/fg 0/bg
  # kaa
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 7/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x093e/devanagari-vowel-aa, 7/x 8/y, 3/fg 0/bg
  # ki
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xa/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x093f/devanagari-vowel-i, 0xa/x 8/y, 3/fg 0/bg
  # kee
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xd/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0940/devanagari-vowel-ii, 0xd/x 8/y, 3/fg 0/bg
  # ku
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x10/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0941/devanagari-vowel-u, 0x10/x 8/y, 3/fg 0/bg
  # koo
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x13/x 8/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0942/devanagari-vowel-oo, 0x13/x 8/y, 3/fg 0/bg
  # kay
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 4/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0947/devanagari-vowel-E, 4/x 9/y, 3/fg 0/bg
  # kai
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 7/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0948/devanagari-vowel-ai, 7/x 9/y, 3/fg 0/bg
  # ko
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xa/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x094b/devanagari-vowel-o, 0xa/x 9/y, 3/fg 0/bg
  # kow
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0xd/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x094f/devanagari-vowel-aw, 0xd/x 9/y, 3/fg 0/bg
  # kan
  # bump this letter down to show the letter without overlap; we've already established above that overlap is an issue
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x10/x 0xa/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0902/devanagari-anusvara, 0x10/x 0xa/y, 3/fg 0/bg
  # kaha
  var dummy/eax: int <- draw-code-point-on-real-screen 0x0915/devanagari-letter-ka, 0x13/x 9/y, 3/fg 0/bg
  var dummy/eax: int <- overlay-code-point-on-real-screen 0x0903/devanagari-visarga, 0x13/x 9/y, 3/fg 0/bg

  # render the same devanagari letters as a single stream of utf-8 code-point-utf8s rather than individual code-points.
  var text-storage: (stream byte 0x200)
  var text/esi: (addr stream byte) <- address text-storage
  var g/eax: code-point-utf8 <- to-utf8 0x0915/devanagari-letter-ka
  var ka/ecx: code-point-utf8 <- copy g
  # ka
  write-code-point-utf8 text, ka
  # kaa
  write-code-point-utf8 text, ka
  g <- to-utf8 0x093e/devanagari-vowel-aa
  write-code-point-utf8 text, g
  # ki
  write-code-point-utf8 text, ka
  g <- to-utf8 0x093f/devanagari-vowel-i
  write-code-point-utf8 text, g
  # kee
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0940/devanagari-vowel-ii
  write-code-point-utf8 text, g
  # ku
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0941/devanagari-vowel-u
  write-code-point-utf8 text, g
  # koo
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0942/devanagari-vowel-oo
  write-code-point-utf8 text, g
  # kay
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0947/devanagari-vowel-E
  write-code-point-utf8 text, g
  # kai
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0948/devanagari-vowel-ai
  write-code-point-utf8 text, g
  # ko
  write-code-point-utf8 text, ka
  g <- to-utf8 0x094b/devanagari-vowel-o
  write-code-point-utf8 text, g
  # kow
  write-code-point-utf8 text, ka
  g <- to-utf8 0x094f/devanagari-vowel-aw
  write-code-point-utf8 text, g
  # kan
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0902/devanagari-anusvara
  write-code-point-utf8 text, g
  # kaha
  write-code-point-utf8 text, ka
  g <- to-utf8 0x0903/devanagari-visarga
  write-code-point-utf8 text, g
  # render everything
  set-cursor-position screen, 4/x 0xe/y
  draw-stream-wrapping-right-then-down-from-cursor-over-full-screen screen, text, 3/fg 0/bg

  # a stream of tamil code-point-utf8s (with interspersed spaces for clarity) that don't look the same in Mu
  set-cursor-position 0, 4/x 0x12/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "எ ஃ கு ", 3/fg 0/bg
  set-cursor-position 0, 4/x 0x13/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ ன் று ", 3/fg 0/bg
  set-cursor-position 0, 4/x 0x14/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ தா வ து " , 3/fg 0/bg
  set-cursor-position 0, 4/x 0x15/y
  draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0, "அ ஃ தா ன் று ", 3/fg 0/bg
}