making 5x8 characters into 6x8

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

making 5x8 characters into 6x8

Post by cobra1 »

Hi,

I need a bit of help with some code modification, im trying to add in an extra column to get 6x8 characters.

heres the code im working with

Code: Select all

/*Macro_LCD_Print_String_Start*/
    char xwidth, xpix, ypix, pos_Str, count, xcount, ycount, height, width, i;
    char Fontwidth = 1;                //First we assume small font
    char Fontheight = 1;
	char inv_colour = 1;
	
 
    char temp[6];
    temp[5] = 0x00;                        //Spacing Line


	if (Colour)
		inv_colour = 0;

    if (Font == 1)                     	//Double Height Sizes //Double Width
    {
        Fontwidth = 2;
    }
    if (Font == 2)                         //Double Height and Width Sizes
    {
        Fontwidth = 2;
        Fontheight = 2;
    }
    if (Font == 3)                         //Double Height Sizes
    {
        Fontheight = 2;
    }

    xcount = 0;
    for (i=0;i<MSZ_String;i++)         //Start at beginning of string and work along
    {
        if (String[i] == 0)
        	return;
        pos_Str = String[i] - 32;      //Calculate place in ASCII memory
		
	

        /* character is made up of 5*8 pixels, get all columns into temporary memory */
        for (count = 0; count < 5; count++)        //Use correct buffer location
        {
           
			if (pos_Str < 12)
            {
                temp[count]=ASCII1[(pos_Str*5)+count];
            }
            else if (pos_Str < 24)
            {
                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
            }
            else if (pos_Str < 36)
            {
                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
            }
            else if (pos_Str < 48)
            {
                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
            }
            else if (pos_Str < 60)
            {
                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
            }
            else if (pos_Str < 72)
            {
                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
            }
            else if (pos_Str < 84)
            {
                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
            }
            else if (pos_Str < 96)
            {
                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
            }
 			else if (pos_Str < 108)
            {
                temp[count]=ASCII9[((pos_Str - 96)*5)+count]; // this is for custom ASCII
            }

        }

	if (String[i] > 126)
			xwidth=5;
		else if (String[i] == 32)
			xwidth=4;        // width of space
	
		else
																	 //			xwidth=6; 
			{
			for (count=4,xwidth=6;count>0 && temp[count]==0;count--) //counts the 0 in last column
				{												     // normal font width with 1 space line 5+1
					xwidth--;                                        // remove spaces
			  	}
				
		}
       
 /* now working across columns of temporary memory */

        for (xpix=0; xpix<xwidth; xpix++)    //For 6 ASCII bytes 0 - 5
        {
            for (width=0;width<Fontwidth;width++)
            {
                ycount = 0;
                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
                {
                    for (height=0;height<Fontheight;height++)
                    {
                        if (test_bit(temp[xpix],ypix))
                        {
                            LCD_PlotPixel(X + xcount, Y + ycount, Colour);
                        }
                        else if (Transparent == 0)
                        {
                            LCD_PlotPixel(X+xcount, Y+ycount, inv_colour);
                        }
                        ycount++;
                    }
                }
                xcount++;
            }
        }
    }
	//LCD_Write_Screen(); //Needs to refresh whole display  
/*Macro_LCD_Print_String_End*/
I have tried changing the values for xwidth but the letters keep getting screwed up, i get added pixels in between characters etc.

if i do manage to get it to display a 6th column then i have no spaces in between the characters.

Does anyone know how to do this correctly??

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: making 5x8 characters into 6x8

Post by Benj »

Hello,

Here is the print function I use. it creates characters of 6 x 8 where the last column is a space.

Code: Select all

void Print (char* String, char X, char Y, char Font, char Transparent)
{
/*Macro_Print_Start*/
    char xpix, ypix, pos_Str, length_Str, count, xcount, ycount, height, width, i;
    char Fontwidth = 1;                //First we assume small font
    char Fontheight = 1;

    char temp[6];
    temp[5] = 0x00;                        //Spacing Line

    length_Str = strlen(String);       //Get length of string

    if (Font == 1)                     //Double Height Sizes //Double Width
    {
        Fontwidth = 2;
    }
    if (Font == 2)                         //Double Height and Width Sizes
    {
        Fontwidth = 2;
        Fontheight = 2;
    }
    if (Font == 3)                         //Double Height Sizes
    {
        Fontheight = 2;
    }


    xcount = 0;

    for (i=0;i<length_Str;i++)         //Start at beginning of string and work along
    {

        pos_Str = String[i] - 32;      //Calculate place in ASCII memory

        for (count = 0; count < 5; count++)        //Use correct buffer location
        {
            if (pos_Str < 12)
            {
                temp[count]=ASCII1[(pos_Str*5)+count];
            }
            else if (pos_Str < 24)
            {
                temp[count]=ASCII2[((pos_Str - 12)*5)+count];
            }
            else if (pos_Str < 36)
            {
                temp[count]=ASCII3[((pos_Str - 24)*5)+count];
            }
            else if (pos_Str < 48)
            {
                temp[count]=ASCII4[((pos_Str - 36)*5)+count];
            }
            else if (pos_Str < 60)
            {
                temp[count]=ASCII5[((pos_Str - 48)*5)+count];
            }
            else if (pos_Str < 72)
            {
                temp[count]=ASCII6[((pos_Str - 60)*5)+count];
            }
            else if (pos_Str < 84)
            {
                temp[count]=ASCII7[((pos_Str - 72)*5)+count];
            }
            else if (pos_Str < 95)
            {
                temp[count]=ASCII8[((pos_Str - 84)*5)+count];
            }
        }

        for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
        {
            for (width=0;width<Fontwidth;width++)
            {
                ycount = 0;
                for (ypix=0;ypix<8;ypix++)    //For 8 data bits in bytes 0 - 7
                {
                    for (height=0;height<Fontheight;height++)
                    {
                        if (test_bit(temp[xpix],ypix))
                        {
                            Plot(X + xcount, Y + ycount);
                        }
                        else if (Transparent == 0)
                        {
                            gLCD_Window(X+xcount+1, Y+ycount+1, X+xcount+1, Y+ycount+1);
                            gLCD_SendByte(MX_GFXLCD_PARAM, GFX_Back_Color);
							gLCD_SendByte(MX_GFXLCD_PARAM, GFX_Back_Color>>8);
                        }
                        ycount++;
                    }
                }
                xcount++;
            }
        }
    }
/*Macro_Print_End*/
}
To increase the width of the characters you would need to change the limits of this loop.

Code: Select all

char temp[6];
temp[5] = 0x00;                        //Spacing Line
for (xpix=0;xpix<6;xpix++)    //For 6 ASCII bytes 0 - 5
to

Code: Select all

char temp[7];
temp[6] = 0x00;                        //Spacing Line
for (xpix=0;xpix<7;xpix++)    //For 7 ASCII bytes 0 - 6
And then you would also need to increase the data array populate with correct data and update the data array pointers,

Code: Select all

 for (count = 0; count < 5; count++)        //Use correct buffer location
        {
            if (pos_Str < 12)
            {
                temp[count]=ASCII1[(pos_Str*5)+count];
            }

Code: Select all

 for (count = 0; count < 6; count++)        //Use correct buffer location
        {
            if (pos_Str < 12)
            {
                temp[count]=ASCII1[(pos_Str*6)+count];
            }

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: making 5x8 characters into 6x8

Post by cobra1 »

Hi Benj,

Thanks for your reply.

Can my macro be altered to do this or do I have to use and modify your macro?

If I have to use your macro is it just a simple case of replacing mine with it and it works?

Or do I have to use your modifications and adapt them to my macro

The reason I ask is because all these modifications you suggested I have tried and it doesn't work correctly. Also by changing the pos_string data from 5 to 6 incriments the character by 1. I.e 1 becomes 2 and A becomes B and so on.

Could you make the alterations required to my macro so I can just copy it in and see if it works I am getting close to what I want but I'm obviously missing something.

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: making 5x8 characters into 6x8

Post by cobra1 »

Ok, after much hair pulling, i got it to work. thanks for your help Ben, much appreciated.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: making 5x8 characters into 6x8

Post by Benj »

Hi Cobra,

Great glad you got it working correctly. Would you mind posting your code so I can see what you had to change in the end to get it to work.

Post Reply