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/
|
|
|
|
|
|
|
|
/// @file font_file_lister.h
|
|
|
|
/// @see font_file_lister.cpp
|
|
|
|
/// @ingroup font_collector
|
|
|
|
///
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
#pragma once
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs_fwd.h>
|
|
|
|
|
|
|
|
#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>
|
2012-01-12 23:32:09 +01:00
|
|
|
#include <set>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <string>
|
2012-01-12 23:32:09 +01:00
|
|
|
#include <vector>
|
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
|
|
|
|
|
|
|
/// @class FontFileLister
|
2012-01-12 23:32:09 +01:00
|
|
|
/// @brief Font lister interface
|
2007-06-20 07:18:47 +02:00
|
|
|
class FontFileLister {
|
|
|
|
public:
|
2012-02-02 20:18:40 +01:00
|
|
|
struct CollectionResult {
|
|
|
|
/// Characters which could not be found in any font files
|
|
|
|
wxString missing;
|
|
|
|
/// Paths to the file(s) containing the requested font
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<agi::fs::path> paths;
|
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
|
2012-12-30 01:32:36 +01:00
|
|
|
virtual CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) = 0;
|
2007-06-20 07:18:47 +02:00
|
|
|
};
|
2009-07-29 07:43:02 +02:00
|
|
|
|
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 {
|
2012-12-30 01:32:36 +01:00
|
|
|
std::set<wxUniChar> chars; ///< Characters used in this style which glyphs will be needed for
|
|
|
|
std::set<int> lines; ///< Lines on which this style is used via overrides
|
|
|
|
std::set<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;
|
|
|
|
/// The actual lister to use to get font paths
|
|
|
|
FontFileLister &lister;
|
|
|
|
|
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
|
2013-01-04 16:01:50 +01:00
|
|
|
std::set<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
|
|
|
|
FontCollector(FontCollectorStatusCallback status_callback, FontFileLister &lister);
|
|
|
|
|
|
|
|
/// @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
|
|
|
};
|