Print a Unicode Glyph

Hi,

How do I print a ‘󰵝’ character to the terminal?

I am trying to convert the U+XXX code to the Unicode byte representation and put it using Text_IO.

Using Wide_Wide_Character’Val (16#EEAB9A#) doesn’t display the character properly:

with Ada.Wide_Wide_Text_IO;
with Ada.Wide_Wide_Characters;
declare
   Symbol : Wide_Wide_Character := Wide_Wide_Character'Val (16#EEAB9A#);
begin
   Ada.Wide_Wide_Text_IO.Put (Symbol);
end

If I use the character literal in the source file I get the error:

error: (Ada 2005) non-graphic character not permitted in character literal

Any ideas?

N

Your code certainly works with 16#1E2# (Ǣ), and the unicode converters I’ve checked with on the net don’t give a result for your number. As a colour value, it’s Sea Pink

   Block : constant String :=  -- UTF-8 U+25A1
                    (  Character'Val (16#E2#),
                       Character'Val (16#96#),
                       Character'Val (16#A1#)
                    );
begin
   Ada.Text_IO.Put_Line (Block);

What character is that? The usual Unicode pages doesn’t give any result.

Illegal. The code points are in the range 0…16#10FFFF#.

I am trying to print the ‘nf-md-camera_outline’ character (as part of the nerd-fonts font).

I think this is U+f0d5d

I’m filling the UTF-8 template: 1110xxx 10xxxxxx 10 xxxxxx 10xxxxxx , x with the value F0D5D to create the value.

If you’re on Windows, be sure you set your console to use unicode. I think it defaults (Win7/Vista) to codepage 646.

Eureka! I was converting the values on the nerdfonts website using the UTF conversion template erroneously, this is not necessary. Just add the value into the symbol and print.

For example, to print the nf-cod-chip symbol:

with Ada.Wide_Wide_Characters; use Ada.Wide_Wide_Characters;
with Ada.Wide_Wide_Text_IO;
declare
  Symbol : Wide_Wide_Character : Wide_Wide_Character'Val (16#ec19#);
begin
   Ada.Wide_Wide_Text_IO.Put (Symbol);
end;

OK, I have no idea why are you keep on trying to output illegal code points. None of the numbers you specified are legal Unicode code points.

Anyway, using Wide_Wide_Text_IO is highly non-portable. Windows console simply does not support UTF-32. It says that it does, the code page 12000, but it does not on my machine. Nether does Windows support UTF-16, which would be Wide_Text_IO. Which is a bit strange because internally Windows is UTF-16.

Wide_Wide_Text_IO is wasting resources too.

The most compatible encoding is UTF-8 which works both under Linux and Windows (chcp 65001).

For UTF-8 encoding see.

Here is an example:

with Ada.Text_IO;
with Strings_Edit.UTF8; use Strings_Edit.UTF8;

procedure Test is
begin
   Ada.Text_IO.Put_Line ("hello I am a block " & Image (16#25A1#));
end Test;

Function Image converts a code point into UTF-8 encoded string.

I don’t think nerd_type is trying to print the code points themselves, just the numeric position of the code points (So 0030 instead of '0' (which is U+0030)). For that, it doesn’t make much difference if they are illegal or or not, in a practical sense.