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/
|
|
|
|
|
2012-02-25 03:58:23 +01:00
|
|
|
#include "font_file_lister.h"
|
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
#include "ass_dialogue.h"
|
2012-10-12 19:16:39 +02:00
|
|
|
#include "ass_file.h"
|
2012-01-12 23:32:09 +01:00
|
|
|
#include "ass_style.h"
|
2012-12-30 00:53:56 +01:00
|
|
|
#include "compat.h"
|
2014-05-29 17:28:37 +02:00
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
#include <libaegisub/format_flyweight.h>
|
|
|
|
#include <libaegisub/format_path.h>
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
#include <algorithm>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <tuple>
|
2013-02-01 17:43:24 +01:00
|
|
|
#include <unicode/uchar.h>
|
2012-01-12 23:32:09 +01:00
|
|
|
#include <wx/intl.h>
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2013-02-01 17:43:24 +01:00
|
|
|
namespace {
|
2014-07-05 19:31:53 +02:00
|
|
|
wxString format_missing(wxString const& str) {
|
|
|
|
wxString printable;
|
|
|
|
wxString unprintable;
|
|
|
|
for (wxUniChar c : str) {
|
|
|
|
if (!u_isUWhiteSpace(c.GetValue()))
|
|
|
|
printable += c;
|
|
|
|
else {
|
|
|
|
unprintable += fmt_wx("\n - U+%04X ", c.GetValue());
|
|
|
|
UErrorCode ec;
|
|
|
|
char buf[1024];
|
|
|
|
auto len = u_charName(c.GetValue(), U_EXTENDED_CHAR_NAME, buf, sizeof buf, &ec);
|
|
|
|
if (len != 0 && U_SUCCESS(ec))
|
|
|
|
unprintable += to_wx(buf);
|
|
|
|
if (c.GetValue() == 0xA0)
|
|
|
|
unprintable += " (\\h)";
|
2013-02-01 17:43:24 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
|
|
|
|
return printable + unprintable;
|
|
|
|
}
|
2013-02-01 17:43:24 +01:00
|
|
|
}
|
|
|
|
|
2014-07-05 19:31:53 +02:00
|
|
|
FontCollector::FontCollector(FontCollectorStatusCallback status_callback)
|
2013-11-21 18:13:36 +01:00
|
|
|
: status_callback(std::move(status_callback))
|
2014-07-05 19:31:53 +02:00
|
|
|
, lister(this->status_callback)
|
2012-01-12 23:32:09 +01:00
|
|
|
{
|
2007-06-20 07:18:47 +02:00
|
|
|
}
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
2012-01-12 23:32:09 +01:00
|
|
|
if (line->Comment) return;
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2013-11-09 15:25:50 +01:00
|
|
|
auto style_it = styles.find(line->Style);
|
|
|
|
if (style_it == end(styles)) {
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("Style '%s' does not exist\n", line->Style), 2);
|
2013-11-09 15:25:50 +01:00
|
|
|
++missing;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleInfo style = style_it->second;
|
2012-01-12 23:32:09 +01:00
|
|
|
StyleInfo initial = style;
|
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-02-02 20:18:40 +01:00
|
|
|
bool overriden = false;
|
|
|
|
|
2014-04-14 19:58:46 +02:00
|
|
|
for (auto& block : line->ParseTags()) {
|
2014-12-26 17:51:14 +01:00
|
|
|
switch (block->GetType()) {
|
|
|
|
case AssBlockType::OVERRIDE:
|
|
|
|
for (auto const& tag : static_cast<AssDialogueBlockOverride&>(*block).Tags) {
|
2014-07-05 19:31:53 +02:00
|
|
|
if (tag.Name == "\\r") {
|
2013-01-04 16:01:50 +01:00
|
|
|
style = styles[tag.Params[0].Get(line->Style.get())];
|
2012-02-02 20:18:40 +01:00
|
|
|
overriden = false;
|
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
else if (tag.Name == "\\b") {
|
2012-12-11 00:32:36 +01:00
|
|
|
style.bold = tag.Params[0].Get(initial.bold);
|
2012-02-02 20:18:40 +01:00
|
|
|
overriden = true;
|
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
else if (tag.Name == "\\i") {
|
2012-12-11 00:32:36 +01:00
|
|
|
style.italic = tag.Params[0].Get(initial.italic);
|
2012-02-02 20:18:40 +01:00
|
|
|
overriden = true;
|
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
else if (tag.Name == "\\fn") {
|
2012-12-30 01:32:36 +01:00
|
|
|
style.facename = tag.Params[0].Get(initial.facename);
|
2012-02-02 20:18:40 +01:00
|
|
|
overriden = true;
|
|
|
|
}
|
2012-01-12 23:32:09 +01:00
|
|
|
}
|
2014-12-26 17:51:14 +01:00
|
|
|
break;
|
|
|
|
case AssBlockType::PLAIN: {
|
|
|
|
auto text = block->GetText();
|
2012-02-02 20:31:27 +01:00
|
|
|
|
2012-12-30 18:04:43 +01:00
|
|
|
if (text.empty())
|
2012-02-02 20:31:27 +01:00
|
|
|
continue;
|
|
|
|
|
2014-07-05 19:31:53 +02:00
|
|
|
auto& usage = used_styles[style];
|
|
|
|
|
|
|
|
if (overriden) {
|
|
|
|
auto& lines = usage.lines;
|
|
|
|
if (lines.empty() || lines.back() != index)
|
|
|
|
lines.push_back(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& chars = usage.chars;
|
|
|
|
auto size = static_cast<int>(text.size());
|
|
|
|
for (int i = 0; i < size; ) {
|
|
|
|
if (text[i] == '\\' && i + 1 < size) {
|
|
|
|
char next = text[++i];
|
|
|
|
if (next == 'N' || next == 'n') {
|
|
|
|
++i;
|
2012-06-26 03:50:41 +02:00
|
|
|
continue;
|
2014-07-05 19:31:53 +02:00
|
|
|
}
|
|
|
|
if (next == 'h') {
|
|
|
|
++i;
|
|
|
|
chars.push_back(0xA0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
chars.push_back('\\');
|
|
|
|
continue;
|
2012-06-26 03:50:41 +02:00
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
|
|
|
|
UChar32 c;
|
|
|
|
U8_NEXT(&text[0], i, size, c);
|
|
|
|
chars.push_back(c);
|
2012-06-26 03:50:41 +02:00
|
|
|
}
|
2014-07-05 19:31:53 +02:00
|
|
|
|
|
|
|
sort(begin(chars), end(chars));
|
|
|
|
chars.erase(unique(chars.begin(), chars.end()), chars.end());
|
2014-12-26 17:51:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AssBlockType::DRAWING:
|
|
|
|
case AssBlockType::COMMENT:
|
|
|
|
break;
|
2012-01-12 23:32:09 +01:00
|
|
|
}
|
2009-07-24 04:30:11 +02:00
|
|
|
}
|
2007-06-20 07:18:47 +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
|
|
|
|
2012-02-02 20:18:40 +01:00
|
|
|
void FontCollector::ProcessChunk(std::pair<StyleInfo, UsageData> const& style) {
|
2012-02-02 20:31:37 +01:00
|
|
|
if (style.second.chars.empty()) return;
|
|
|
|
|
2014-07-05 19:31:53 +02:00
|
|
|
auto res = lister.GetFontPaths(style.first.facename, style.first.bold, style.first.italic, style.second.chars);
|
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-02-02 20:18:40 +01:00
|
|
|
if (res.paths.empty()) {
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("Could not find font '%s'\n", style.first.facename), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
PrintUsage(style.second);
|
2012-01-12 23:32:09 +01:00
|
|
|
++missing;
|
|
|
|
}
|
2008-01-14 19:36:10 +01:00
|
|
|
else {
|
2013-11-21 18:13:36 +01:00
|
|
|
for (auto& elem : res.paths) {
|
2014-07-05 19:31:53 +02:00
|
|
|
elem.make_preferred();
|
|
|
|
if (std::find(begin(results), end(results), elem) == end(results)) {
|
|
|
|
status_callback(fmt_tl("Found '%s' at '%s'\n", style.first.facename, elem), 0);
|
|
|
|
results.push_back(elem);
|
|
|
|
}
|
2012-02-02 20:18:40 +01:00
|
|
|
}
|
|
|
|
|
2014-04-18 01:07:01 +02:00
|
|
|
if (res.fake_bold)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("'%s' does not have a bold variant.\n", style.first.facename), 3);
|
2014-04-18 01:07:01 +02:00
|
|
|
if (res.fake_italic)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("'%s' does not have an italic variant.\n", style.first.facename), 3);
|
2014-04-18 01:07:01 +02:00
|
|
|
|
2012-02-02 20:18:40 +01:00
|
|
|
if (res.missing.size()) {
|
|
|
|
if (res.missing.size() > 50)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("'%s' is missing %d glyphs used.\n", style.first.facename, res.missing.size()), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
else if (res.missing.size() > 0)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_tl("'%s' is missing the following glyphs used: %s\n", style.first.facename, format_missing(res.missing)), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
PrintUsage(style.second);
|
|
|
|
++missing_glyphs;
|
2012-01-12 23:32:09 +01:00
|
|
|
}
|
2014-05-07 15:51:35 +02:00
|
|
|
else if (res.fake_bold || res.fake_italic)
|
|
|
|
PrintUsage(style.second);
|
2008-01-14 19:36:10 +01:00
|
|
|
}
|
2007-06-20 07:18:47 +02:00
|
|
|
}
|
|
|
|
|
2012-02-02 20:18:40 +01:00
|
|
|
void FontCollector::PrintUsage(UsageData const& data) {
|
|
|
|
if (data.styles.size()) {
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(_("Used in styles:\n"), 2);
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& style : data.styles)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_wx(" - %s\n", style), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.lines.size()) {
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(_("Used on lines:"), 2);
|
2012-11-04 04:53:03 +01:00
|
|
|
for (int line : data.lines)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_wx(" %d", line), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
status_callback("\n", 2);
|
|
|
|
}
|
|
|
|
status_callback("\n", 2);
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<agi::fs::path> FontCollector::GetFontPaths(const AssFile *file) {
|
2012-01-12 23:32:09 +01:00
|
|
|
missing = 0;
|
2012-02-02 20:18:40 +01:00
|
|
|
missing_glyphs = 0;
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
status_callback(_("Parsing file\n"), 0);
|
2012-02-02 20:18:40 +01:00
|
|
|
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto const& style : file->Styles) {
|
|
|
|
StyleInfo &info = styles[style.name];
|
|
|
|
info.facename = style.font;
|
|
|
|
info.bold = style.bold;
|
|
|
|
info.italic = style.italic;
|
2014-07-05 19:31:53 +02:00
|
|
|
used_styles[info].styles.push_back(style.name);
|
2007-06-20 07:18:47 +02:00
|
|
|
}
|
|
|
|
|
2012-11-27 01:37:53 +01:00
|
|
|
int index = 0;
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto const& diag : file->Events)
|
|
|
|
ProcessDialogueLine(&diag, ++index);
|
2012-11-27 01:37:53 +01:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
status_callback(_("Searching for font files\n"), 0);
|
2014-03-26 18:36:34 +01:00
|
|
|
for (auto const& style : used_styles) ProcessChunk(style);
|
2012-01-12 23:32:09 +01:00
|
|
|
status_callback(_("Done\n\n"), 0);
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<agi::fs::path> paths;
|
2012-01-12 23:32:09 +01:00
|
|
|
paths.reserve(results.size());
|
|
|
|
paths.insert(paths.end(), results.begin(), results.end());
|
2007-06-20 07:18:47 +02:00
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
if (missing == 0)
|
|
|
|
status_callback(_("All fonts found.\n"), 1);
|
|
|
|
else
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_plural(missing, "One font could not be found\n", "%d fonts could not be found.\n", missing), 2);
|
2012-02-02 20:18:40 +01:00
|
|
|
if (missing_glyphs != 0)
|
2014-05-29 17:28:37 +02:00
|
|
|
status_callback(fmt_plural(missing_glyphs,
|
|
|
|
"One font was found, but was missing glyphs used in the script.\n",
|
|
|
|
"%d fonts were found, but were missing glyphs used in the script.\n",
|
2014-03-12 17:13:46 +01:00
|
|
|
missing_glyphs), 2);
|
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
|
|
|
return paths;
|
2007-06-20 07:18:47 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:32:09 +01:00
|
|
|
bool FontCollector::StyleInfo::operator<(StyleInfo const& rgt) const {
|
2013-01-04 16:01:50 +01:00
|
|
|
return std::tie(facename, bold, italic) < std::tie(rgt.facename, rgt.bold, rgt.italic);
|
2007-06-20 07:18:47 +02:00
|
|
|
}
|