From: Marten Richter Date: Sat, 17 Nov 2012 17:31:48 +0000 (+0100) Subject: Use system fonts X-Git-Tag: 0-4-0^2~12^2~21 X-Git-Url: https://git.vomp.tv/gitweb/?a=commitdiff_plain;h=fd57c5893f1e43bbf6a87d4e867301d713bfc213;p=vompclient.git Use system fonts --- diff --git a/GNUmakefile b/GNUmakefile index ae43c1a..f759c16 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -57,7 +57,7 @@ endif ifeq ($(vomp_platform),raspberry) $(info Raspberry pi flags) -LDFLAGS = -Wall -Wl,--format=binary -Wl,fonts/sourcesans.ttf -Wl,other/vdrhires.jpg -Wl,other/wallpaper720p.jpg -Wl,--format=default +LDFLAGS = -Wall -Wl,--format=binary -Wl,other/vdrhires.jpg -Wl,other/wallpaper720p.jpg -Wl,--format=default LIBS = -L/opt/vc/lib -lpthread -lrt -lEGL -lOpenVG -lopenmaxil -lbcm_host -lavformat -lavcodec -lavutil OBJECTS += main.o threadp.o osdvector.o surfacevector.o osdopenvg.o ledraspberry.o mtdraspberry.o videoomx.o audioomx.o wjpegsimple.o remotelinux.o diff --git a/command.cc b/command.cc index 32616e5..789fb7e 100644 --- a/command.cc +++ b/command.cc @@ -961,6 +961,16 @@ void Command::doJustConnected(VConnect* vconnect) if (DEFAULT_TCP_WINDOWSIZE) vdr->setReceiveWindow(2048); // Default } + config = vdr->configLoad("Advanced", "Font Name"); + if (config) + { + Osd::getInstance()->setFont(config); + logger->log("Command", Log::INFO, "Setting Font to %s", config); + delete[] config; + + } + + config = vdr->configLoad("Advanced", "Disable WOL"); if (config) { diff --git a/fonts/licensesourcesans.txt b/fonts/licensesourcesans.txt deleted file mode 100644 index 1177330..0000000 --- a/fonts/licensesourcesans.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fonts/sourcesans.ttf b/fonts/sourcesans.ttf deleted file mode 100644 index ffe2786..0000000 Binary files a/fonts/sourcesans.ttf and /dev/null differ diff --git a/osd.h b/osd.h index 0fe00b9..5b96e68 100644 --- a/osd.h +++ b/osd.h @@ -46,6 +46,9 @@ class Osd virtual void screenShot(const char* fileName)=0; + virtual int getFontNames(const char *** names,const char *** names_keys){ return 0;}; + virtual void setFont(const char * fontname){}; + protected: static Osd* instance; int initted; diff --git a/osdopenvg.cc b/osdopenvg.cc index 85245dc..2dc2d9b 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -30,13 +30,12 @@ #include "teletxt/txtfont.h" #include +#include #include #include using namespace Magick; -extern uint8_t font_data[] asm("_binary_fonts_sourcesans_ttf_start"); -extern uint8_t font_data_end[] asm("_binary_fonts_sourcesans_ttf_end"); extern uint8_t vdr_data[] asm("_binary_other_vdrhires_jpg_start"); extern uint8_t vdr_data_end[] asm("_binary_other_vdrhires_jpg_end"); extern uint8_t wallpaper_data[] asm("_binary_other_wallpaper720p_jpg_start"); @@ -59,6 +58,9 @@ OsdOpenVG::OsdOpenVG() freetype_inited=false; wait_id=1; + const char *fontname="Droid Sans:style=Regular"; + cur_fontname=(char*)malloc(strlen(fontname)+1); + strcpy(cur_fontname,fontname); } @@ -70,7 +72,24 @@ OsdOpenVG::~OsdOpenVG() shutdown(); } + if (cur_fontname) free(cur_fontname); if (freetype_inited) FT_Done_Face(ft_face); + if (!fontnames.size()) { + vector::iterator itty=fontnames.begin(); + while (itty!=fontnames.end()) { + free((void*)*itty); + + itty++; + } + } + if (!fontnames_keys.size()) { + vector::iterator itty=fontnames_keys.begin(); + while (itty!=fontnames_keys.end()) { + free((void*)*itty); + + itty++; + } + } vgmutex.Unlock(); taskmutex.Unlock(); @@ -216,7 +235,43 @@ int OsdOpenVG::init(void* device) aspect_correction= ((float)BACKBUFFER_HEIGHT)/576.f/(((float)BACKBUFFER_WIDTH)/720.f); initPaths(); - if (!loadFont()) { + if (!fontnames.size()) { + //inspired by and copied from vdr's code + FcInit(); + FcObjectSet *objset= FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL); + FcPattern * pattern=FcPatternCreate(); + FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); + FcFontSet* fonts = FcFontList(NULL, pattern, objset); + for (int i=0; infont;i++) { + char *s = (char *)FcNameUnparse(fonts->fonts[i]); + + if (s) { + char *c= strchr(s,':'); + if (c) { + char *s2= strchr(c+1,','); + if (s2) *s2=0; + } + char *p=strchr(s,','); + if (p) { + if (!c) *p=0; + else memmove(p,c,strlen(c)+1); + } + char *key=(char*)malloc(strlen(s)+1); + strcpy(key,s); + fontnames_keys.push_back(key); + char *s2=strstr(s,"style="); + if (s2) { + memmove(s2,s2+6,strlen(s2+6)+1); + } + fontnames.push_back(s); + } + } + FcFontSetDestroy(fonts); + FcPatternDestroy(pattern); + FcObjectSetDestroy(objset); + } + + if (!loadFont(false)) { return 0; } vgttfont=vgCreateFont(0); @@ -518,7 +573,31 @@ unsigned int OsdOpenVG::loadTTchar(cTeletextChar c) return glyph_index; } -int OsdOpenVG::loadFont() +int OsdOpenVG::getFontNames(const char *** names,const char *** names_keys) +{ + *names=(const char**)&(fontnames[0]); + *names_keys=(const char**)&(fontnames_keys[0]); + return fontnames.size(); +} + +void OsdOpenVG::setFont(const char * fontname) { + + if (strcmp(fontname,cur_fontname)) { + // new font! + if (cur_fontname) free(cur_fontname); + cur_fontname=(char*)malloc(strlen(fontname)+1); + strcpy(cur_fontname,fontname); + + struct OpenVGCommand comm; + comm.task=OVGreplacefont; + putOpenVGCommand(comm,false); + + + } +} + + +int OsdOpenVG::loadFont(bool newfont) { int error; float font_size=16.f; @@ -529,24 +608,57 @@ int OsdOpenVG::loadFont() Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x",error); return 0; } + } - error=FT_New_Memory_Face(ft_library,font_data,font_data_end-font_data,0,&ft_face ); + if (!freetype_inited || newfont) { + //first get the filename algorith extracted from vdr by Klaus Schmidinger + FcInit(); + FcPattern *pattern=FcNameParse((FcChar8*)cur_fontname); + FcPatternAddBool(pattern,FC_SCALABLE,FcTrue); + FcConfigSubstitute(NULL,pattern,FcMatchPattern); + FcDefaultSubstitute(pattern); + FcResult fres; + FcFontSet *fonts=FcFontSort(NULL,pattern,FcFalse,NULL,&fres); + FcChar8 *filename=NULL; + if (fonts) { + for (int i=0;infont;i++) { + FcBool canscale; + FcPatternGetBool(fonts->fonts[i],FC_SCALABLE,0,&canscale); + if (canscale){ + FcPatternGetString(fonts->fonts[i],FC_FILE,0,&filename); + break; + } + } + FcFontSetDestroy(fonts); + } else { + Log::getInstance()->log("OSD", Log::CRIT, "Could not locate a font! Abort!"); + return 0; + } + FcPatternDestroy(pattern); + + Log::getInstance()->log("OSD", Log::NOTICE, "Load Font %s: %s", cur_fontname,filename); + // second load the font + FT_Face new_ft_face; + error=FT_New_Face(ft_library,(const char*)filename,0,&new_ft_face ); if (error) { - Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x",error); + Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x %s",error,filename); return 0; } - error=FT_Set_Char_Size(ft_face,0,font_size*64,0,0 /*dpi*/); + error=FT_Set_Char_Size(new_ft_face,0,font_size*256,0,0 /*dpi*/); if (error) { - FT_Done_Face(ft_face); + FT_Done_Face(new_ft_face); Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x",error); return 0; } + FT_Face old_ft_face=ft_face; // do it thread safe + ft_face=new_ft_face; + if (freetype_inited) FT_Done_Face(old_ft_face);// freetype_inited=true; } vgfont=vgCreateFont(0); FT_ULong cur_char; FT_UInt glyph; - font_height=ft_face->size->metrics.height/64.f; + font_height=ft_face->size->metrics.height/256.f; cur_char = FT_Get_First_Char(ft_face,&glyph); vector segments; vector coord; @@ -606,8 +718,8 @@ int OsdOpenVG::loadFont() if (!(last_tag &0x1)) { segments.push_back(VG_QUAD_TO); int coord_size=coord.size(); - VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/64.f)*0.5f*aspect_correction; - VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/64.f))*0.5f; + VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/256.f)*0.5f*aspect_correction; + VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/256.f))*0.5f; coord.push_back(x); coord.push_back(y); } @@ -616,8 +728,8 @@ int OsdOpenVG::loadFont() } last_tag=tag; - coord.push_back(((float)fpoint.x)*aspect_correction/64.); - coord.push_back(font_size-((float)fpoint.y)/64.); + coord.push_back(((float)fpoint.x)*aspect_correction/256.); + coord.push_back(font_size-((float)fpoint.y)/256.); //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph coord %d %d %g %g",fpoint.x,fpoint.y,coord[coord.size()-2],coord[coord.size()-1]); } if (!(last_tag &0x1)) { @@ -626,8 +738,8 @@ int OsdOpenVG::loadFont() } else { segments.push_back(VG_QUAD_TO); } - coord.push_back(((float)pt[first_point].x)*aspect_correction/64.); - coord.push_back(font_size-((float)pt[first_point].y)/64.); + coord.push_back(((float)pt[first_point].x)*aspect_correction/256.); + coord.push_back(font_size-((float)pt[first_point].y)/256.); } //segments.push_back(VG_CLOSE_PATH); @@ -655,8 +767,8 @@ int OsdOpenVG::loadFont() //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError()); } VGfloat ori[]={0.f,0.f}; - VGfloat esp[]={ft_face->glyph->advance.x/64.f*aspect_correction,ft_face->glyph->advance.y/64.f}; - font_exp_x[glyph]=ft_face->glyph->advance.x/64.f*aspect_correction; //recalculate + VGfloat esp[]={ft_face->glyph->advance.x/256.f*aspect_correction,ft_face->glyph->advance.y/256.f}; + font_exp_x[glyph]=ft_face->glyph->advance.x/256.f*aspect_correction; //recalculate vgSetGlyphToPath(vgfont,glyph,path,VG_FALSE,ori,esp); //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError()); @@ -820,6 +932,12 @@ void OsdOpenVG::executeDrawCommand(SVGCommand & command) unsigned int OsdOpenVG::handleTask(OpenVGCommand& command) { switch (command.task){ + case OVGreplacefont: { + vgDestroyFont(vgfont); + loadFont(true); + return 0; + } break; + case OVGdestroyImageRef: { vgDestroyImage((VGImage)command.param1); return 0; diff --git a/osdopenvg.h b/osdopenvg.h index 44e88fe..baf6c0c 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -50,7 +50,8 @@ enum OpenVGTask { OVGcreateMonoBitmap, OVGcreateColorRef, OVGimageUploadLine, - OVGcreateImageFile + OVGcreateImageFile, + OVGreplacefont }; struct OpenVGCommand @@ -85,6 +86,10 @@ class OsdOpenVG : public OsdVector, public Thread_TYPE float getCharWidth(wchar_t c); void imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data); + int getFontNames(const char *** names,const char *** names_keys); + + virtual void setFont(const char * fontname); + protected: /*osd vector implementation*/ @@ -125,8 +130,11 @@ protected: VGFont vgfont; VGFont vgttfont; VGPaint vgttpaint; - int loadFont(); + int loadFont(bool fontchange); map font_exp_x; + vector fontnames; + vector fontnames_keys; + char * cur_fontname; unsigned int loadTTchar(cTeletextChar c); map tt_font_chars; diff --git a/vopts.cc b/vopts.cc index d4ab0b3..6d9e248 100644 --- a/vopts.cc +++ b/vopts.cc @@ -22,6 +22,7 @@ #include "colour.h" #include "video.h" +#include "osd.h" #include "audio.h" #include "remote.h" #include "boxstack.h" @@ -242,6 +243,14 @@ VOpts::VOpts() options.push_back(option); wop->addOptionLine(option); #endif + const char * * fontnames; + const char * * fontnames_keys; + int numfonts=Osd::getInstance()->getFontNames(&fontnames,&fontnames_keys); + if (numfonts) { + option = new Option(15, "Font Name", "Advanced", "Font Name", Option::TYPE_KEYED_TEXT, numfonts, 1, 0, fontnames,fontnames_keys); + options.push_back(option); + wop->addOptionLine(option); + } Remote::getInstance()->addOptionsToPanes(2,&options,wop); Video::getInstance()->addOptionsToPanes(2,&options,wop); @@ -432,6 +441,9 @@ void VOpts::doSave() VDR::getInstance()->setReceiveWindow(newTCPsize); break; } + case 15: { + Osd::getInstance()->setFont(options[i]->optionkeys[options[i]->userSetChoice]); + } break; } } else