Clean text rendering in editor.

This commit is contained in:
James Grogan 2022-12-02 11:50:15 +00:00
parent 290b64e230
commit f16dd7c0d9
45 changed files with 59 additions and 60 deletions

View file

@ -1,17 +1,14 @@
# Sample GUI add_subdirectory(notes_tk)
add_subdirectory(website-generator)
add_subdirectory(sample-gui)
# Experimental Below
if(WIN32) if(WIN32)
add_subdirectory(directx-practice) add_subdirectory(directx-practice)
endif() endif()
# Sample Console # Sample Console
add_executable(sample_console console-main.cpp) add_executable(notes_tk_console main.cpp)
target_link_libraries(sample_console PUBLIC console core network target_link_libraries(notes_tk_console PUBLIC console core network database geometry audio web)
database geometry audio web) set_property(TARGET notes_tk_console PROPERTY FOLDER apps)
set_property(TARGET sample_console PROPERTY FOLDER apps)
add_subdirectory(website-generator)

View file

@ -1,9 +1,9 @@
set(APP_NAME sample_gui) set(APP_NAME notes_tk)
message(STATUS "Checking dependencies for app: " ${APP_NAME}) message(STATUS "Checking dependencies for app: " ${APP_NAME})
list(APPEND client_HEADERS list(APPEND client_HEADERS
MediaTool.h NotesTk.h
text_editor/TextEditorView.h text_editor/TextEditorView.h
text_editor/TextEditorModel.h text_editor/TextEditorModel.h
text_editor/TextEditorController.h text_editor/TextEditorController.h
@ -33,15 +33,15 @@ list(APPEND client_LIB_INCLUDES
canvas/CanvasView.cpp canvas/CanvasView.cpp
canvas/CanvasController.cpp canvas/CanvasController.cpp
web_client/WebClientView.cpp web_client/WebClientView.cpp
MediaTool.cpp) NotesTk.cpp)
set(DEPENDENCIES_FOUND True) set(DEPENDENCIES_FOUND True)
if(WIN32) if(WIN32)
add_executable(${APP_NAME} WIN32 gui-main-win.cpp ${client_LIB_INCLUDES}) add_executable(${APP_NAME} WIN32 main-win.cpp ${client_LIB_INCLUDES})
else() else()
find_package(X11 QUIET) find_package(X11 QUIET)
if(X11_FOUND) if(X11_FOUND)
add_executable(${APP_NAME} gui-main.cpp ${client_LIB_INCLUDES} ${client_HEADERS}) add_executable(${APP_NAME} main.cpp ${client_LIB_INCLUDES} ${client_HEADERS})
else() else()
message(STATUS "X11 not found - skipping") message(STATUS "X11 not found - skipping")
set(DEPENDENCIES_FOUND FALSE) set(DEPENDENCIES_FOUND FALSE)

View file

@ -1,4 +1,4 @@
#include "MediaTool.h" #include "NotesTk.h"
#include "TextEditorView.h" #include "TextEditorView.h"
#include "AudioEditorView.h" #include "AudioEditorView.h"
@ -16,17 +16,17 @@
#include "DesktopManager.h" #include "DesktopManager.h"
#include "MainApplication.h" #include "MainApplication.h"
MediaTool::MediaTool(std::unique_ptr<CommandLineArgs> args) NotesTk::NotesTk(std::unique_ptr<CommandLineArgs> args)
: GuiApplication(std::move(args)) : GuiApplication(std::move(args))
{ {
} }
void MediaTool::initializeViews() void NotesTk::initializeViews()
{ {
auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow(); auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow();
mainWindow->setSize(800, 600); mainWindow->setSize(800, 600);
mainWindow->setTitle("Media Tool"); mainWindow->setTitle("NotesTK");
auto tabbedPanel = TabbedPanelWidget::Create(); auto tabbedPanel = TabbedPanelWidget::Create();
@ -41,7 +41,7 @@ void MediaTool::initializeViews()
auto audioEditor = AudioEditorView::Create(); auto audioEditor = AudioEditorView::Create();
audioEditor->setName("audioEditor"); audioEditor->setName("audioEditor");
tabbedPanel->addPanel(std::move(audioEditor), "audio Editor"); tabbedPanel->addPanel(std::move(audioEditor), "Audio Editor");
auto imageEditor = ImageEditorView::Create(); auto imageEditor = ImageEditorView::Create();
imageEditor->setName("imageEditor"); imageEditor->setName("imageEditor");
@ -60,12 +60,12 @@ void MediaTool::initializeViews()
tabbedPanel->addPanel(std::move(mesh), "Mesh Viewer"); tabbedPanel->addPanel(std::move(mesh), "Mesh Viewer");
auto topBar = TopBar::Create(); auto topBar = TopBar::Create();
auto statusBar = StatusBar::Create(); //auto statusBar = StatusBar::Create();
auto horizontal_spacer = HorizontalSpacer::Create(); auto horizontal_spacer = HorizontalSpacer::Create();
horizontal_spacer->addWidgetWithScale(std::move(topBar), 1); horizontal_spacer->addWidgetWithScale(std::move(topBar), 1);
horizontal_spacer->addWidgetWithScale(std::move(tabbedPanel), 20); horizontal_spacer->addWidgetWithScale(std::move(tabbedPanel), 20);
horizontal_spacer->addWidgetWithScale(std::move(statusBar), 1); //horizontal_spacer->addWidgetWithScale(std::move(statusBar), 1);
mainWindow->setWidget(std::move(horizontal_spacer)); mainWindow->setWidget(std::move(horizontal_spacer));
} }

View file

@ -2,10 +2,10 @@
#include "GuiApplication.h" #include "GuiApplication.h"
class MediaTool : public GuiApplication class NotesTk : public GuiApplication
{ {
public: public:
MediaTool(std::unique_ptr<CommandLineArgs> args); NotesTk(std::unique_ptr<CommandLineArgs> args);
protected: protected:
void initializeViews() override; void initializeViews() override;

View file

@ -16,7 +16,6 @@
CanvasView::CanvasView() CanvasView::CanvasView()
: mController(CanvasController::Create()) : mController(CanvasController::Create())
{ {
std::cout << "Creatin canvas" << std::endl;
initialize(); initialize();
} }

View file

@ -7,7 +7,6 @@
ImageViewWidget::ImageViewWidget() ImageViewWidget::ImageViewWidget()
{ {
std::cout << "Creating image view widget" << std::endl;
mName = "ImageViewWidget"; mName = "ImageViewWidget";
} }

View file

@ -1,6 +1,6 @@
#include <memory> #include <memory>
#include "MediaTool.h" #include "NotesTk.h"
#include "MainApplication.h" #include "MainApplication.h"
#include "CommandLineArgs.h" #include "CommandLineArgs.h"
@ -11,7 +11,7 @@ int main(int argc, char *argv[])
args->recordLaunchPath(); args->recordLaunchPath();
// Start the gui app // Start the gui app
auto app = MediaTool(std::move(args)); auto app = NotesTk(std::move(args));
//app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER); //app.setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
app.run(); app.run();

View file

@ -1,7 +1,7 @@
#include "FontGlyph.h" #include "FontGlyph.h"
FontGlyph::FontGlyph(unsigned width, unsigned height, unsigned bearingX, unsigned bearingY, FontGlyph::FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY,
unsigned advanceX, std::unique_ptr<Image<unsigned char> > image) int advanceX, std::unique_ptr<Image<unsigned char> > image)
: mImage(std::move(image)), : mImage(std::move(image)),
mWidth(width), mWidth(width),
mHeight(height), mHeight(height),
@ -27,17 +27,17 @@ unsigned FontGlyph::getHeight() const
return mHeight; return mHeight;
} }
unsigned FontGlyph::getBearingX() const int FontGlyph::getBearingX() const
{ {
return mBearingX; return mBearingX;
} }
unsigned FontGlyph::getBearingY() const int FontGlyph::getBearingY() const
{ {
return mBearingY; return mBearingY;
} }
unsigned FontGlyph::getAdvanceX() const int FontGlyph::getAdvanceX() const
{ {
return mAdvanceX; return mAdvanceX;
} }

View file

@ -8,22 +8,22 @@ class FontGlyph
{ {
public: public:
FontGlyph(unsigned width, unsigned height, unsigned bearingX, unsigned bearingY, FontGlyph(unsigned width, unsigned height, int bearingX, int bearingY,
unsigned advanceX, std::unique_ptr<Image<unsigned char> > image); int advanceX, std::unique_ptr<Image<unsigned char> > image);
Image<unsigned char>* getImage() const; Image<unsigned char>* getImage() const;
unsigned getWidth() const; unsigned getWidth() const;
unsigned getHeight() const; unsigned getHeight() const;
unsigned getBearingX() const; int getBearingX() const;
unsigned getBearingY() const; int getBearingY() const;
unsigned getAdvanceX() const; int getAdvanceX() const;
private: private:
unsigned mWidth{0}; unsigned mWidth{0};
unsigned mHeight{0}; unsigned mHeight{0};
unsigned mBearingX{0}; int mBearingX{0};
unsigned mBearingY{0}; int mBearingY{0};
unsigned mAdvanceX{0}; int mAdvanceX{0};
std::unique_ptr<Image<unsigned char> > mImage; std::unique_ptr<Image<unsigned char> > mImage;
}; };

View file

@ -50,7 +50,7 @@ public:
} }
private: private:
unsigned mSize{16}; unsigned mSize{24};
std::string mFaceName; std::string mFaceName;
std::filesystem::path mPath; std::filesystem::path mPath;
}; };

View file

@ -29,9 +29,9 @@ IFontEngine* FontsManager::getFontEngine() const
return mFontEngine.get(); return mFontEngine.get();
} }
FontGlyph* FontsManager::getGlyph(const std::string& fontFace, int size, char c) FontGlyph* FontsManager::getGlyph(const std::string& fontFace, int size, uint32_t c)
{ {
auto path = std::filesystem::path("truetype/msttcorefonts/arial.ttf"); auto path = std::filesystem::path("truetype/liberation/LiberationSans-Regular.ttf");
mFontEngine->loadFontFace(path, size); mFontEngine->loadFontFace(path, size);

View file

@ -15,12 +15,12 @@ public:
IFontEngine* getFontEngine() const; IFontEngine* getFontEngine() const;
FontGlyph* getGlyph(const std::string& fontFace, int size, char c); FontGlyph* getGlyph(const std::string& fontFace, int size, uint32_t c);
private: private:
std::unique_ptr<IFontEngine> mFontEngine; std::unique_ptr<IFontEngine> mFontEngine;
std::unordered_map<char, std::unique_ptr<FontGlyph> > mGlyphs; std::unordered_map<uint32_t, std::unique_ptr<FontGlyph> > mGlyphs;
}; };
using FontsManagerPtr = std::unique_ptr<FontsManager>; using FontsManagerPtr = std::unique_ptr<FontsManager>;

View file

@ -4,6 +4,8 @@
#include "FileLogger.h" #include "FileLogger.h"
#include "FontGlyph.h" #include "FontGlyph.h"
#include <iostream>
void FreeTypeFontEngine::initialize() void FreeTypeFontEngine::initialize()
{ {
if (mLibrary) if (mLibrary)
@ -43,7 +45,7 @@ void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, int
FT_Set_Pixel_Sizes(mWorkingFontFace, penSize, 0); FT_Set_Pixel_Sizes(mWorkingFontFace, penSize, 0);
} }
std::unique_ptr<FontGlyph> FreeTypeFontEngine::loadGlyph(unsigned charCode) std::unique_ptr<FontGlyph> FreeTypeFontEngine::loadGlyph(uint32_t charCode)
{ {
auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, charCode ); auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, charCode );
if (glyph_index == 0) if (glyph_index == 0)
@ -89,7 +91,6 @@ std::unique_ptr<FontGlyph> FreeTypeFontEngine::loadGlyph(unsigned charCode)
} }
} }
image->setData(data); image->setData(data);
auto glyph = std::make_unique<FontGlyph>(mWorkingFontFace->glyph->bitmap.width, auto glyph = std::make_unique<FontGlyph>(mWorkingFontFace->glyph->bitmap.width,
mWorkingFontFace->glyph->bitmap.rows, mWorkingFontFace->glyph->bitmap.rows,
mWorkingFontFace->glyph->bitmap_left, mWorkingFontFace->glyph->bitmap_left,

View file

@ -19,7 +19,7 @@ public:
void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override; void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override;
std::unique_ptr<FontGlyph> loadGlyph(unsigned charCode) override; std::unique_ptr<FontGlyph> loadGlyph(uint32_t charCode) override;
private: private:
std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"}; std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"};

View file

@ -15,5 +15,5 @@ public:
virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) = 0; virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) = 0;
virtual std::unique_ptr<FontGlyph> loadGlyph(unsigned charCode) = 0; virtual std::unique_ptr<FontGlyph> loadGlyph(uint32_t charCode) = 0;
}; };

View file

@ -27,8 +27,6 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include <iostream>
OpenGlTextPainter::OpenGlTextPainter() OpenGlTextPainter::OpenGlTextPainter()
{ {
@ -118,7 +116,7 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
auto texture = mFontTextures[c].get(); auto texture = mFontTextures[c].get();
float xpos = x + texture->getGlyph()->getBearingX(); float xpos = x + texture->getGlyph()->getBearingX();
float ypos = y - (texture->getGlyph()->getHeight() - texture->getGlyph()->getBearingY()); float ypos = y - (int(texture->getGlyph()->getHeight()) - texture->getGlyph()->getBearingY());
float w = texture->getGlyph()->getWidth(); float w = texture->getGlyph()->getWidth();
float h = texture->getGlyph()->getHeight(); float h = texture->getGlyph()->getHeight();
@ -131,7 +129,6 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
{ xpos + w, ypos, 1.0f, 1.0f }, { xpos + w, ypos, 1.0f, 1.0f },
{ xpos + w, ypos + h, 1.0f, 0.0f } { xpos + w, ypos + h, 1.0f, 0.0f }
}; };
glBindTexture(GL_TEXTURE_2D, texture->getHandle()); glBindTexture(GL_TEXTURE_2D, texture->getHandle());
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
@ -140,12 +137,11 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
x += (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64) auto offset = (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64)
x += offset;
} }
line_offset += line_delta; line_offset += line_delta;
} }
glBindVertexArray(0); glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }

View file

@ -42,8 +42,8 @@ PdfPage::PdfPage(PdfPageTree* parent)
std::string pageContent = "BT\n"; std::string pageContent = "BT\n";
pageContent += "/F1 24 Tf\n"; pageContent += "/F1 24 Tf\n";
pageContent += "100 100 Td\n"; pageContent += "100 700 Td\n";
pageContent += "(Hello World) Tj\n"; pageContent += "(Hello \nWorld) Tj\n";
pageContent += "ET"; pageContent += "ET";
mContent->setContent(pageContent); mContent->setContent(pageContent);

View file

@ -17,6 +17,5 @@ public:
void updateDictionary() override; void updateDictionary() override;
private: private:
PdfPagePtr mRootPage; PdfPagePtr mRootPage;
}; };

View file

@ -57,7 +57,15 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
else else
{ {
const auto keyString = event->getKeyString(); const auto keyString = event->getKeyString();
appendContent(keyString); if (keyString.length() < 2)
{
appendContent(keyString);
}
else
{
appendContent("?");
}
} }
return true; return true;
} }