#include "DHL_OSAL.h" #include "DHL_DBG.h" #include "DHL_Graphic.h" #include "utfAPI.h" #include "DMG_Util.h" #include "grp_jungle.h" //#include "EIA_708_B_13.h" //#include "EIA_708_B_14.h" //#include "EIA_708_B_15.h" #include "EIA_708_B_17.h" #include "EIA_708_B_19.h" #include "EIA_708_B_21.h" //#include "EIA_708_B_23.h" //#include "EIA_708_B_25.h" //#include "EIA_708_B_26.h" //#include "EIA_708_B_28.h" //#include "EIA_708_B_30.h" //#include "EIA_708_B_32.h" //#include "EIA_708_B_OL.h" #include "JUNGR_FONT_UNI.h" //#include //#include DHL_MODULE("GRP_JG", 0); #define CH_BLANK 0x20 #define MAX_CH_W (p_reg_font_attr.size*8/10) static UT_FC p_reg_fc; static Jungle_FontAttr p_reg_font_attr; /* antialias dhl graphic¿¡¼­ ±×´ë·Î °¡Á®¿È */ static UINT32 p_antialias_argb8888_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) { int a1,r1,g1,b1; int a2,r2,g2,b2; /* no change */ if (alpha <= 0) return bg_pixel; else if (alpha >= 255) return fg_pixel; DHL_DECOMPOSE_ARGB8888(bg_pixel,a1,r1,g1,b1); DHL_DECOMPOSE_ARGB8888(fg_pixel,a2,r2,g2,b2); /* blend them */ DHL_BLEND(r1,r2,alpha); DHL_BLEND(g1,g2,alpha); DHL_BLEND(b1,b2,alpha); DHL_BLEND(a1,a2,alpha); /* TODO: is this right? */ return DHL_COMPOSE_ARGB8888(a1,r1,g1,b1); } static UINT32 p_antialias_argb4444_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) { int a1,r1,g1,b1; int a2,r2,g2,b2; /* no change */ if (alpha <= 0) return bg_pixel; else if (alpha >= 255) return fg_pixel; DHL_DECOMPOSE_ARGB4444(bg_pixel,a1,r1,g1,b1); DHL_DECOMPOSE_ARGB4444(fg_pixel,a2,r2,g2,b2); /* blend them */ DHL_BLEND(r1,r2,alpha); DHL_BLEND(g1,g2,alpha); DHL_BLEND(b1,b2,alpha); DHL_BLEND(a1,a2,alpha); return DHL_COMPOSE_ARGB4444(a1,r1,g1,b1); } static UINT32 p_antialias_rgb565_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) { int a1,r1,g1,b1; int a2,r2,g2,b2; /* no change */ if (alpha <= 0) return bg_pixel; else if (alpha >= 255) return fg_pixel; DHL_DECOMPOSE_RGB565(bg_pixel,r1,g1,b1); DHL_DECOMPOSE_RGB565(fg_pixel,r2,g2,b2); /* blend them */ DHL_BLEND(r1,r2,alpha); DHL_BLEND(g1,g2,alpha); DHL_BLEND(b1,b2,alpha); return DHL_COMPOSE_RGB565(r1,g1,b1); } static UINT32 p_antialias_argb1555_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) { int a1,r1,g1,b1; int a2,r2,g2,b2; /* no change */ if (alpha <= 0) return bg_pixel; else if (alpha >= 255) return fg_pixel; DHL_DECOMPOSE_ARGB1555(bg_pixel,a1,r1,g1,b1); DHL_DECOMPOSE_ARGB1555(fg_pixel,a2,r2,g2,b2); /* blend them */ DHL_BLEND(r1,r2,alpha); DHL_BLEND(g1,g2,alpha); DHL_BLEND(b1,b2,alpha); DHL_BLEND(a1,a2,alpha); return DHL_COMPOSE_ARGB1555(a1,r1,g1,b1); } #define USE_FONT_CACHE 1 #if USE_FONT_CACHE #define MAX_NUM_FONT_BUF 128 #define MAX_SIZE_FONT_CACHE (30*30) /* ÃÖ´ë ±Û²ÃÀº 30À̰í 30 ³Ñ¾î°¡¸é caching ¾ÈÇÔ */ static struct { UINT16 ch; INT8 width; INT8 height; INT8 sx; INT8 sy; INT8 ox; INT8 oy; INT8 bSize; UINT8 data[MAX_SIZE_FONT_CACHE]; } p_font_buf[MAX_NUM_FONT_BUF]; static int p_font_buf_idx; static void p_put_cache(UINT16 ch, int width, int height, int sx, int sy, int ox, int oy, int bSize, UINT8 *pdata) { p_font_buf[p_font_buf_idx].ch=ch; p_font_buf[p_font_buf_idx].width=width; p_font_buf[p_font_buf_idx].height=height; p_font_buf[p_font_buf_idx].sx=sx; p_font_buf[p_font_buf_idx].sy=sy; p_font_buf[p_font_buf_idx].ox=ox; p_font_buf[p_font_buf_idx].oy=oy; p_font_buf[p_font_buf_idx].bSize=bSize; memcpy(p_font_buf[p_font_buf_idx].data, pdata, bSize*sy); if(++p_font_buf_idx>=MAX_NUM_FONT_BUF) p_font_buf_idx=0; } static int p_get_cache_idx(UINT16 ch) { int i; for(i=0; i=0xac00) { /* ÇѱÛÀ̸é ÀÚµ¿ º¯È¯*/ ut_SetFont(&p_reg_fc, 100); } #if USE_FONT_CACHE { int cache_idx=p_get_cache_idx(ch); if(cache_idx>=0) { ch_width=p_font_buf[cache_idx].width; ch_height=p_font_buf[cache_idx].height; ch_sx=p_font_buf[cache_idx].sx; ch_sy=p_font_buf[cache_idx].sy; ch_ox=p_font_buf[cache_idx].ox; ch_oy=p_font_buf[cache_idx].oy; bsize=p_font_buf[cache_idx].bSize; pdata=p_font_buf[cache_idx].data; goto label_font_drawing; } } #endif ut_GetCharImage(&p_reg_fc, ch, &image); if(image.type != _UT_IMAGE_TYPE_BITMAP_65) { ut_GetCharImage(&p_reg_fc, CH_BLANK, &image); } if(image.type != _UT_IMAGE_TYPE_BITMAP_65) { dprint(0, "getting image from jungle font engine failed!!!(0x%x:%c)\n", ch, ch); if(ch>=0xac00) { /* ¿ø·¡´ë·Î º¯°æ */ ut_SetFont(&p_reg_fc, p_reg_font_attr.font_style); } return 0; } ch_width=image.width; ch_height=image.height; ch_sx=image.bbox.sx; ch_sy=image.bbox.sy; ch_ox=image.bbox.ox; ch_oy=image.bbox.oy; bsize=image.bSize; pdata=image.data; #if USE_FONT_CACHE p_put_cache(ch, ch_width, ch_height, ch_sx, ch_sy, ch_ox, ch_oy, bsize, pdata); #endif label_font_drawing : if(ch>=0xac00) { /* ¿ø·¡´ë·Î º¯°æ */ ut_SetFont(&p_reg_fc, p_reg_font_attr.font_style); } #if 0 x_margin=MAX_CH_W*1/20; //sizeÀÇ 1/10ÀÌ marginÀÌ µÊ #else x_margin=0; #endif dprint(2, "plane_addr(0x%x), plane_pitch(%d), pixel_type(%d)\n", plane_addr, plane_pitch, pixel_type); if(p_reg_font_attr.is_underline) { //underline DHL_DrawHLine(id, x, y+p_reg_font_attr.size*(1-x_margin), ch_width+x_margin*2, c_font); } if(pixel_type==eDHL_PIXELTYPE_ARGB4444) { c_font=DHL_COMPOSE_ARGB4444(c_font>>24, (c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); } else if(pixel_type==eDHL_PIXELTYPE_RGB565) { c_font=DHL_COMPOSE_RGB565((c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); } else if(pixel_type==eDHL_PIXELTYPE_ARGB1555) { c_font=DHL_COMPOSE_ARGB1555(c_font>>24, (c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); } c_edge=p_reg_font_attr.c_edge; if(pixel_type==eDHL_PIXELTYPE_ARGB4444) { c_edge=DHL_COMPOSE_ARGB4444(c_edge>>24, (c_edge>>16)&0xff, (c_edge>>8)&0xff, c_edge&0xff); } else if(pixel_type==eDHL_PIXELTYPE_RGB565) { c_edge=DHL_COMPOSE_RGB565((c_edge>>16)&0xff, (c_edge>>8)&0xff, c_edge&0xff); } else if(pixel_type==eDHL_PIXELTYPE_ARGB1555) { c_edge=DHL_COMPOSE_ARGB1555(c_edge>>24, (c_edge>>16)&0xff, (c_edge>>8)&0xff, c_edge&0xff); } if(ch>=0x200 && !p_reg_font_attr.is_unicode) { //¿Ï¼ºÇüÀ» unicode·Î º¯°æÇÔ. ch=DMG_Ksx1001toUnicode(ch); } for(j=0, p=pdata; j=_UT_IMAGE_TYPE_BITMAP_65_SMOOTH_COLOR_CORNER) continue; if(pixel_type==eDHL_PIXELTYPE_ARGB8888) { c_bg=DHL_GET_PIXEL32(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j); if(p[i]==_UT_IMAGE_TYPE_BITMAP_65_SHADOW_COLOR) color=c_edge; else color=p_antialias_argb8888_pixels(c_bg, c_font, p[i]*4); DHL_SET_PIXEL32(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j, color); } else if(pixel_type==eDHL_PIXELTYPE_ARGB4444) { c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j); if(p[i]==_UT_IMAGE_TYPE_BITMAP_65_SHADOW_COLOR) color=c_edge; else color=p_antialias_argb4444_pixels(c_bg, c_font, p[i]*4); DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j, color); } else if(pixel_type==eDHL_PIXELTYPE_RGB565) { c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j); if(p[i]==_UT_IMAGE_TYPE_BITMAP_65_SHADOW_COLOR) color=c_edge; else color=p_antialias_rgb565_pixels(c_bg, c_font, p[i]*4); DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j, color); } else if(pixel_type==eDHL_PIXELTYPE_ARGB1555) { c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j); if(p[i]==_UT_IMAGE_TYPE_BITMAP_65_SHADOW_COLOR) color=c_edge; else color=p_antialias_argb1555_pixels(c_bg, c_font, p[i]*4); DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, y+p_reg_font_attr.size-ch_oy-j, color); } } } DHL_PostDraw(id, x, y, ch_width+x_margin*2, p_reg_font_attr.size); return ch_width+x_margin*2; } int Jungle_GetChWidth(UINT16 ch) { int ch_width, ch_height; int ch_sx, ch_sy, ch_ox, ch_oy, bsize; UINT8 *pdata; UT_IMAGE image; if(ch>=0xac00) { /* ÇѱÛÀ̸é ÀÚµ¿ º¯È¯*/ ut_SetFont(&p_reg_fc, 100); } #if USE_FONT_CACHE { int cache_idx=p_get_cache_idx(ch); if(cache_idx>=0) { ch_width=p_font_buf[cache_idx].width; ch_height=p_font_buf[cache_idx].height; ch_sx=p_font_buf[cache_idx].sx; ch_sy=p_font_buf[cache_idx].sy; ch_ox=p_font_buf[cache_idx].ox; ch_oy=p_font_buf[cache_idx].oy; bsize=p_font_buf[cache_idx].bSize; pdata=p_font_buf[cache_idx].data; goto label_font_drawing; } } #endif ut_GetCharImage(&p_reg_fc, ch, &image); if(image.type == _UT_IMAGE_TYPE_NULL_GLYPH) { ut_GetCharImage(&p_reg_fc, CH_BLANK, &image); } ch_width=image.width; ch_height=image.height; ch_sx=image.bbox.sx; ch_sy=image.bbox.sy; ch_ox=image.bbox.ox; ch_oy=image.bbox.oy; bsize=image.bSize; pdata=image.data; if (ch_sx + ch_ox > ch_width) ch_width = ch_sx + ch_ox; // 2012.10.10 megakiss newcon2 #2194 Handwritten font broken solve #if USE_FONT_CACHE p_put_cache(ch, ch_width, ch_height, ch_sx, ch_sy, ch_ox, ch_oy, bsize, pdata); #endif label_font_drawing : if(ch>=0xac00) { /* ¿ø·¡´ë·Î º¯°æ */ ut_SetFont(&p_reg_fc, p_reg_font_attr.font_style); } return ch_width+(MAX_CH_W*1/20)*2; } int Jungle_GetChHeight(UINT16 ch) { int ch_width, ch_height; int ch_sx, ch_sy, ch_ox, ch_oy, bsize; UINT8 *pdata; UT_IMAGE image; if(ch>=0xac00) { /* ÇѱÛÀ̸é ÀÚµ¿ º¯È¯*/ ut_SetFont(&p_reg_fc, 100); } #if USE_FONT_CACHE { int cache_idx=p_get_cache_idx(ch); if(cache_idx>=0) { ch_width=p_font_buf[cache_idx].width; ch_height=p_font_buf[cache_idx].height; ch_sx=p_font_buf[cache_idx].sx; ch_sy=p_font_buf[cache_idx].sy; ch_ox=p_font_buf[cache_idx].ox; ch_oy=p_font_buf[cache_idx].oy; bsize=p_font_buf[cache_idx].bSize; pdata=p_font_buf[cache_idx].data; goto label_font_drawing; } } #endif ut_GetCharImage(&p_reg_fc, ch, &image); if(image.type == _UT_IMAGE_TYPE_NULL_GLYPH) ut_GetCharImage(&p_reg_fc, CH_BLANK, &image); ch_width=image.width; ch_height=image.height; ch_sx=image.bbox.sx; ch_sy=image.bbox.sy; ch_ox=image.bbox.ox; ch_oy=image.bbox.oy; bsize=image.bSize; pdata=image.data; #if USE_FONT_CACHE p_put_cache(ch, ch_width, ch_height, ch_sx, ch_sy, ch_ox, ch_oy, bsize, pdata); #endif label_font_drawing : if(ch>=0xac00) { /* ¿ø·¡´ë·Î º¯°æ */ ut_SetFont(&p_reg_fc, p_reg_font_attr.font_style); } return ch_height*11/10; //¾à 1.1¹è¸¦ Ű¿î Å©±â } void Jungle_GetFontAttr(Jungle_FontAttr *pfont_attr) { memcpy(pfont_attr, &p_reg_font_attr, sizeof(*pfont_attr)); } void Jungle_SetFontAttr(Jungle_FontAttr *pfont_attr) { BOOL bchanged=FALSE; if(pfont_attr->size!=p_reg_font_attr.size) { ut_SetSize(&p_reg_fc, pfont_attr->size, pfont_attr->size); bchanged=TRUE; } if(pfont_attr->is_bold!=p_reg_font_attr.is_bold) { ut_SetBold(&p_reg_fc, pfont_attr->is_bold?1:0); bchanged=TRUE; } if(pfont_attr->is_italic!=p_reg_font_attr.is_italic) { ut_SetItalic(&p_reg_fc, pfont_attr->is_italic?1:0); bchanged=TRUE; } if(pfont_attr->font_style!=p_reg_font_attr.font_style) { ut_SetFont(&p_reg_fc, pfont_attr->font_style); bchanged=TRUE; } if(pfont_attr->edge_type!=p_reg_font_attr.edge_type) { int edge_type=pfont_attr->edge_type; //edge type 4´Â 16, 5´Â 14·Î º¯È¯ÇØÁà¾ß ÇÔ. if(edge_type==4) edge_type=16; else if(edge_type==5) edge_type=14; ut_SetEdgeType(&p_reg_fc, edge_type); bchanged=TRUE; } if(bchanged) { memcpy(&p_reg_font_attr, pfont_attr, sizeof(p_reg_font_attr)); p_init_cache(); //font°¡ º¯°æµÇ¾úÀ¸¹Ç·Î ÆùÆ® cache ÃʱâÈ­. } } static void *p_jg_malloc(unsigned int size) { return DHL_OS_Malloc(size); } static void p_jg_free(void *ptr) { DHL_OS_Free(&ptr); } void Jungle_FontInit(Jungle_FontAttr *pfont_attr) { ut_InitFontManager(p_jg_malloc, p_jg_free, 0, 0, 0, 0); ut_InitFontContext(&p_reg_fc, 0, 0); //ut_AddFont(EIA_708_B_13); //ut_AddFont(EIA_708_B_14); //ut_AddFont(EIA_708_B_15); ut_AddFont(EIA_708_B_17); ut_AddFont(EIA_708_B_19); ut_AddFont(EIA_708_B_21); //ut_AddFont(EIA_708_B_23); //ut_AddFont(EIA_708_B_25); //ut_AddFont(EIA_708_B_26); //ut_AddFont(EIA_708_B_28); //ut_AddFont(EIA_708_B_30); //ut_AddFont(EIA_708_B_32); //ut_AddFont(EIA_708_B_OL); ut_AddFont(JUNGR_FONT); ut_SetSize(&p_reg_fc, pfont_attr->size, 0); ut_SetBold(&p_reg_fc, 0); ut_SetItalic(&p_reg_fc, 0); ut_SetFont(&p_reg_fc, 0); ut_SetEdgeType(&p_reg_fc, 0); Jungle_SetFontAttr(pfont_attr); } #if 0 ___Debug___() #endif