Skip to content

Font Modifications

Alejandro Olvera edited this page Nov 8, 2017 · 17 revisions

Sources

Reviewing the source code, I have found that the two vital files needed for modification are located in the directory ~/projects/lms2012/c_ui/source. These files are the following:

  • d_lcd.c
  • c_ui.c

They manage display functions and fonts. The bitmaps associated with the fonts are technically stored in the same directory, however after closer examination their sources are found in the directory: ~/projects/lms2012/lmssrc/c_ui This was evident after examining the Makefile located in this directory. Simply put, any new bitmaps for fonts will be stored in this directory and the Makefile will be invoked. Additions to the make file will be required to include the new font sources. They will be covered in the next section.

TIP All modifications to c_ui will be set via the main make file by invoking make lms2012 according to the main make file.

TIP Since bitmaps will be included to lmssrc/c_ui directory invoke the Makefile in the directory or use make programs.

Modifying the Makefile

Since the Makefile is relatively small, I shall include it and display changes.

APP = c_ui
INSTALL_TO = source

# The following lines indicate the raw files to be included.
GRAPHICS_XBM = small_icons menu_icons normal_icons large_icons arrow_icons \
               small_font normal_font large_font tiny_font keyboardc keyboardn \
               keyboards mindstorms Ani1x Ani2x Ani3x Ani4x Ani5x Ani6x POP2 \
               POP3 PCApp

# The following lines dictate the name that will be known 
# to the C files during their compilation.
small_icons_SOURCE = 16x8_TopBar_Icons
menu_icons_SOURCE = 16x12_MenuItems
normal_icons_SOURCE = 24x12_Files_Folders_Settings
large_icons_SOURCE = 24x22_Yes_No_OFF_FILEOps
arrow_icons_SOURCE = 8x12_miniArrows
small_font_SOURCE = brick_font_2011_v1.3-bold
normal_font_SOURCE = brick_font_2011_v1.3-regular
large_font_SOURCE = brick_font_LARGE
tiny_font_SOURCE = small_font
keyboardc_SOURCE = KEY_CAPCHAR
keyboardn_SOURCE = KEY_NumSymb
keyboards_SOURCE = KEY_SmCHAR
mindstorms_SOURCE = mindstorms
POP2_SOURCE = 144x48_POP2
POP3_SOURCE = 144x65_POP3
PCApp_SOURCE = 24x12_PCApp

include ../rules.mk

As observed with the added comments, the variable GRAPHICS_XBM shall store raw sources. Below these inclusions are multiple variables whose names will be actually known to the C files at compilation time.

Modifying d_lcd.c

In order to inject new fonts modification to d_lcd.c must be made.:

typedef   struct
{
  const   char    *pFontBits;           // Pointer to start of font bitmap
  const   DATA16  FontHeight;           // Character height (all inclusive)
  const   DATA16  FontWidth;            // Character width (all inclusive)
  const   DATA16  FontHorz;             // Number of horizontal character in font bitmap
  const   DATA8   FontFirst;            // First character supported
  const   DATA8   FontLast;             // Last character supported
}
FONTINFO;


#include  "normal_font.xbm"
#include  "small_font.xbm"
#include  "large_font.xbm"
#include  "tiny_font.xbm"


FONTINFO  FontInfo[] =
{
  [NORMAL_FONT] = {
                    .pFontBits    = (const char*)normal_font_bits,
                    .FontHeight   = 9,
                    .FontWidth    = 8,
                    .FontHorz     = 16,
                    .FontFirst    = 0x20,
                    .FontLast     = 0x7F
                  },
  [SMALL_FONT] =  {
                    .pFontBits    = (const char*)small_font_bits,
                    .FontHeight   = 8,
                    .FontWidth    = 8,
                    .FontHorz     = 16,
                    .FontFirst    = 0x20,
                    .FontLast     = 0x7F
                  },
  [LARGE_FONT] =  {
                    .pFontBits    = (const char*)large_font_bits,
                    .FontHeight   = 16,
                    .FontWidth    = 16,
                    .FontHorz     = 16,
                    .FontFirst    = 0x20,
                    .FontLast     = 0x7F
                  },
  [TINY_FONT] =   {
                    .pFontBits    = (const char*)tiny_font_bits,
                    .FontHeight   = 7,
                    .FontWidth    = 5,
                    .FontHorz     = 16,
                    .FontFirst    = 0x20,
                    .FontLast     = 0x7F
                  },

};

The above lines indicate a method of storing Font information, as well as already defined fonts from the manufacturer. By modifying this initial structure, it is possible to provide fonts that can be easily view-able by users with visual impairment.

Injection

Three font sizes with the heights, 14, 16, and 18 pixels will be injected into the display modules. Luckily the d_lcd.c file contains all necessary primitive functions for drawing to the LCD. After closer examination of the primitive function dLcdDrawChar, I have noticed that all font sizes should be handled by the function and may not require modifications.

In order to provide additional FontType definitions, additions were made to ~/projects/lms2012/lms2012/source/bytecodes.h. It is important that the enum value corresponds to the position of your added font. The current enumerations are listed below:

typedef   enum
{
  NORMAL_FONT                   = 0,
  SMALL_FONT                    = 1,
  LARGE_FONT                    = 2,
  TINY_FONT                     = 3,
  AL_FONT                       = 4,

  FONTTYPES                             //!< Maximum font types supported by the VM
                                        // The AL_FONT (access Large FONT) was added for easy selections.
}
FONTTYPE;

Currently, the only font injected is the 16px font size, which is classified as AL_FONT ( access_large_font ).

Modifying the Browser

Since a large majority of the UI involves browsing, it will be essential to modify the cUiBrowser function located in the c_ui.c file in the c_ui directory. Oddly enough, the portion for the browser seems to be commented out ( possible issue with my editor? ), however since it is the only function call with the name I have decided to modify the function to see if there are any results.

The following section in the cUiBrowser function contains the necessary portion to modify.

//* INIT *****************************************************************************************************

    // Define screen
    (*pB).ScreenStartX  =  X;
    (*pB).ScreenStartY  =  Y;
    (*pB).ScreenWidth   =  X1;
    (*pB).ScreenHeight  =  Y1;

    // calculate lines on screen
    (*pB).LineSpace     =  5;
    (*pB).IconHeight    =  dLcdGetIconHeight(NORMAL_ICON);
    (*pB).LineHeight    =  (*pB).IconHeight + (*pB).LineSpace;
    (*pB).Lines         =  ((*pB).ScreenHeight / (*pB).LineHeight);

    // Although this entire section is commented out, I feel as though this is the appropriate area to make additions.
    // calculate chars and lines on screen
    (*pB).CharWidth     =  dLcdGetFontWidth(NORMAL_FONT);
    (*pB).CharHeight    =  dLcdGetFontHeight(NORMAL_FONT);
    (*pB).IconWidth     =  dLcdGetIconWidth(NORMAL_ICON);
    (*pB).Chars         =  (((*pB).ScreenWidth - (*pB).IconWidth) / (*pB).CharWidth);

    // calculate start of icon
    (*pB).IconStartX    =  cUiAlignX((*pB).ScreenStartX);
    (*pB).IconStartY    =  (*pB).ScreenStartY + (*pB).LineSpace / 2;

    // calculate start of text
    (*pB).TextStartX    =  cUiAlignX((*pB).ScreenStartX + (*pB).IconWidth);
    (*pB).TextStartY    =  (*pB).ScreenStartY + ((*pB).LineHeight - (*pB).CharHeight) / 2;

Specifically the these lines are of interest:

    // Although this entire section is commented out, I feel as though this is the appropriate area to make additions.
    // calculate chars and lines on screen
    (*pB).CharWidth     =  dLcdGetFontWidth(NORMAL_FONT);
    (*pB).CharHeight    =  dLcdGetFontHeight(NORMAL_FONT);
    (*pB).IconWidth     =  dLcdGetIconWidth(NORMAL_ICON);
    (*pB).Chars         =  (((*pB).ScreenWidth - (*pB).IconWidth) / (*pB).CharWidth);

Since we have injected a new font defined as AL_FONT, swapping this for the NORMAL_FONT should render the desired results. After modifications, the actual font used to print the names was not modified however the 'selection' was modified and would fit the new font once added.

After digging through the C_UI.c file some more, I have found what I now believe to be the actual font handlers, the previous information handled selection sizing, which would of have to been modded as well. The corresponding default switch case correlates with the actual font drawing:

                  default :
                  {
                    // After careful examination, it would seem at this location NORMAL_FONT will be changed to AL_FONT    search: BROWSERFONT
                    Indent  =  (((*pB).Chars - 1) - (DATA16)strlen((char*)(*pB).Text)) * (*pB).CharWidth;
                    dLcdDrawText((*UiInstance.pLcd).Lcd,Color,(*pB).TextStartX + Indent,(*pB).TextStartY + (Tmp * (*pB).LineHeight),AL_FONT,(*pB).Text); // NORMAL_FONT -> AL_FONT
                  }
                  break;

The lines in interest start on line 4407 ( as of now ) and continue to 4504. This lines will likely need to be modified in the future if larger icons wish to be used. The locations near the end of this selection also handle some of the visual aesthetics to the browser capabilities and will be modified to the liking of Dr. Ludi.

Hello World and Testing New Fonts

Once modifications are made, the hello world program will be modified to include the UI_Draw function with the operand command 'select_font' :

vmthread MAIN
{
    UI_DRAW(FILLWINDOW,0x00,0,0)               // Clear screen 
    UI_DRAW(SELECT_FONT, # )                   // Where # will be the corresponding index value for new font
    UI_DRAW(TEXT,FG_COLOR,10,50,'hello world') // Write "hello world" at 10,50 (X,Y)
    UI_WRITE(LED,LED_ORANGE_PULSE)	       // Pulse status LEDs				 
    UI_DRAW(UPDATE)                            // Show the stuff
    UI_BUTTON(WAIT_FOR_PRESS)                  // Wait for button press
}

Here the addition is UI_DRAW(SELECT_FONT, # ) where the number will be the corresponding index value for the new font that was injected into the d_lcd.c file.

Table of Contents

General

OS Components

UI

Inter-Communication Interface

Application Program Interfaces

Clone this wiki locally