Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed May 31, 2020
2 parents b60415d + 4982be1 commit fd52faf
Show file tree
Hide file tree
Showing 50 changed files with 2,819 additions and 659 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 1.1.0 - 2020-05-31
* Export subset of font characters (only the characters that you really
need in the font) - helps to reduce font size when you only use a bunch
of characters and not the whole ASCII table
* Exported source code is wrapped at around 80 columns
* Added pseudocode in the generated source code, explaining how to retrieve
individual font glyphs
* More user-friendly Undo/Redo functionality
* Added checking for updates on-demand from the menu and automatically
at start-up (the latter can be disabled)


## 1.0.0 - 2020-03-20
* First public release
* Importing system fonts
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.9)
project(FontEdit)

set(CMAKE_PROJECT_VERSION_MAJOR 1)
set(CMAKE_PROJECT_VERSION_MINOR 0)
set(CMAKE_PROJECT_VERSION_MINOR 1)
set(CMAKE_PROJECT_VERSION_PATCH 0)

set(APP_VERSION 1.0.0)
set(APP_BUILD 3)
set(APP_VERSION 1.1.0)
set(APP_BUILD 4)
set(APP_YEAR 2020)

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -49,7 +49,7 @@ elseif (WIN32)
endif ()


set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION "1.1.0")
set(CPACK_PACKAGE_CONTACT "dominik@kapusta.cc")
set(CPACK_PROJECT_HOMEPAGE_URL "https://kapusta.cc")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
Expand Down
10 changes: 8 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)
find_package(Qt5LinguistTools)

add_subdirectory(utf8)
Expand All @@ -39,13 +39,16 @@ set(SRC_FILES
mainwindowmodel.h
qfontfacereader.cpp
qfontfacereader.h
semver.hpp
sourcecoderunnable.cpp
sourcecoderunnable.h
updatehelper.cpp
updatehelper.h
)

add_library(appbundle ${SRC_FILES})
target_include_directories(appbundle PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} utf8 common ui)
target_link_libraries(appbundle PUBLIC Qt5::Widgets Qt5::Core common ui font2bytes GSL)
target_link_libraries(appbundle PUBLIC Qt5::Widgets Qt5::Core Qt5::Network common ui font2bytes GSL)

if (APPLE)
message(STATUS "Building MacOS X Bundle")
Expand All @@ -61,11 +64,14 @@ if (APPLE)
file(MAKE_DIRECTORY ${RESOURCES_DIR})
file(COPY ${PROJECT_SOURCE_DIR}/macos/fontedit.icns DESTINATION ${RESOURCES_DIR})
elseif(WIN32)
set(OPENSSL_ROOT_DIR "${Qt5_DIR}/../../../../Tools/OpenSSL/Win_x64" CACHE STRING "OpenSSL dir")
include(FindOpenSSL)
add_executable(${PROJECT_NAME} WIN32
main.cpp
assets.qrc
win/fontedit.rc
)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
else()
add_executable(${PROJECT_NAME}
main.cpp
Expand Down
13 changes: 7 additions & 6 deletions app/addglyphdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ AddGlyphDialog::AddGlyphDialog(const FontFaceViewModel& faceViewModel, QWidget *
ui_->faceGraphicsView->setScene(faceScene_.get());
ui_->faceGraphicsView->scene()->addItem(faceWidget_);

faceWidget_->load(faceViewModel.face(), Font::Margins {});
faceWidget_->load(faceViewModel.face(), f2b::font::margins {});
connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged, ui_->copyRadio, &QRadioButton::click);
connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged, [&, faceViewModel](std::size_t index) {
newGlyph_ = faceViewModel.face().glyph_at(index);
connect(faceWidget_, &FaceWidget::currentGlyphIndexChanged, [&, faceViewModel](std::optional<std::size_t> index) {
if (index.has_value())
newGlyph_ = faceViewModel.face().glyph_at(index.value());
});
connect(ui_->buttonBox, &QDialogButtonBox::accepted, [&, faceViewModel] {
if (ui_->emptyRadio->isChecked()) {
newGlyph_ = Font::Glyph { faceViewModel.face().glyph_size() };
newGlyph_ = f2b::font::glyph { faceViewModel.face().glyphs_size() };
} else if (ui_->characterRadio->isChecked()) {
QFontFaceReader adapter {
faceViewModel.font().value(),
ui_->characterLineEdit->text().toStdString(),
faceViewModel.face().glyph_size()
faceViewModel.face().glyphs_size()
};
newGlyph_ = Font::Face(adapter).glyph_at(0);
newGlyph_ = f2b::font::face(adapter).glyph_at(0);
}
emit glyphSelected(newGlyph_);
});
Expand Down
4 changes: 2 additions & 2 deletions app/addglyphdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class AddGlyphDialog : public QDialog
~AddGlyphDialog();

signals:
void glyphSelected(const std::optional<Font::Glyph>& glyph);
void glyphSelected(const std::optional<f2b::font::glyph>& glyph);

private:
Ui::AddGlyphDialog *ui_;
FaceWidget *faceWidget_ { nullptr };
std::unique_ptr<QGraphicsScene> faceScene_ { std::make_unique<QGraphicsScene>() };

std::optional<Font::Glyph> newGlyph_ {};
std::optional<f2b::font::glyph> newGlyph_ {};
};

#endif // ADDGLYPHDIALOG_H
59 changes: 58 additions & 1 deletion app/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define COMMAND_H

#include <QUndoCommand>
#include "facewidget.h"
#include "mainwindowmodel.h"

class Command : public QUndoCommand
{
Expand All @@ -18,9 +20,64 @@ class Command : public QUndoCommand
void undo() override { undo_(); }
void redo() override { redo_(); }

private:
int id() const override { return -1; }

protected:
std::function<void()> undo_;
std::function<void()> redo_;
};


class SwitchActiveGlyphCommand : public QUndoCommand
{
public:
SwitchActiveGlyphCommand(FaceWidget* faceWidget,
MainWindowModel* viewModel,
std::size_t fromIndex,
std::size_t toIndex,
QUndoCommand *parent = nullptr) :
QUndoCommand(QObject::tr("Switch Active Glyph"), parent),
faceWidget_ { faceWidget },
viewModel_ { viewModel },
fromIndex_ { fromIndex },
toIndex_ { toIndex }
{}

void undo() override {
faceWidget_->setCurrentGlyphIndex(fromIndex_);
viewModel_->setActiveGlyphIndex(fromIndex_);
}

void redo() override {
faceWidget_->setCurrentGlyphIndex(toIndex_);
viewModel_->setActiveGlyphIndex(toIndex_);
}

bool isObsolete() const {
return fromIndex_ == toIndex_;
}

int id() const override { return 0xa5b939e9; }

bool mergeWith(const QUndoCommand *other) override {
if (other->id() != id())
return false;

auto otherCommand = static_cast<const SwitchActiveGlyphCommand *>(other);

toIndex_ = otherCommand->toIndex_;
return true;
}

void setToIndex(std::size_t index) {
toIndex_ = index;
}

private:
FaceWidget* faceWidget_;
MainWindowModel* viewModel_;
std::size_t fromIndex_;
std::size_t toIndex_;
};

#endif // COMMAND_H
6 changes: 5 additions & 1 deletion app/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

namespace Color {

static constexpr QRgb glyphMargin = 0xe2e2e2;
static constexpr QRgb activeGlyph = 0xff000000;
static constexpr QRgb inactiveGlyph = 0xffe2e2e2;
static constexpr QRgb glyphMargin = 0xffe2e2e2;

static constexpr QRgb inactiveText = 0xffc8c8c8;

}

Expand Down
49 changes: 30 additions & 19 deletions app/common/f2b_qt_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ static constexpr quint32 font_glyph_magic_number = 0x92588c12;
static constexpr quint32 font_face_magic_number = 0x03f59a82;

static constexpr quint32 font_glyph_version = 1;
static constexpr quint32 font_face_version = 1;
static constexpr quint32 font_face_version = 2;

QDataStream& operator<<(QDataStream& s, const Font::Glyph& glyph)
using namespace f2b;

QDataStream& operator<<(QDataStream& s, const font::glyph& glyph)
{
s << font_glyph_magic_number;
s << font_glyph_version;
Expand All @@ -18,7 +20,7 @@ QDataStream& operator<<(QDataStream& s, const Font::Glyph& glyph)
return s;
}

QDataStream& operator>>(QDataStream& s, Font::Glyph& glyph)
QDataStream& operator>>(QDataStream& s, font::glyph& glyph)
{
quint32 magic_number;
quint32 version;
Expand All @@ -32,62 +34,71 @@ QDataStream& operator>>(QDataStream& s, Font::Glyph& glyph)
pixels.reserve(width * height);
s >> pixels;

glyph = Font::Glyph({width, height}, pixels);
glyph = font::glyph({width, height}, pixels);
}

return s;
}

QDataStream& operator<<(QDataStream& s, const Font::Face& face)
QDataStream& operator<<(QDataStream& s, const font::face& face)
{
s << font_face_magic_number;
s << font_face_version;
s.setVersion(QDataStream::Qt_5_7);
s << (quint32) face.glyph_size().width;
s << (quint32) face.glyph_size().height;
s << (quint32) face.glyphs_size().width;
s << (quint32) face.glyphs_size().height;
s << face.glyphs();
s << face.exported_glyph_ids();

return s;

}

QDataStream& operator>>(QDataStream& s, Font::Face& face)
QDataStream& operator>>(QDataStream& s, font::face& face)
{
quint32 magic_number;
quint32 version;
s >> magic_number >> version;
if (magic_number == font_face_magic_number && version == font_face_version) {
if (magic_number == font_face_magic_number) {
s.setVersion(QDataStream::Qt_5_7);
quint32 width, height;
s >> width >> height;

std::vector<Font::Glyph> glyphs;
std::vector<font::glyph> glyphs;
s >> glyphs;

face = Font::Face({width, height}, glyphs);
std::set<std::size_t> exported_glyph_ids;
if (version < 2) {
for (std::size_t i = 0; i < glyphs.size(); i++) {
exported_glyph_ids.insert(i);
}
} else {
s >> exported_glyph_ids;
}
face = font::face({width, height}, glyphs, exported_glyph_ids);
}

return s;
}

QVariant to_qvariant(const SourceCode::Indentation& i) {
if (std::holds_alternative<SourceCode::Tab>(i)) {
QVariant to_qvariant(const source_code::indentation& i) {
if (std::holds_alternative<source_code::tab>(i)) {
return QVariant(-1);
} else if (std::holds_alternative<SourceCode::Space>(i)) {
return QVariant((uint)std::get<SourceCode::Space>(i).num_spaces);
} else if (std::holds_alternative<source_code::space>(i)) {
return QVariant((uint)std::get<source_code::space>(i).num_spaces);
}
return QVariant();
}

SourceCode::Indentation from_qvariant(const QVariant& v) {
source_code::indentation from_qvariant(const QVariant& v) {
bool ok;
auto intValue = v.toInt(&ok);
if (ok && intValue == -1) {
return SourceCode::Tab {};
return source_code::tab {};
}
auto uintValue = v.toUInt(&ok);
if (ok) {
return SourceCode::Space { uintValue };
return source_code::space { uintValue };
}
return SourceCode::Tab {};
return source_code::tab {};
}
Loading

0 comments on commit fd52faf

Please sign in to comment.