📄 gfx_drawlib.c.svn-base
字号:
} //init the structure; rmfont->metrics.unitsPerEm = RMbeBufToUint16(tp.head_table + 18); rmfont->metrics.ascender = (RMint16) RMbeBufToUint16(tp.hhea_table + 4); rmfont->metrics.descender = (RMint16) RMbeBufToUint16(tp.hhea_table + 6); err = upload_charmap(&charmap, &tp); if (RMFAILED(err)) { RMDBGLOG((GFXDBG,"Could not store truetype charmap on memory\n")); return RM_ERROR; } err = upload_glyphs(pRUA, &(rmfont->glyph_table), &charmap, &lib_index, charset, &tp); if (RMFAILED(err)) { RMDBGLOG((GFXDBG,"Could not store truetype glyphs on memory\n")); return RM_ERROR; } rmfont->lib_base_addr = lib_index.tab[0].addr; RFREE(file_buf_base); RFREE(charmap.ttf_cmap); return RM_OK;}static inline void set_max_advance(struct RMTTFont *rmfont){ RMuint32 i; RMint32 max_advance = 0; for (i = 0; i < 2048/*LAT1_CHAR_NO*/; i++) { if (max_advance < rmfont->glyph_table[i].metrics.advance) max_advance = rmfont->glyph_table[i].metrics.advance; } rmfont->metrics.max_advance = max_advance;}static inline RMstatus gfxTOpenFont(struct RUA *pRUA, struct RMTTFont **rmfont, RMnonAscii *fname, struct ttf_charset *charset){ RMascii *file_ext = (RMascii*) NULL; RMstatus err; if (RMnonAsciiLength(fname) >= 5) file_ext = RMnonAsciiToAscii(fname + RMnonAsciiLength(fname) - 5); else { RMDBGLOG((GFXDBG, "Font should be a truetype font (.ttf, .TTF) or a RealMagic Glyph Font (.rmg, .RMG)\n")); return RM_ERROR; } if (file_ext == NULL) { RMDBGLOG((GFXDBG, "Can't convert file extension from non-ascii to ascii\n")); return RM_ERROR; } *rmfont = MALLOC(sizeof(struct RMTTFont)); if (rmfont == NULL) { RFREE(file_ext); RMDBGLOG((GFXDBG, "Could not allocate struct RMTTFont (%ld bytes)\n", sizeof(struct RMTTFont))); return RM_FATALOUTOFMEMORY; } if (!(RMMemcmp(file_ext, ".ttf", 4)) || !(RMMemcmp(file_ext, ".TTF", 4))) { err = open_ttf_file(pRUA, *rmfont, fname, charset); if (RMFAILED(err)) goto cleanup; }#ifdef WITH_RMG else if( !(RMMemcmp( file_ext, ".rmg", 4)) || !(RMMemcmp( file_ext, ".RMG", 4))) { err = open_rmg_file(*rmfont, fname); if (RMFAILED(err)) goto cleanup; }#endif else { RMDBGLOG((GFXDBG, "Font should be a truetype font (.ttf, .TTF) or a RealMagic Glyph Font (.rmg, .RMG)\n")); err = RM_ERROR; goto cleanup; } set_max_advance(*rmfont); RFREE(file_ext); return RM_OK; cleanup: RFREE(file_ext); RFREE(*rmfont); *rmfont = NULL; return err;}static inline RMstatus gfx_load_font(struct RUA *pRua, RMnonAscii *fname){ RMstatus err; RMuint32 charset_unicodes[2048]; struct ttf_charset charset; RMnonAscii *file_ext; gdata.font_type = rtk_font_type_None; if (RMnonAsciiLength(fname) > 5) file_ext = fname + RMnonAsciiLength(fname) - 5; else { RMDBGLOG((GFXDBG, "Font should be a truetype font (.ttf, .TTF) or a PC Screen font (.psf, .PSF)\n")); return RM_ERROR; } if (!(RMMemcmp(file_ext, ".ttf", 4)) || !(RMMemcmp(file_ext, ".TTF", 4))) { gdata.font_type = rtk_font_type_TT; } else if (!(RMMemcmp(file_ext, ".psf", 4)) || !(RMMemcmp(file_ext, ".PSF", 4))) { gdata.font_type = rtk_font_type_PS; } else { RMDBGLOG((GFXDBG, "Font should be a truetype font (.ttf, .TTF) or a PC Screen font (.psf, .PSF)\n")); return RM_ERROR; } // switch(gdata.font_type){ // case rtk_font_type_None: // return RM_ERROR; // case rtk_font_type_TT: charset.unicodes = charset_unicodes; rtk86_fill_charset(&charset, rtk_charset_type_LATIN1); err = gfxTOpenFont(pRua, &(gdata.ttfont), fname, &charset); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Error while loading TT font\n")); gdata.font_type = rtk_font_type_None; return err; } // break; // case rtk_font_type_PS: // err = rtk86_load_ps_font(pRua, fname); // if (RMFAILED(err)){ // RMDBGLOG((GFXDBG, "Error while loading PS font\n")); // gdata.font_type = rtk_font_type_None; // return RM_ERROR; // } // break; // } return RM_OK;}static RMstatus RMTTCloseFont(struct RUA *pRUA, struct RMTTFont *rmfont){ RFREE(rmfont->glyph_table); rmfont->glyph_table = NULL; RUAFree(pRUA, rmfont->lib_base_addr); RFREE(rmfont); return RM_OK;}static RMstatus rtk86_unload_font(struct RUA *pRua){ // switch(gdata.font_type){ // case rtk_font_type_None: // return RM_ERROR; // case rtk_font_type_TT: if (gdata.ttfont != NULL) { RMTTCloseFont(pRua, gdata.ttfont); } // break; // case rtk_font_type_PS: // return rtk86_unload_ps_font(rtk); // } return RM_OK;}RMstatus gfxLoadFontFile(struct RUA *pRua, RMnonAscii *fontFile){ RMstatus err; RMuint32 charset_unicodes[256]; struct ttf_charset charset; charset.unicodes = charset_unicodes; if (gdata.font_type != rtk_font_type_None) { err = rtk86_unload_font(pRua); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Failed to close the previously open font\n")); return RM_ERROR; } } return gfx_load_font(pRua, fontFile);}/* set osd parameters */RMstatus gfxSetOSDParams(struct RUA *pRua, RMuint32 OSDaddr, RMuint32 OSDwidth, RMuint32 OSDheight){ RMstatus status; RMuint32 osdmemsize = 0; RMuint32 drawbuffsize = 0; // taken from osdmem to aid drawing of multiple part objects if (OSDaddr == 0 || OSDwidth <= 0) return RM_ERROR; // Calculate amount of memory to allocate osdmemsize = OSDwidth + ((OSDwidth & 0x3F) ? (64 - (OSDwidth & 0x3F)) : 0); osdmemsize *= OSDheight + ((OSDheight & 0x3F) ? (64 - (OSDheight & 0x3F)) : 0); osdmemsize *= 10; // drawbuffsize = 147456; drawbuffsize = OSDwidth + ((OSDwidth & 0x3F) ? (64 - (OSDwidth & 0x3F)) : 0); drawbuffsize *= OSDheight + ((OSDheight & 0x3F) ? (64 - (OSDheight & 0x3F)) : 0); // drawbuffsize /= 2; // drawbuffsize = 40000; // drawbuffsize *= 6; // osdmemsize = (OSDwidth * OSDheight * 4) / 1024; // if(osdmemsize <= 1024){ // osdmemsize = 2000000; // drawbuffsize = 10000; // } // else if(osdmemsize <= 2048){ // osdmemsize = 4500000; // drawbuffsize = 1572864; // } // else{ // osdmemsize = 4660000; // drawbuffsize = 40000; // } // Allocate memory RMMemset(&gdata.baseBuffer, 0, sizeof(RMdrawBuffer)); status = AllocateBaseBuffer(pRua, &gdata.baseBuffer, osdmemsize); if (RMFAILED(status)) { RMDBGLOG((GFXDBG, "Failed to allocate OSD buffer\n")); return RM_ERROR; } else { RMDBGLOG((GFXDBG, "Allocated a %.3f MB OSD surface\n", ((double)osdmemsize) / 1000000.0)); } RMMemset(&gdata.drawBuffer, 0, sizeof(RMdrawBuffer)); RMMemset(&gdata.backBuffer, 0, sizeof(RMdrawBuffer)); // Allocate extra buffer to help drawing -- no error in return since we may be ok without // The usable part of the base buffer is set to the end of the drawing buffer (if any). // When displaying pictures the begin of the base buffer will be set to 0 and will be restored // to the drawing buffer size when a page is to be displayed if (drawbuffsize) { if (RMSUCCEEDED(AllocateBuffer(&gdata.drawBuffer, drawbuffsize, TRUE))) { gdata.baseBuffer.offset = gdata.drawBuffer.size; } if (RMSUCCEEDED(AllocateBackBuffer(pRua, &gdata.backBuffer, drawbuffsize * 4))) { //gdata.baseBuffer.offset = gdata.backBuffer.size; } } gdata.osdAddr = OSDaddr; gdata.osdWidth = OSDwidth; gdata.osdHeight = OSDheight; // pass osd params to graphic loader SetOsdSurfaceSize(gdata.osdWidth, gdata.osdHeight); return RM_OK;}RMstatus gfxSetTvType(struct RUA *pRua, RMbool set4_3){ gdata.tvType = (set4_3 ? TVTYPE_4_3 : TVTYPE_16_9); DoTVRatio(pRua, gdata.tvType); return RM_OK;}/* draw a rectangle of a given color */RMstatus gfxDrawRect(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 width, RMuint16 height, RMuint32 color){ // RMstatus status; // // status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); // if(RMFAILED(status)) // return status; return Fill(pRua, x, y, width, height, color); //return BitBlt(pRua);}/* draw a vertical line of a given length, color and thickness*/RMstatus gfxDrawVLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){ RMstatus status; if (thickness <= 0 || length <= 0) return RM_ERROR; status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); if (RMFAILED(status)) return status; gfxDrawRect(pRua, x, y, thickness, length, color); return BitBlt(pRua);}/* draw a horizontal line of a given length, color and thickness*/RMstatus gfxDrawHLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){ // RMstatus status; if (thickness <= 0 || length <= 0) return RM_ERROR; // status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); // if(RMFAILED(status)) // return status; return gfxDrawRect(pRua, x, y, length, thickness, color); // return BitBlt(pRua);}RMstatus gfxDrawTransLine(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint16 length, RMuint16 thickness, RMuint32 color){ RMstatus status; if (thickness <= 0 || length <= 0) return RM_ERROR; status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); if (RMFAILED(status)) return status; RoundRect(pRua, x, y, length, thickness, color, TRUE, 0); return BitBlt(pRua);}/* draw a point of a given color*/RMstatus gfxDrawPoint(struct RUA *pRua, RMuint16 x, RMuint16 y, RMuint32 color){ return gfxDrawRect(pRua, x, y, 1, 1, color);}RMstatus gfxDrawButton(struct RUA *pRua, RMButtonObject *obj){ RMstatus status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); if (RMFAILED(status)) return status; DrawButton(pRua, 0, 0, obj, 0); return BitBlt(pRua);}RMstatus gfxDrawPopupButton(struct RUA *pRua, RMBitmapObject *popup, RMuint16 x, RMuint16 y, RMButtonObject *obj){ RMstatus status; RMuint8 bmpindex; if (obj->visible == FALSE) return RM_OK; status = GetBitmapIndex(pRua, popup->file, &bmpindex, TRUE); if (RMFAILED(status)) return status; return DrawButton(pRua, x, y, obj, bmpindex);}/* draw text */RMstatus gfxDrawStringEvent(struct RUA *pRua, RMuint16 xOrigen, RMuint16 yOrigen, RMStringObject *obj){ RMstatus status = RM_OK; // RMuint8 fontindex;//, predeffontindex; GFXLib_rect rect, rctext;//rc, // GFXLib_textdata txt; // RMtextitem lines[MAX_STR_LINES]; // RMuint8 count = 0; RMuint8 i; // RMuint16 maxwidth, maxheight; // RMuint8 fontheight; // RMuint32 color; Prop prop; prop.trunc = TRUNC_NONE; if (obj->visible == FALSE) return RM_OK; status = SetOutputSurfaceBuffer(pRua, gdata.backBuffer.baseAddr, gdata.osdWidth); if (RMFAILED(status)) return status; rect.x = obj->x + xOrigen; rect.y = obj->y + yOrigen; rect.width = obj->width; rect.height = obj->height; gfxDrawRect(pRua, rect.x - 10, rect.y - 8, 250, 53, 0xAA000000); // status = GetFontIndex(pRua, obj->fontfile, obj->charwidth, &fontindex); // if(RMFAILED(status)) // return status; // status = SetOutputSurface(pRua); // if(RMFAILED(status)) // return status; // fill the palette // SetTextPalette(pRua, obj->foregroundcolor, obj->backgroundcolor, obj->transparentbackground); // [RC] assuming 1bpp // SetTextColorFormat(pRua); // status = getPredefinedFontIndex(GetBmpPath(fontindex), &predeffontindex); // if(RMFAILED(status)) // return status; // fontheight = getFontHeight(predeffontindex); // gfxGetTextExtents(pRua, &prop, &rctext); // // // break up string // maxwidth = rect.width; // maxheight = yOrigen + obj->y + obj->height; // // rect.x = obj->x + xOrigen; // rect.width = maxwidth; // rect.height = rctext.height; // count = getTextLines(obj->text, predeffontindex, maxwidth, MAX_STR_LENGTH, MAX_STR_LINES, lines); // for(i = 0; i < count; i++){ RMMemset(&prop, 0, sizeof(Prop)); RMCopyAscii(prop.text, obj->text/*lines[0]*/); prop.alignment = obj->textalign; prop.fgColor = obj->backgroundcolor; prop.bgColor = obj->foregroundcolor;// & 0x00FFFFFF; // txt.transparentbackground = obj->transparentbackground; prop.scale = atoi(obj->fontfile); gfxGetTextExtents(pRua, &prop, &rctext); // break up string // maxwidth = rect.width; // maxheight = yOrigen + obj->y + obj->height; // rect.x = obj->x;// + xOrigen; // rect.width = maxwidth; // rect.height = rctext.height; // calculate position and correct accordingly // rect.y = rect.height + obj->y + yOrigen; // printf("<<<<<<<<<<<<<<<<<<<<<<<(x, y, w, h) (%ld, %ld, %ld, %ld)\n", rect.x, rect.y, rect.width, rect.height); // verify we are not going beyond clipping area // if((rect.y + rect.height) > maxheight){ // status = RM_ERROR; // break; // } // txt.hasfocus = obj->hasfocus; // txt.outlinecolor = obj->outlinecolor; // txt.selectioncolor = obj->selectioncolor; // txt.inputchar = obj->inputchar; // txt.password = (obj->type == STRING_PASSWORD); // txt.input = (obj->type != STRING_UNKNOWN); if (obj->type == STRING_PASSWORD)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -