2007-07-29 03:21:28 +02:00
|
|
|
// Copyright (c) 2007, Niels Martin Hansen, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-07-29 03:21:28 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file font_file_lister_freetype.cpp
|
|
|
|
/// @brief FreeType based font collector
|
|
|
|
/// @ingroup font_collector
|
|
|
|
///
|
2007-07-29 03:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// Includes
|
2008-01-16 19:29:29 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#ifdef WITH_FREETYPE2
|
2007-07-29 03:21:28 +02:00
|
|
|
#include "font_file_lister_freetype.h"
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_GLYPH_H
|
|
|
|
#include FT_SFNT_NAMES_H
|
2007-09-12 01:22:26 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
# include <shlobj.h>
|
|
|
|
#endif
|
2007-07-29 03:21:28 +02:00
|
|
|
#include <wx/dir.h>
|
2009-07-14 23:28:49 +02:00
|
|
|
#include "charset_conv.h"
|
2007-07-29 03:21:28 +02:00
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2007-07-29 03:21:28 +02:00
|
|
|
FreetypeFontFileLister::FreetypeFontFileLister() {
|
|
|
|
// Initialize freetype2
|
|
|
|
FT_Init_FreeType(&ft2lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Destructor
|
|
|
|
///
|
2007-07-29 03:21:28 +02:00
|
|
|
FreetypeFontFileLister::~FreetypeFontFileLister() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Get name from face
|
|
|
|
/// @param face
|
|
|
|
/// @param id
|
|
|
|
/// @return
|
|
|
|
///
|
2008-01-14 07:38:33 +01:00
|
|
|
wxArrayString GetName(FT_Face &face,int id) {
|
2008-01-14 06:54:58 +01:00
|
|
|
// Get name
|
2008-01-14 07:38:33 +01:00
|
|
|
wxArrayString final;
|
|
|
|
int count = FT_Get_Sfnt_Name_Count(face);
|
|
|
|
|
|
|
|
for (int i=0;i<count;i++) {
|
|
|
|
FT_SfntName name;
|
|
|
|
FT_Get_Sfnt_Name(face,i,&name);
|
|
|
|
if (name.name_id == id) {
|
2008-01-14 08:06:43 +01:00
|
|
|
char *str = new char[name.string_len+2];
|
2008-01-14 07:38:33 +01:00
|
|
|
memcpy(str,name.string,name.string_len);
|
|
|
|
str[name.string_len] = 0;
|
2008-01-14 08:06:43 +01:00
|
|
|
str[name.string_len+1] = 0;
|
2009-07-14 23:28:49 +02:00
|
|
|
if (name.encoding_id == 0) final.Add(wxString(str, csConvLocal));
|
2008-01-14 08:06:43 +01:00
|
|
|
else if (name.encoding_id == 1) {
|
2008-01-14 19:36:10 +01:00
|
|
|
wxMBConvUTF16BE conv;
|
|
|
|
wxString string(str,conv);
|
|
|
|
final.Add(string);
|
2008-01-14 08:06:43 +01:00
|
|
|
}
|
2008-01-14 07:38:33 +01:00
|
|
|
delete [] str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-14 06:54:58 +01:00
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Gather data from system
|
|
|
|
///
|
2007-07-29 03:21:28 +02:00
|
|
|
void FreetypeFontFileLister::DoInitialize() {
|
|
|
|
// Load cache
|
|
|
|
LoadCache();
|
|
|
|
|
|
|
|
// Get fonts folder
|
|
|
|
wxString source;
|
2007-09-12 01:22:26 +02:00
|
|
|
#ifdef WIN32
|
2007-07-29 03:21:28 +02:00
|
|
|
TCHAR szPath[MAX_PATH];
|
|
|
|
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_FONTS,NULL,0,szPath))) {
|
|
|
|
source = wxString(szPath);
|
|
|
|
}
|
|
|
|
else source = wxGetOSDirectory() + _T("\\fonts");
|
|
|
|
source += _T("\\");
|
2007-09-12 01:22:26 +02:00
|
|
|
#else
|
|
|
|
# ifdef __APPLE__
|
|
|
|
// XXXHACK: Is this always a correct assumption?
|
|
|
|
// Fonts might be instaled in more places, I think...
|
|
|
|
source = _T("/Library/Fonts/");
|
|
|
|
# endif
|
|
|
|
#endif
|
2007-07-29 03:21:28 +02:00
|
|
|
|
|
|
|
// Get the list of fonts in the fonts folder
|
|
|
|
wxArrayString fontfiles;
|
|
|
|
wxDir::GetAllFiles(source, &fontfiles, wxEmptyString, wxDIR_FILES);
|
|
|
|
|
|
|
|
// Loop through each file
|
|
|
|
int fterr;
|
|
|
|
for (unsigned int i=0;i<fontfiles.Count(); i++) {
|
|
|
|
// Check if it's cached
|
|
|
|
if (IsFilenameCached(fontfiles[i])) continue;
|
|
|
|
|
|
|
|
// Loop through each face in the file
|
|
|
|
for (int facenum=0;true;facenum++) {
|
|
|
|
// Get font face
|
|
|
|
FT_Face face;
|
|
|
|
fterr = FT_New_Face(ft2lib, fontfiles[i].mb_str(*wxConvFileName), facenum, &face);
|
|
|
|
if (fterr) break;
|
|
|
|
|
2008-01-14 06:54:58 +01:00
|
|
|
// Special names for TTF and OTF
|
|
|
|
int nameCount = 0;
|
|
|
|
wxString ext = fontfiles[i].Right(4).Lower();
|
|
|
|
if (ext == _T(".otf") || ext == _T(".ttf") || ext == _T(".ttc_")) nameCount = FT_Get_Sfnt_Name_Count(face);
|
2008-01-14 07:38:33 +01:00
|
|
|
if (nameCount > 0) {
|
|
|
|
wxArrayString family = GetName(face,1);
|
|
|
|
wxArrayString subFamily = GetName(face,2);
|
|
|
|
wxArrayString fullName = GetName(face,4);
|
2008-01-14 19:36:10 +01:00
|
|
|
for (size_t j=0;j<family.Count() && j<subFamily.Count();j++) {
|
|
|
|
if (subFamily[j] != _T("Regular")) {
|
|
|
|
AddFont(fontfiles[i],family[j] + _T(" ") + subFamily[j]);
|
|
|
|
AddFont(fontfiles[i],_T("*")+family[j]);
|
|
|
|
}
|
|
|
|
else AddFont(fontfiles[i],family[j]);
|
|
|
|
}
|
2008-01-14 07:38:33 +01:00
|
|
|
for (size_t j=0;j<fullName.Count();j++) AddFont(fontfiles[i],fullName[j]);
|
2008-01-14 06:54:58 +01:00
|
|
|
}
|
|
|
|
|
2008-01-14 19:36:10 +01:00
|
|
|
// Ordinary fonts
|
|
|
|
else {
|
|
|
|
if (face->style_name) {
|
2009-07-14 23:28:49 +02:00
|
|
|
AddFont(fontfiles[i],wxString(face->family_name, csConvLocal) + _T(" ") + wxString(face->style_name, csConvLocal));
|
|
|
|
AddFont(fontfiles[i],_T("*")+wxString(face->family_name, csConvLocal));
|
2008-01-14 19:36:10 +01:00
|
|
|
}
|
2009-07-14 23:28:49 +02:00
|
|
|
else AddFont(fontfiles[i],wxString(face->family_name, csConvLocal));
|
2008-01-14 19:36:10 +01:00
|
|
|
}
|
2007-07-29 03:21:28 +02:00
|
|
|
FT_Done_Face(face);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save cache
|
|
|
|
SaveCache();
|
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
|
|
|
#endif WITH_FREETYPE2
|
2009-07-29 07:43:02 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|