]> git.vomp.tv Git - vompclient.git/commitdiff
Use system fonts
authorMarten Richter <marten.richter@freenet.de>
Sat, 17 Nov 2012 17:31:48 +0000 (18:31 +0100)
committerMarten Richter <marten.richter@freenet.de>
Sat, 17 Nov 2012 17:31:48 +0000 (18:31 +0100)
GNUmakefile
command.cc
fonts/licensesourcesans.txt [deleted file]
fonts/sourcesans.ttf [deleted file]
osd.h
osdopenvg.cc
osdopenvg.h
vopts.cc

index ae43c1a9baefb5e1d271daba0cff2377ceeb8c89..f759c164846cf4d99ffbd9d22a4632a9b46cb80a 100644 (file)
@@ -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  
index 32616e51197addb50ef819ed99f335b9104eabe6..789fb7e04d796607c59ca5e326e031a9d0e9414e 100644 (file)
@@ -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 (file)
index 1177330..0000000
+++ /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 (file)
index ffe2786..0000000
Binary files a/fonts/sourcesans.ttf and /dev/null differ
diff --git a/osd.h b/osd.h
index 0fe00b9a8f12738d6f5912618e08d54da99837b7..5b96e685d5eb8aeb307fcb9135a9d17f67478b5b 100644 (file)
--- 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;
index 85245dc4f80019c6520e0277acc49c275bf1ba0a..2dc2d9bc8411bdd657f419f5e2d995b0bceb13d8 100644 (file)
 #include "teletxt/txtfont.h"
 
 #include <sys/syscall.h>
+#include <fontconfig/fontconfig.h>
 #include <vector>
 #include <math.h>
 
 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<char*>::iterator itty=fontnames.begin();
+         while (itty!=fontnames.end()) {
+                 free((void*)*itty);
+
+                 itty++;
+         }
+  }
+  if (!fontnames_keys.size()) {
+         vector<char*>::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; i<fonts->nfont;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;i<fonts->nfont;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<VGubyte> segments;
        vector<VGfloat> 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;
index 44e88fef6ddece9b7d09b02afb6bdf89ac0a9292..baf6c0c5831b4a495b178efc1e861c06df88d4d8 100644 (file)
@@ -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<unsigned int,float> font_exp_x;
+    vector<char*> fontnames;
+    vector<char*> fontnames_keys;
+    char * cur_fontname;
 
     unsigned int loadTTchar(cTeletextChar c);
     map<unsigned int,int> tt_font_chars;
index d4ab0b3b778f2f4256b66e6894023bd5896d4159..6d9e24829d26f1c7dbcad69ad6f1dc823dda237f 100644 (file)
--- 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