PreviousUpNext

15.4.1626  src/lib/x-kit/xclient/src/window/font-index.pkg

## font-index.pkg
#

# Compiled by:
#     src/lib/x-kit/xclient/xclient-internals.sublib





stipulate
    include package   threadkit;                                # threadkit                                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    #
    package vec =  rw_vector;                                   # rw_vector                                     is from   src/lib/std/src/rw-vector.pkg
    package un  =  unt;                                         # unt                                           is from   src/lib/std/unt.pkg
    package v1u =  vector_of_one_byte_unts;                     # vector_of_one_byte_unts                       is from   src/lib/std/src/vector-of-one-byte-unts.pkg
    package v2w =  value_to_wire;                               # value_to_wire                                 is from   src/lib/x-kit/xclient/src/wire/value-to-wire.pkg
    package w2v =  wire_to_value;                               # wire_to_value                                 is from   src/lib/x-kit/xclient/src/wire/wire-to-value.pkg
    package g2d =  geometry2d;                                  # geometry2d                                    is from   src/lib/std/2d/geometry2d.pkg
    package xtr =  xlogger;                                     # xlogger                                       is from   src/lib/x-kit/xclient/src/stuff/xlogger.pkg

    package hs  =  hash_string;                                 # hash_string                                   is from   src/lib/src/hash-string.pkg
#   package op  =  xsequencer_to_outbuf;                        # xsequencer_to_outbuf                          is from   src/lib/x-kit/xclient/src/wire/xsequencer-to-outbuf.pkg
    package xps =  xpacket_sink;                                # xpacket_sink                                  is from   src/lib/x-kit/xclient/src/wire/xpacket-sink.pkg
    package xt  =  xtypes;                                      # xtypes                                        is from   src/lib/x-kit/xclient/src/wire/xtypes.pkg
#   package xet =  xevent_types;                                # xevent_types                                  is from   src/lib/x-kit/xclient/src/wire/xevent-types.pkg
#   package x2s =  xclient_to_sequencer;                        # xclient_to_sequencer                          is from   src/lib/x-kit/xclient/src/wire/xclient-to-sequencer.pkg

    package fb  =  font_base;                                   # font_base                                     is from   src/lib/x-kit/xclient/src/window/font-base.pkg
    package dy  =  display;                                     # display                                       is from   src/lib/x-kit/xclient/src/wire/display.pkg

    nb = log::note_on_stderr;                                   # log                                           is from   src/lib/std/src/log.pkg
    #
    trace =  xtr::log_if  xtr::io_logging  0;                   # Conditionally write strings to tracing.log or whatever.
herein


    package   font_index
    : (weak)  Font_Index                                        # Font_Index                                    is from   src/lib/x-kit/xclient/src/window/font-index.api
    {
                                                                # typelocked_hashtable_g                        is from   src/lib/src/typelocked-hashtable-g.pkg

        # hashtables on font names:
        #
        package sht
            =
            typelocked_hashtable_g (

                Hash_Key = String;

                fun hash_value s
                    =
                    hs::hash_string s;

                fun same_key (s1:  String, s2:  String)
                    =
                    s1 == s2;
            );






        Font_Index =  sht::Hashtable( fb::Font );                                                                               # Holds all nonephemeral state.



        fun note_font font_index (fontname, font)                                                                               # PUBLIC.
            =
            sht::set font_index (fontname, font);


        fun find_font font_index fontname
            =
            sht::find  font_index fontname;


        fun make_font
              ( font_id:                xt::Font_Id,
                xdpy:                   dy::Xdisplay,
                font_query_reply:       w2v::Font_Query_Reply
              )
            =
            {
                info =  if (min_byte1 == 0                                                                                      # For background here see p38 in   http://mythryl.org/pub/exene/X-protocol-R7.pdf
                        and max_byte1 == 0)
                            #
                            fb::FINFO8    { min_bounds,
                                            max_bounds,
                                            min_char,
                                            max_char,
                                            default_char,
                                            draw_dir,
                                            all_chars_exist,
                                            font_ascent,
                                            font_descent,
                                            properties,
                                            char_info
                                          };
                      else
                            fb::FINFO16   { min_bounds,
                                            max_bounds,
                                            min_char,
                                            max_char,
                                            min_byte1,
                                            max_byte1,
                                            default_char,
                                            draw_dir,
                                            all_chars_exist,
                                            font_ascent,
                                            font_descent,
                                            properties,
                                            char_info
                                          };
                      fi;

                { id   => font_id,
                  xdpy,
                  info
                }
                : fb::Font;
            }
            where
                font_query_reply ->   { all_chars_exist:    Bool,
                                        char_infos:         List( xt::Char_Info ),
                                        default_char:       Int,
                                        draw_dir:           xt::Font_Drawing_Direction,
                                        #
                                        font_ascent:        Int,
                                        font_descent:       Int,
                                        #
                                        max_bounds:         xt::Char_Info,
                                        min_bounds:         xt::Char_Info,
                                        #
                                        max_byte1:          Int,
                                        min_byte1:          Int,
                                        #
                                        min_char:           Int,
                                        max_char:           Int,
                                        #
                                        properties:         List( xt::Font_Prop )
                                      };

                fun in_range c
                    =
                    c >= min_char   and
                    c <= max_char;

                char_info
                    =
                    case char_infos
                        #
                        [] => if (in_range default_char)
                                  #
                                  \\ _ =  min_bounds;
                              else
                                  \\ c =  in_range c  ??  min_bounds
                                                      ::  (raise exception fb::NO_CHAR_INFO);
                              fi;
                        #
                        l => {
                                table = vec::from_list l;

                                fun info_exists (xt::CHAR_INFO { char_width=>0, left_bearing=>0, right_bearing=>0, ... } )
                                        =>
                                        FALSE;

                                    info_exists _
                                        =>
                                        TRUE;
                                end;

                                fun lookup c
                                    =
                                    if (in_range c)
                                        #
                                        case (vec::get (table, c - min_char))
                                            #   
                                            xt::CHAR_INFO { char_width=>0, left_bearing=>0, right_bearing=>0, ... }
                                                =>
                                                NULL;

                                            per_compile_stuff
                                                =>
                                                THE per_compile_stuff;
                                        esac;
                                    else
                                        NULL;
                                    fi;

                                fun get_info default c
                                    =
                                    if (in_range c)
                                        #
                                        case (lookup c)
                                            #
                                            THE c =>  c;
                                            NULL  =>  default ();
                                        esac;
                                    else
                                        default ();
                                    fi;

                                  case (lookup default_char)
                                      #
                                      NULL  => get_info (\\ () =  raise exception fb::NO_CHAR_INFO);
                                      THE c => get_info (\\ () =  c);
                                  esac;
                          };
                    esac;


            end;                                                                                                        # make_font



        ##########################################################################################
        # PUBLIC.
        #
        fun make_font_index ()                                                                                          # PUBLIC.
            =
            sht::make_hashtable  { size_hint => 32,  not_found_exception => DIE "FontMap" }
                :  sht::Hashtable( fb::Font );
    };                                                                                                                  # package font_index
end;




Comments and suggestions to: bugs@mythryl.org

PreviousUpNext