Compare commits

...

5 Commits

Author SHA1 Message Date
Thomas Goyne 6f546951b4 Use appropriate DPI images in more places on macOS 2019-10-06 12:46:06 -07:00
Thomas Goyne 85f711fccc Adjust the index of the drag subtool button for the addition of the separator 2019-09-28 18:13:44 -07:00
Thomas Goyne 5da48d0f30 Don't call Realize() before setting the toolbar 2019-09-28 18:13:44 -07:00
Thomas Goyne 6ca879938d Always feed the entire file into uchardet when detection is needed
uchardet will report that a file is "ascii" if the first page has no bytes
>127, so we need to actually look at the entire file in case the first higher
byte is later in the file.
2019-09-28 18:13:44 -07:00
Thomas Goyne 8d17a0e88a Assume that files which start with a unicode BOM are valid files of that type 2019-09-28 18:13:44 -07:00
9 changed files with 47 additions and 31 deletions

View File

@ -29,20 +29,28 @@ namespace agi { namespace charset {
std::string Detect(agi::fs::path const& file) {
agi::read_file_mapping fp(file);
// First check for known magic bytes which identify the file type
if (fp.size() >= 4) {
const char* header = fp.read(0, 4);
if (!strncmp(header, "\xef\xbb\xbf", 3))
return "utf-8";
if (!strncmp(header, "\x00\x00\xfe\xff", 4))
return "utf-32be";
if (!strncmp(header, "\xff\xfe\x00\x00", 4))
return "utf-32le";
if (!strncmp(header, "\xfe\xff", 2))
return "utf-16be";
if (!strncmp(header, "\xff\xfe", 2))
return "utf-16le";
if (!strncmp(header, "\x1a\x45\xdf\xa3", 4))
return "binary"; // Actually EBML/Matroska
}
// If it's over 100 MB it's either binary or big enough that we won't
// be able to do anything useful with it anyway
if (fp.size() > 100 * 1024 * 1024)
return "binary";
// FIXME: Dirty hack for Matroska. These 4 bytes are the magic
// number of EBML which is used by mkv and webm
if (fp.size() >= 4) {
const char* buf = fp.read(0, 4);
if (!strncmp(buf, "\x1a\x45\xdf\xa3", 4))
return "binary";
}
uint64_t binaryish = 0;
#ifdef WITH_UCHARDET
@ -51,9 +59,6 @@ std::string Detect(agi::fs::path const& file) {
auto read = std::min<uint64_t>(4096, fp.size() - offset);
auto buf = fp.read(offset, read);
uchardet_handle_data(ud, buf, read);
uchardet_data_end(ud);
if (*uchardet_get_charset(ud))
return uchardet_get_charset(ud);
offset += read;
@ -66,6 +71,7 @@ std::string Detect(agi::fs::path const& file) {
if (binaryish > offset / 8)
return "binary";
}
uchardet_data_end(ud);
return uchardet_get_charset(ud);
#else
auto read = std::min<uint64_t>(4096, fp.size());

View File

@ -34,12 +34,12 @@ namespace agi { struct Context; }
#define STR_HELP(a) wxString StrHelp() const override { return _(a); }
#define CMD_TYPE(a) int Type() const override { using namespace cmd; return a; }
#define CMD_ICON(icon) wxBitmap Icon(int size, wxLayoutDirection dir = wxLayout_LeftToRight) const override { \
if (size == 64) return GETIMAGEDIR(icon##_64, dir); \
if (size == 48) return GETIMAGEDIR(icon##_48, dir); \
if (size == 32) return GETIMAGEDIR(icon##_32, dir); \
if (size == 24) return GETIMAGEDIR(icon##_24, dir); \
return GETIMAGEDIR(icon##_16, dir); \
#define CMD_ICON(icon) wxBitmap Icon(int size, double scale = 1.0, wxLayoutDirection dir = wxLayout_LeftToRight) const override { \
if (size * scale >= 64) return GETIMAGEDIR(icon##_64, scale, dir); \
if (size * scale >= 48) return GETIMAGEDIR(icon##_48, scale, dir); \
if (size * scale >= 32) return GETIMAGEDIR(icon##_32, scale, dir); \
if (size * scale >= 24) return GETIMAGEDIR(icon##_24, scale, dir); \
return GETIMAGEDIR(icon##_16, scale, dir); \
}
#define COMMAND_GROUP(cname, cmdname, menu, disp, help) \
@ -107,7 +107,7 @@ DEFINE_EXCEPTION(CommandNotFound, CommandError);
/// Request icon.
/// @param size Icon size.
virtual wxBitmap Icon(int size, wxLayoutDirection = wxLayout_LeftToRight) const { return wxBitmap{}; }
virtual wxBitmap Icon(int size, double scale = 1.0, wxLayoutDirection = wxLayout_LeftToRight) const { return wxBitmap{}; }
/// Command function
virtual void operator()(agi::Context *c)=0;

View File

@ -20,11 +20,11 @@
#include <wx/intl.h>
#include <wx/mstream.h>
wxBitmap libresrc_getimage(const unsigned char *buff, size_t size, int dir) {
wxBitmap libresrc_getimage(const unsigned char *buff, size_t size, double scale, int dir) {
wxMemoryInputStream mem(buff, size);
if (dir != wxLayout_RightToLeft)
return wxBitmap(wxImage(mem));
return wxBitmap(wxImage(mem).Mirror());
return wxBitmap(wxImage(mem), -1, scale);
return wxBitmap(wxImage(mem).Mirror(), -1, scale);
}
wxIcon libresrc_geticon(const unsigned char *buff, size_t size) {

View File

@ -21,10 +21,10 @@
class wxBitmap;
class wxIcon;
wxBitmap libresrc_getimage(const unsigned char *image, size_t size, int dir=0);
wxBitmap libresrc_getimage(const unsigned char *image, size_t size, double scale=1.0, int dir=0);
wxIcon libresrc_geticon(const unsigned char *image, size_t size);
#define GETIMAGE(a) libresrc_getimage(a, sizeof(a))
#define GETIMAGEDIR(a, d) libresrc_getimage(a, sizeof(a), d)
#define GETIMAGEDIR(a, s, d) libresrc_getimage(a, sizeof(a), s, d)
#define GETICON(a) libresrc_geticon(a, sizeof(a))
#define GET_DEFAULT_CONFIG(a) std::make_pair(reinterpret_cast<const char *>(a), sizeof(a))

View File

@ -45,8 +45,9 @@
#include "include/aegisub/hotkey.h"
#include "initial_line_state.h"
#include "options.h"
#include "project.h"
#include "placeholder_ctrl.h"
#include "project.h"
#include "retina_helper.h"
#include "selection_controller.h"
#include "subs_edit_ctrl.h"
#include "text_selection_controller.h"
@ -56,6 +57,7 @@
#include "validators.h"
#include <libaegisub/character_count.h>
#include <libaegisub/make_unique.h>
#include <libaegisub/util.h>
#include <functional>
@ -105,6 +107,7 @@ const auto AssDialogue_Effect = &AssDialogue::Effect;
SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxRAISED_BORDER, "SubsEditBox")
, c(context)
, retina_helper(agi::make_unique<RetinaHelper>(parent))
, undo_timer(GetEventHandler())
{
using std::bind;
@ -273,7 +276,7 @@ TimeEdit *SubsEditBox::MakeTimeCtrl(wxString const& tooltip, TimeField field) {
void SubsEditBox::MakeButton(const char *cmd_name) {
cmd::Command *command = cmd::get(cmd_name);
wxBitmapButton *btn = new wxBitmapButton(this, -1, command->Icon(16));
wxBitmapButton *btn = new wxBitmapButton(this, -1, command->Icon(16, retina_helper->GetScaleFactor()));
ToolTipManager::Bind(btn, command->StrHelp(), "Subtitle Edit Box", cmd_name);
middle_right_sizer->Add(btn, wxSizerFlags().Expand());

View File

@ -43,6 +43,7 @@ namespace agi { struct Context; }
namespace agi { class Time; }
class AssDialogue;
class AssStyle;
class RetinaHelper;
class SubsTextEditCtrl;
class TimeEdit;
class wxButton;
@ -103,6 +104,8 @@ class SubsEditBox final : public wxPanel {
wxSizer *middle_left_sizer;
wxSizer *bottom_sizer;
std::unique_ptr<RetinaHelper> retina_helper;
void SetControlsState(bool state);
/// @brief Update times of selected lines
/// @param field Field which changed

View File

@ -68,6 +68,9 @@ namespace {
/// Listener for icon size change signal
agi::signal::Connection icon_size_slot;
/// Listener for scale factor change signal
agi::signal::Connection scale_factor_slot;
/// Listener for hotkey change signal
agi::signal::Connection hotkeys_changed_slot;
@ -139,7 +142,7 @@ namespace {
flags & cmd::COMMAND_TOGGLE ? wxITEM_CHECK :
wxITEM_NORMAL;
wxBitmap const& bitmap = command->Icon(icon_size, GetLayoutDirection());
wxBitmap const& bitmap = command->Icon(icon_size, retina_helper.GetScaleFactor(), GetLayoutDirection());
AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, GetTooltip(command), kind);
commands.push_back(command);
@ -173,6 +176,9 @@ namespace {
, retina_helper(parent)
, icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt())
, icon_size_slot(OPT_SUB("App/Toolbar Icon Size", &Toolbar::OnIconSizeChange, this))
, scale_factor_slot(retina_helper.AddScaleFactorListener([=](double scale) {
RegenerateToolbar();
}))
, hotkeys_changed_slot(hotkey::inst->AddHotkeyChangeListener(&Toolbar::RegenerateToolbar, this))
{
Populate();
@ -189,9 +195,8 @@ namespace {
, icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt())
, icon_size_slot(OPT_SUB("App/Toolbar Icon Size", &Toolbar::OnIconSizeChange, this))
#else
, icon_size(32 * retina_helper.GetScaleFactor())
, icon_size(32)
, icon_size_slot(retina_helper.AddScaleFactorListener([=](double scale) {
icon_size = 32 * retina_helper.GetScaleFactor();
RegenerateToolbar();
}))
#endif

View File

@ -416,7 +416,6 @@ void VideoDisplay::SetTool(std::unique_ptr<VisualToolBase> new_tool) {
toolBar->Show(false);
toolBar->ClearTools();
toolBar->AddSeparator();
toolBar->Realize();
tool->SetToolbar(toolBar);
// Update size as the new typesetting tool may have changed the subtoolbar size

View File

@ -71,7 +71,7 @@ void VisualToolDrag::UpdateToggleButtons() {
if (to_move == button_is_move) return;
toolbar->SetToolNormalBitmap(toolbar->GetToolByPos(0)->GetId(),
toolbar->SetToolNormalBitmap(toolbar->GetToolByPos(1)->GetId(),
to_move ? ICON(visual_move_conv_move) : ICON(visual_move_conv_pos));
button_is_move = to_move;
}