/* Example application that renders the given (UTF-8 or ASCII) string into * a BMP image. */ #include #include #include #include "mcufont.h" #include "render_bmp.h" #include"board.c" //#include "ite_display_i80.h" /*************************************** * Parsing of the command line options * ***************************************/ int color=0; typedef struct { const char *fontname; const char *filename; const char *text; bool justify; enum mf_align_t alignment; int width; int margin; int anchor; int scale; } options_t; static const char default_text[] = "SATYAM SOFTWARE"; uint16_t image_width = 0; static void parse_options(options_t *options, const char *text,uint8_t fontType , uint8_t fontsize, uint8_t alignment) { // char align = 'j'; memset(options, 0, sizeof(options_t)); // options->fontname = mf_get_font_list()->font->short_name; if(fontType== 1 ) //'5') { options->fontname="MyFont96";//"MyFont48";//"MyFont96"; options->scale = 1; } else if(fontType== 2 )//'3') { options->fontname="DejaVuSans48bw"; options->scale = 1; } else if (fontType == 4) { options->fontname="DejaVuSans174bw"; options->scale=1; } /*if(fontsize != 1) { options->scale = 2; } else { options->scale = 1; }*/ options->scale = 1; options->filename = "out.bmp"; // options->text = default_text; options->text = text; options->width = 1600; //wrong right->1872 //because of 1bpp testing options->margin =1; if(alignment == 2) { options->alignment = 2;//right } else if (alignment ==1) { options->alignment =1; //center } else { options->alignment=0 ;// left; } options->justify = false; options->anchor = options->margin; if (options->width % 4 != 0) options->width += 4 - options->width % 4; } static void parse_optionsZeroCounter(options_t *options, const char *text,char language) { memset(options, 0, sizeof(options_t)); if(language=='2') { options->fontname="DevanagariBold96bw"; options->scale = 2; } else if(language=='3') { options->fontname="DejaVuSans48bw"; options->scale = 1; } else if(language=='5') { options->fontname="MyFont96"; options->scale = 1; } else { options->fontname="DejaVuSans174bw"; options->scale=1; } options->filename = "out.bmp"; options->text = default_text; options->text = text; options->width = 1600; //wrong right->1872 //because of 1bpp testing options->margin =1; //options->alignment=0; options->justify = true; options->anchor = options->margin; if (options->width % 4 != 0) options->width += 4 - options->width % 4; } /******************************************** * Callbacks to specify rendering behaviour * ********************************************/ typedef struct { options_t *options; uint8_t *buffer; uint16_t width; uint16_t height; uint16_t y; const struct mf_font_s *font; } state_t; /* Callback to write to a memory buffer. */ void printBits2(unsigned int num) { for(int bit=0;bit<(sizeof(unsigned int) * 8); bit++) { //printf("%i ", num & 0x01); num = num >> 1; } } void printBits(unsigned int num) { int bit = 0; while(bit < (sizeof(unsigned int) * 8)) { //printf("[....%i....] ", num & 0x01); num = num >> 1; bit++; } } static void pixel_callback(int16_t x, int16_t y, uint8_t count, uint8_t alpha, void *state) { state_t *s = (state_t*)state; uint32_t pos; int16_t value; uint32_t position; int16_t remainder; // PRINTF("this is called"); if (y < 0 || y >= s->height) return; if (x < 0 || x + count >= s->width) return; while (count--) { pos = (uint32_t)s->width * y + x; position = (y*(s->width/8)) + (x/8); //For 1bpp //position = pos / 8; if (x % 8 == 0) remainder = 0;//8; else remainder = x % 8; /* position = (y*(s->width/8)) + (x/8); if (position % 8 == 0) remainder = 8; else remainder = position % 8; */ value = s->buffer[25000]; value -= alpha; if (value < 0) value = 0; //s->buffer[pos] = value; //s->buffer[position]|=(1 << (8 - remainder)); //for 1 //remove (8-)endian (for working) if(color == 0) s->buffer[position] = s->buffer[position] & (~(1 << (remainder))); //for 0 else s->buffer[position]|=(1 << (remainder)); //for 1 s->buffer[position]|=(1 << (8 - remainder))//remove (8-)endian (for working) //printBits(s->buffer[position]); //printf("position = [%d] | renmainer = [%d] | buffer = [%d]",position,remainder, s->buffer[position]); x++; } /* while (count--) { pos = (uint32_t)s->width * y + x; value = s->buffer[pos]; value -= alpha; if (value < 0) value = 0; s->buffer[pos] = color; x++; } */ } /* Callback to render characters. */ static uint8_t character_callback(int16_t x, int16_t y, mf_char character, void *state) { const struct mf_font_s *font1; state_t *s = (state_t*)state; state_t *state1; if(character=='$') { // PRINTF("\r\nthis is for the INR symbol"); font1 = mf_find_font("IndianRupee174bw"); if(!font1) { PRINTF("not found"); } mf_char c='`'; int widthofchar=mf_character_width(font1,c); if(widthofchar%2!=0) { widthofchar+=1; } state1=(state_t*)s; x=x+60; y=y+30; character='`'; } else { //s1=(state_t*)s; return mf_render_character(s->font, x, y, character, pixel_callback, state); // font1 = mf_find_font(s1->options->fontname); // if(!font1) // { // PRINTF("not found"); // } // s1->font=font1; } //return mf_render_character(font1, x, y, character, pixel_callback, state1); return mf_render_character(s->font, x, y, character, pixel_callback, state); } /* Callback to render lines. */ static bool line_callback(const char *line, uint16_t count, void *state) { word_count = count; state_t *s = (state_t*)state; if (s->options->justify) { mf_render_justified(s->font, s->options->anchor, s->y, s->width - s->options->margin * 2, line, count, character_callback, state); } else { mf_render_aligned(s->font, s->options->anchor, s->y, s->options->alignment, line, count, character_callback, state); } s->y += s->font->line_height; //return true; //ORIGINAL STATE return false; } /* Callback to just count the lines. * Used to decide the image height */ bool count_lines(const char *line, uint16_t count, void *state) { int *linecount = (int*)state; (*linecount)++; return true; } int mcufontxy(TWord *w, TWord *h, char *Text,uint8_t fontType , uint8_t fontsize, uint8_t alignment,uint8_t bgcolor,uint8_t* fontheight) { int height; const struct mf_font_s *font; struct mf_scaledfont_s scaledfont; options_t options; state_t state = {}; parse_options(&options, Text, fontType , fontsize, alignment); options.width =*w;//1600-208; image_width = *w; if (options.width % 4 != 0) options.width += 4 - options.width % 4; font = mf_find_font(options.fontname); static int center=0; center++; if (!font) { return 2; } if (options.scale > 1) { mf_scale_font(&scaledfont, font, options.scale, options.scale); font = &scaledfont.font; } /* Count the number of lines that we need. */ height = 0; mf_wordwrap2(font, options.width - 2 * options.margin,options.text, count_lines, &height); *fontheight = font->height; height *= font->height; height += 4; /* Allocate and clear the image buffer */ state.options = &options; state.width = options.width; state.height = height; state.buffer = gpFrameBuf2; state.y = 2; state.font = font; *w = options.width; *h = height; if (bgcolor == 0x00) { color = 0xF0; } else { color = 0; } memset(state.buffer, bgcolor, 60000);//options.width * height); mf_wordwrap2(font, options.width - 2 * options.margin, options.text, line_callback, &state); return 0; } int mcufont2(TWord *w, TWord *h, char *Text,uint8_t fontType , uint8_t fontsize, uint8_t alignment,uint8_t bgcolor,uint8_t* fontheight) { int height; const struct mf_font_s *font; struct mf_scaledfont_s scaledfont; options_t options; state_t state = {}; parse_options(&options, Text, fontType , fontsize, alignment); font = mf_find_font(options.fontname); static int center=0; center++; if (!font) { return 2; } if (options.scale > 1) { mf_scale_font(&scaledfont, font, options.scale, options.scale); font = &scaledfont.font; } /* Count the number of lines that we need. */ height = 0; mf_wordwrap2(font, options.width - 2 * options.margin,options.text, count_lines, &height); *fontheight = font->height; height *= font->height; height += 4; /* Allocate and clear the image buffer */ state.options = &options; state.width = options.width; state.height = height; state.buffer = gpFrameBuf2; state.y = 2; state.font = font; *w = options.width; *h = height; if (bgcolor == 0x00) { color = 0xF0; } else { color = 0; } memset(state.buffer, bgcolor, 60000);//options.width * height); mf_wordwrap2(font, options.width - 2 * options.margin, options.text, line_callback, &state); return 0; } int mcufont2ZeroCounter(TWord *w, TWord *h, char *Text,char language,uint8_t bgcolor,uint8_t* fontheight) { int height; const struct mf_font_s *font; struct mf_scaledfont_s scaledfont; options_t options; state_t state = {}; parse_optionsZeroCounter(&options, Text, language); font = mf_find_font(options.fontname); static int center=0; center++; if (!font) { return 2; } if (options.scale > 1) { mf_scale_font(&scaledfont, font, options.scale, options.scale); font = &scaledfont.font; } /* Count the number of lines that we need. */ height = 0; mf_wordwrap2(font, options.width - 2 * options.margin,options.text, count_lines, &height); *fontheight = font->height+1; height *= font->height; height += 4; /* Allocate and clear the image buffer */ state.options = &options; state.width = options.width; state.height = height; state.buffer = gpFrameBuf2; state.y = 2; state.font = font; *w = options.width; *h = height; if (bgcolor == 0x00) { color = 0xF0; } else { color = 0; } memset(state.buffer, bgcolor, 60000);//options.width * height); mf_wordwrap2(font, options.width - 2 * options.margin, options.text, line_callback, &state); return 0; } int mcufont(TWord *w, TWord *h, char *Text,char language,uint8_t bgcolor) { int height; const struct mf_font_s *font; struct mf_scaledfont_s scaledfont; options_t options; state_t state = {}; // parse_options(&options, Text,language); font = mf_find_font(options.fontname); if (!font) { // printf("No such font: %s\n", options.fontname); return 2; } if (options.scale > 1) { mf_scale_font(&scaledfont, font, options.scale, options.scale); font = &scaledfont.font; } mf_char c=*Text; int widthofchar=mf_character_width(font,c); if(widthofchar%2!=0) { widthofchar+=1; } if(c=='$') { widthofchar=140; } options.width=widthofchar; // if((language==1)||(language=='3')) // { // // if(c=='$') // { // widthofchar=140; // } // options.width=widthofchar; // } //PRINTF("\r\n the width initial is %d",widthofchar); if(language=='2') { // PRINTF("this is the value of the length is:%d",strlen(Text)); if(strlen(Text)==2) { if((c=='l')) { c=*(Text+1); widthofchar+=mf_character_width(font,c); } else if(((c=*(Text+1))=='L')) { widthofchar+=mf_character_width(font,c); } widthofchar+=2; } if(widthofchar%2!=0) { widthofchar+=1; } options.width=widthofchar; } height = font->height; height += 4; /* /////////////////////////////////NEW HEIGHT height = 0; mf_wordwrap2(font, options.width - 2 * options.margin, options.text, count_lines, &height); height *= font->height; height += 4; /////////////////////////////NEW HEIGHT */ // if(c=='$') // { // height=130; // } // /* Allocate and clear the image buffer */ options.width+=4; state.options = &options; state.width = options.width; *w = options.width; *h = height; state.height = height; //Assigned display Buffer state.buffer = gpFrameBuf2; state.y = 2; state.font = font; if (bgcolor==0x00) { color=0xF0; } else { color=0; } /* Initialize image to white */ memset(state.buffer, bgcolor, options.width * height); /* Render the text */ mf_wordwrap(font, options.width - 2 * options.margin, options.text, line_callback, &state); return 0; }