2012-01-12 23:32:09 +01:00
|
|
|
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-06-20 07:18:47 +02:00
|
|
|
//
|
2012-01-12 23:32:09 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-06-20 07:18:47 +02:00
|
|
|
//
|
2012-01-12 23:32:09 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-06-20 07:18:47 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs_fwd.h>
|
2014-07-05 19:31:53 +02:00
|
|
|
#include <libaegisub/scoped_ptr.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
2012-09-25 01:35:27 +02:00
|
|
|
#include <functional>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2012-01-12 23:32:09 +01:00
|
|
|
#include <vector>
|
2015-12-23 21:27:24 +01:00
|
|
|
#include <unordered_map>
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <wx/string.h>
|
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
class AssDialogue;
|
2012-10-12 19:16:39 +02:00
|
|
|
class AssFile;
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2012-09-25 01:35:27 +02:00
|
|
|
typedef std::function<void (wxString, int)> FontCollectorStatusCallback;
|
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
|
|
|
|
2014-07-05 19:31:53 +02:00
|
|
|
struct CollectionResult {
|
|
|
|
/// Characters which could not be found in any font files
|
|
|
|
wxString missing;
|
|
|
|
/// Paths to the file(s) containing the requested font
|
|
|
|
std::vector<agi::fs::path> paths;
|
|
|
|
bool fake_bold = false;
|
|
|
|
bool fake_italic = false;
|
|
|
|
};
|
|
|
|
|
2015-12-23 21:27:24 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
class GdiFontFileLister {
|
2015-12-26 21:27:44 +01:00
|
|
|
std::unordered_multimap<uint32_t, agi::fs::path> index;
|
2015-12-23 21:27:24 +01:00
|
|
|
agi::scoped_holder<HDC> dc;
|
|
|
|
std::string buffer;
|
|
|
|
|
|
|
|
bool ProcessLogFont(LOGFONTW const& expected, LOGFONTW const& actual, std::vector<int> const& characters);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param cb Callback for status logging
|
|
|
|
GdiFontFileLister(FontCollectorStatusCallback &cb);
|
|
|
|
|
|
|
|
/// @brief Get the path to the font with the given styles
|
|
|
|
/// @param facename Name of font face
|
|
|
|
/// @param bold ASS font weight
|
|
|
|
/// @param italic Italic?
|
|
|
|
/// @param characters Characters in this style
|
|
|
|
/// @return Path to the matching font file(s), or empty if not found
|
|
|
|
CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::vector<int> const& characters);
|
|
|
|
};
|
|
|
|
|
|
|
|
using FontFileLister = GdiFontFileLister;
|
2015-10-28 20:44:22 +01:00
|
|
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
|
|
|
struct CoreTextFontFileLister {
|
|
|
|
CoreTextFontFileLister(FontCollectorStatusCallback &) {}
|
|
|
|
|
|
|
|
/// @brief Get the path to the font with the given styles
|
|
|
|
/// @param facename Name of font face
|
|
|
|
/// @param bold ASS font weight
|
|
|
|
/// @param italic Italic?
|
|
|
|
/// @param characters Characters in this style
|
|
|
|
/// @return Path to the matching font file(s), or empty if not found
|
|
|
|
CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::vector<int> const& characters);
|
|
|
|
};
|
|
|
|
|
|
|
|
using FontFileLister = CoreTextFontFileLister;
|
|
|
|
|
2015-12-23 21:27:24 +01:00
|
|
|
#else
|
2015-10-28 20:44:22 +01:00
|
|
|
|
2014-07-05 19:31:53 +02:00
|
|
|
typedef struct _FcConfig FcConfig;
|
|
|
|
typedef struct _FcFontSet FcFontSet;
|
|
|
|
|
|
|
|
/// @class FontConfigFontFileLister
|
|
|
|
/// @brief fontconfig powered font lister
|
|
|
|
class FontConfigFontFileLister {
|
|
|
|
agi::scoped_holder<FcConfig*> config;
|
|
|
|
|
|
|
|
/// @brief Case-insensitive match ASS/SSA font family against full name. (also known as "name for humans")
|
|
|
|
/// @param family font fullname
|
|
|
|
/// @param bold weight attribute
|
|
|
|
/// @param italic italic attribute
|
|
|
|
/// @return font set
|
|
|
|
FcFontSet *MatchFullname(const char *family, int weight, int slant);
|
2007-06-20 07:18:47 +02:00
|
|
|
public:
|
2014-07-05 19:31:53 +02:00
|
|
|
/// Constructor
|
|
|
|
/// @param cb Callback for status logging
|
|
|
|
FontConfigFontFileLister(FontCollectorStatusCallback &cb);
|
2012-02-02 20:18:40 +01:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
/// @brief Get the path to the font with the given styles
|
|
|
|
/// @param facename Name of font face
|
|
|
|
/// @param bold ASS font weight
|
|
|
|
/// @param italic Italic?
|
2012-02-01 05:17:33 +01:00
|
|
|
/// @param characters Characters in this style
|
2012-01-12 23:32:09 +01:00
|
|
|
/// @return Path to the matching font file(s), or empty if not found
|
2014-07-05 19:31:53 +02:00
|
|
|
CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::vector<int> const& characters);
|
2007-06-20 07:18:47 +02:00
|
|
|
};
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2015-12-23 21:27:24 +01:00
|
|
|
using FontFileLister = FontConfigFontFileLister;
|
|
|
|
#endif
|
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
/// @class FontCollector
|
|
|
|
/// @brief Class which collects the paths to all fonts used in a script
|
|
|
|
class FontCollector {
|
2012-02-02 20:18:40 +01:00
|
|
|
/// All data needed to find the font file used to render text
|
2012-01-12 23:32:09 +01:00
|
|
|
struct StyleInfo {
|
2012-12-30 01:32:36 +01:00
|
|
|
std::string facename;
|
2012-01-12 23:32:09 +01:00
|
|
|
int bold;
|
|
|
|
bool italic;
|
|
|
|
bool operator<(StyleInfo const& rgt) const;
|
|
|
|
};
|
|
|
|
|
2012-02-02 20:18:40 +01:00
|
|
|
/// Data about where each style is used
|
|
|
|
struct UsageData {
|
2014-07-05 19:31:53 +02:00
|
|
|
std::vector<int> chars; ///< Characters used in this style which glyphs will be needed for
|
|
|
|
std::vector<int> lines; ///< Lines on which this style is used via overrides
|
|
|
|
std::vector<std::string> styles; ///< ASS styles which use this style
|
2012-02-02 20:18:40 +01:00
|
|
|
};
|
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
/// Message callback provider by caller
|
|
|
|
FontCollectorStatusCallback status_callback;
|
2014-07-05 19:31:53 +02:00
|
|
|
|
2015-12-23 21:27:24 +01:00
|
|
|
FontFileLister lister;
|
2012-01-12 23:32:09 +01:00
|
|
|
|
2012-02-01 05:17:33 +01:00
|
|
|
/// The set of all glyphs used in the file
|
2012-02-02 20:18:40 +01:00
|
|
|
std::map<StyleInfo, UsageData> used_styles;
|
2012-01-12 23:32:09 +01:00
|
|
|
/// Style name -> ASS style definition
|
2012-12-30 01:32:36 +01:00
|
|
|
std::map<std::string, StyleInfo> styles;
|
2012-01-12 23:32:09 +01:00
|
|
|
/// Paths to found required font files
|
2014-07-05 19:31:53 +02:00
|
|
|
std::vector<agi::fs::path> results;
|
2012-01-12 23:32:09 +01:00
|
|
|
/// Number of fonts which could not be found
|
2013-12-12 01:29:48 +01:00
|
|
|
int missing = 0;
|
2012-02-02 20:18:40 +01:00
|
|
|
/// Number of fonts which were found, but did not contain all used glyphs
|
2013-12-12 01:29:48 +01:00
|
|
|
int missing_glyphs = 0;
|
2012-01-12 23:32:09 +01:00
|
|
|
|
|
|
|
/// Gather all of the unique styles with text on a line
|
2012-10-12 19:16:39 +02:00
|
|
|
void ProcessDialogueLine(const AssDialogue *line, int index);
|
2012-02-02 20:18:40 +01:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
/// Get the font for a single style
|
2012-02-02 20:18:40 +01:00
|
|
|
void ProcessChunk(std::pair<StyleInfo, UsageData> const& style);
|
|
|
|
|
|
|
|
/// Print the lines and styles on which a missing font is used
|
|
|
|
void PrintUsage(UsageData const& data);
|
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
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param status_callback Function to pass status updates to
|
|
|
|
/// @param lister The actual font file lister
|
2014-07-05 19:31:53 +02:00
|
|
|
FontCollector(FontCollectorStatusCallback status_callback);
|
2012-01-12 23:32:09 +01:00
|
|
|
|
|
|
|
/// @brief Get a list of the locations of all font files used in the file
|
|
|
|
/// @param file Lines in the subtitle file to check
|
|
|
|
/// @param status Callback function for messages
|
|
|
|
/// @return List of paths to fonts
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<agi::fs::path> GetFontPaths(const AssFile *file);
|
2012-01-12 23:32:09 +01:00
|
|
|
};
|