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(sample-gui)
add_subdirectory(notes_tk)
add_subdirectory(website-generator)
# Experimental Below
if(WIN32)
add_subdirectory(directx-practice)
endif()
# Sample Console
add_executable(sample_console console-main.cpp)
target_link_libraries(sample_console PUBLIC console core network
database geometry audio web)
add_executable(notes_tk_console main.cpp)
target_link_libraries(notes_tk_console PUBLIC console core network 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})
list(APPEND client_HEADERS
MediaTool.h
NotesTk.h
text_editor/TextEditorView.h
text_editor/TextEditorModel.h
text_editor/TextEditorController.h
@ -33,15 +33,15 @@ list(APPEND client_LIB_INCLUDES
canvas/CanvasView.cpp
canvas/CanvasController.cpp
web_client/WebClientView.cpp
MediaTool.cpp)
NotesTk.cpp)
set(DEPENDENCIES_FOUND True)
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()
find_package(X11 QUIET)
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()
message(STATUS "X11 not found - skipping")
set(DEPENDENCIES_FOUND FALSE)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -29,9 +29,9 @@ IFontEngine* FontsManager::getFontEngine() const
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);

View file

@ -15,12 +15,12 @@ public:
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:
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>;

View file

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

View file

@ -19,7 +19,7 @@ public:
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:
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 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/type_ptr.hpp>
#include <iostream>
OpenGlTextPainter::OpenGlTextPainter()
{
@ -118,7 +116,7 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
auto texture = mFontTextures[c].get();
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 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 + h, 1.0f, 0.0f }
};
glBindTexture(GL_TEXTURE_2D, texture->getHandle());
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
@ -140,12 +137,11 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context)
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;
}
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
}

View file

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

View file

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

View file

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