+++ /dev/null
-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.
#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");
freetype_inited=false;
wait_id=1;
+ const char *fontname="Droid Sans:style=Regular";
+ cur_fontname=(char*)malloc(strlen(fontname)+1);
+ strcpy(cur_fontname,fontname);
}
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();
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);
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;
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;
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);
}
}
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)) {
} 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);
//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());
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;