Basic Font integration.

This commit is contained in:
James Grogan 2022-11-15 09:32:28 +00:00
parent ce11c52ae5
commit 72123bc333
36 changed files with 325 additions and 198 deletions

View file

@ -4,6 +4,7 @@
#include "Window.h"
#include "WindowManager.h"
#include "DesktopManager.h"
#include "FontsManager.h"
#include "MainApplication.h"
#include "AbstractUiInterface.h"

View file

@ -3,7 +3,6 @@
#include "MidiReader.h"
#include "File.h"
#include "DocumentConverter.h"
#include "DrawingManager.h"
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "Grid.h"
@ -97,12 +96,14 @@ void MainApplication::run()
}
else if(program_type == "-draw")
{
/*
auto drawing_manager = DrawingManager::Create();
drawing_manager->InitalizeSurface(400, 400);
auto text = TextNode::Create("Hello World", DiscretePoint(20, 20));
drawing_manager->AddText(text.get());
drawing_manager->RenderToFile("test.png");
*/
}
else
{

View file

@ -0,0 +1,14 @@
#pragma once
#include "IFontEngine.h"
#include "Image.h"
class BasicFontEngine : public IFontEngine
{
virtual void initialize(){};
virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16){};
virtual std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode){return nullptr;};
};

View file

@ -4,12 +4,13 @@ set(fonts_LIB_DEPENDS "")
list(APPEND fonts_LIB_INCLUDES
FontReader.cpp
TrueTypeFont.cpp
FontsManager.cpp
)
if(UNIX)
find_package(Freetype QUIET)
if(Freetype_FOUND)
list(APPEND font_LIB_INCLUDES
list(APPEND fonts_LIB_INCLUDES
FreeTypeFontEngine.cpp
)
@ -27,6 +28,6 @@ target_include_directories(fonts PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(fonts PUBLIC core ${fonts_LIB_DEPENDS})
target_link_libraries(fonts PUBLIC core image ${fonts_LIB_DEPENDS})
set_property(TARGET fonts PROPERTY FOLDER src)
set_target_properties( fonts PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )

View file

@ -0,0 +1,23 @@
#include "FontsManager.h"
#include "FreeTypeFontEngine.h"
#include "BasicFontEngine.h"
FontsManager::FontsManager()
: mFontEngine(std::make_unique<FreeTypeFontEngine>())
{
mFontEngine->initialize();
}
std::unique_ptr<FontsManager> FontsManager::Create()
{
return std::make_unique<FontsManager>();
}
IFontEngine* FontsManager::getFontEngine() const
{
return mFontEngine.get();
}

20
src/fonts/FontsManager.h Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include <memory>
#include <string>
class IFontEngine;
class FontsManager
{
public:
FontsManager();
static std::unique_ptr<FontsManager> Create();
IFontEngine* getFontEngine() const;
private:
std::unique_ptr<IFontEngine> mFontEngine;
};
using FontsManagerPtr = std::unique_ptr<FontsManager>;

View file

@ -0,0 +1,87 @@
#include "FreeTypeFontEngine.h"
#include "Image.h"
#include "FileLogger.h"
void FreeTypeFontEngine::initialize()
{
if (mLibrary)
{
return;
}
const auto error = FT_Init_FreeType(&mLibrary);
if (error)
{
MLOG_ERROR("Error initializing FreeType. Code " << static_cast<int>(error));
}
}
void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, int penSize)
{
if (!mLibrary)
{
initialize();
}
const auto full_path = mSystemFontLocation / fontFile;
const auto error = FT_New_Face(mLibrary, full_path.c_str(), 0, &mWorkingFontFace );
if ( error == FT_Err_Unknown_File_Format )
{
MLOG_ERROR("Found file but format not supported. Code " << static_cast<int>(error));
}
else if ( error )
{
MLOG_ERROR("Failed to find or open file. Code " << static_cast<int>(error));
}
FT_Set_Pixel_Sizes(mWorkingFontFace, penSize, 0);
}
std::unique_ptr<Image<unsigned char> > FreeTypeFontEngine::loadGlyph(unsigned charCode)
{
auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, 65 );
if (glyph_index == 0)
{
MLOG_ERROR("Got the null glyph");
return nullptr;
}
auto error = FT_Load_Glyph(mWorkingFontFace, glyph_index, FT_LOAD_DEFAULT );
if (error == FT_Err_Invalid_Argument)
{
MLOG_ERROR("Error loading glyph - bad arg. Code " << static_cast<int>(error));
return nullptr;
}
else if(error)
{
MLOG_ERROR("Error loading glyph. Code " << static_cast<int>(error));
return nullptr;
}
if (mWorkingFontFace->glyph->format != FT_GLYPH_FORMAT_BITMAP)
{
error = FT_Render_Glyph( mWorkingFontFace->glyph, FT_RENDER_MODE_NORMAL );
}
if (error)
{
MLOG_ERROR("Error rendering glyph. Code " << static_cast<int>(error));
return nullptr;
}
auto rows = mWorkingFontFace->glyph->bitmap.rows;
auto columns = mWorkingFontFace->glyph->bitmap.width;
auto image = std::make_unique<Image<unsigned char>> (columns, rows);
unsigned counter = 0;
std::vector<unsigned char> data(rows*columns, 0);
for (unsigned idx=0; idx<rows; idx++)
{
for (unsigned jdx=0; jdx<columns; jdx++)
{
data[counter] = mWorkingFontFace->glyph->bitmap.buffer[counter];
counter++;
}
}
image->setData(data);
return image;
}

View file

@ -4,8 +4,8 @@
#include "Image.h"
#include <iostream>
#include <filesystem>
template<typename T>
class Image;
#include <ft2build.h>
#include FT_FREETYPE_H
@ -15,86 +15,11 @@ class FreeTypeFontEngine : public IFontEngine
public:
FreeTypeFontEngine() = default;
void initialize()
{
if (mLibrary)
{
return;
}
void initialize() override;
const auto error = FT_Init_FreeType(&mLibrary);
if (error)
{
std::cout << "Error initializing FreeType" << std::endl;
}
}
void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override;
void loadFontFace(const std::filesystem::path& fontFile)
{
const auto full_path = mSystemFontLocation / fontFile;
const auto error = FT_New_Face(mLibrary, full_path.c_str(), 0, &mWorkingFontFace );
if ( error == FT_Err_Unknown_File_Format )
{
std::cout << "Found file but format not supported" << std::endl;
}
else if ( error )
{
std::cout << "Failed to find or open file" << std::endl;
}
int pensize = 16;
FT_Set_Pixel_Sizes(mWorkingFontFace, pensize, 0);
}
std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode)
{
auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, charCode );
if (glyph_index == 0)
{
std::cout << "Got the null glyph" << std::endl;
return nullptr;
}
auto error = FT_Load_Glyph(mWorkingFontFace, glyph_index, FT_LOAD_DEFAULT );
if (error == FT_Err_Invalid_Argument)
{
std::cout << "Error loading glyph - bad arg" << std::endl;
return nullptr;
}
else if(error)
{
auto code = static_cast<int>(error);
std::cout << "Error loading glyph - somethign else " << code << std::endl;
return nullptr;
}
if (mWorkingFontFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
{
std::cout << "It is bitmap format" << std::endl;
}
else
{
error = FT_Render_Glyph( mWorkingFontFace->glyph, FT_RENDER_MODE_NORMAL );
}
auto rows = mWorkingFontFace->glyph->bitmap.rows;
auto columns = mWorkingFontFace->glyph->bitmap.width;
std::cout << "We have a bitmap with rows " << rows << " and columns " << columns << std::endl;
auto image = std::make_unique<Image<unsigned char>> (columns, rows);
unsigned counter = 0;
std::vector<unsigned char> data(rows*columns);
for (unsigned idx=0; idx<rows; idx++)
{
for (unsigned jdx=0; jdx<columns; jdx++)
{
data[counter] = mWorkingFontFace->glyph->bitmap.buffer[counter];
}
}
image->setData(data);
return image;
}
std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode) override;
private:
std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"};

View file

@ -1,8 +1,20 @@
#pragma once
#include <memory>
#include <filesystem>
template<typename T>
class Image;
class IFontEngine
{
public:
IFontEngine() = default;
virtual ~IFontEngine() = default;
virtual void initialize(){};
virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) = 0;
virtual std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode) = 0;
};

View file

@ -5,7 +5,6 @@ set(platform_LIBS "")
list(APPEND graphics_LIB_INCLUDES
DrawingContext.cpp
DrawingManager.cpp
DrawingSurface.cpp
RasterPainter.cpp
${platform_LIB_INCLUDES}
@ -36,7 +35,7 @@ target_include_directories(graphics PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/opengl"
)
target_link_libraries(graphics PUBLIC visual_elements image ${platform_LIBS})
target_link_libraries(graphics PUBLIC geometry mesh fonts image visual_elements ${platform_LIBS})
set_property(TARGET graphics PROPERTY FOLDER src)
set_target_properties( graphics PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )

View file

@ -9,10 +9,11 @@
#include "DrawingSurface.h"
#include "Scene.h"
DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode)
DrawingContext::DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
: mSurface(surface),
mDrawingMode(requestedDrawingMode),
mScene(std::make_unique<Scene>())
mScene(std::make_unique<Scene>()),
mFontsManager(fontsManager)
{
if (mDrawingMode == DrawingMode::GRAPH)
{
@ -24,9 +25,9 @@ DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDra
}
}
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, DrawingMode requestedDrawingMode)
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
{
return std::make_unique<DrawingContext>(surface, requestedDrawingMode);
return std::make_unique<DrawingContext>(surface, fontsManager, requestedDrawingMode);
}
Scene* DrawingContext::getScene() const
@ -41,6 +42,6 @@ DrawingSurface* DrawingContext::getSurface() const
void DrawingContext::paint()
{
mScene->update(mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr);
mScene->update(mFontsManager, mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr);
mPainter->paint(this);
}

View file

@ -6,6 +6,7 @@
class Scene;
class AbstractPainter;
class DrawingSurface;
class FontsManager;
enum class DrawingMode
{
@ -16,9 +17,9 @@ enum class DrawingMode
class DrawingContext
{
public:
DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode);
DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, DrawingMode requestedDrawingMode);
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
Scene* getScene() const;
@ -28,7 +29,7 @@ public:
private:
DrawingMode mDrawingMode;
FontsManager* mFontsManager{nullptr};
DrawingSurface* mSurface{nullptr};
std::unique_ptr<Scene> mScene;
std::unique_ptr<AbstractPainter> mPainter;

View file

@ -1,49 +0,0 @@
#include "DrawingManager.h"
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "AbstractPainter.h"
#include "Grid.h"
#include "Image.h"
#include "TriMesh.h"
#include "Scene.h"
DrawingManager::DrawingManager()
{
}
std::unique_ptr<DrawingManager> DrawingManager::Create()
{
return std::make_unique<DrawingManager>();
}
void DrawingManager::InitalizeSurface(unsigned width, unsigned height)
{
mDrawingSurface = DrawingSurface::Create();
mDrawingSurface->setSize(width, height);
}
void DrawingManager::InitializeContext()
{
//mDrawingContext = DrawingContext::Create();
}
void DrawingManager::AddText(TextNode* text)
{
if (!mDrawingContext)
{
InitializeContext();
}
if (!mDrawingContext)
{
return;
}
}
void DrawingManager::RenderToFile(const std::string& path)
{
}

View file

@ -1,28 +0,0 @@
#pragma once
#include <memory>
#include <string>
class TextNode;
class DrawingSurface;
using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
class DrawingContext;
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
class DrawingManager
{
public:
DrawingManager();
static std::unique_ptr<DrawingManager> Create();
void InitalizeSurface(unsigned width, unsigned height);
void InitializeContext();
void AddText(TextNode* text);
void RenderToFile(const std::string& path);
private:
DrawingSurfacePtr mDrawingSurface {nullptr};
DrawingContextPtr mDrawingContext {nullptr};
};
using DrawingManagerPtr = std::unique_ptr<DrawingManager>;

View file

@ -9,7 +9,9 @@
#include "Scene.h"
#include "TriMesh.h"
#include "AbstractPainter.h"
#include "DrawingContext.h"
#include "FontsManager.h"
#include "IPlatformWindow.h"
#include "Screen.h"
@ -89,10 +91,10 @@ IPlatformWindow* Window::getPlatformWindow() const
return nullptr;
}
void Window::setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode)
void Window::setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode)
{
mPlatformWindow = std::move(window);
mDrawingContext = std::make_unique<DrawingContext>(this, drawingMode);
mDrawingContext = std::make_unique<DrawingContext>(this, fontsManager, drawingMode);
}
void Window::map()

View file

@ -11,7 +11,9 @@ class MouseEvent;
class KeyboardEvent;
class DrawingContext;
class FontsManager;
enum class DrawingMode;
class Widget;
using WidgetPtr = std::unique_ptr<Widget>;
class IPlatformWindow;
@ -43,7 +45,7 @@ public:
IPlatformWindow* getPlatformWindow() const;
void setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode);
void setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode);
void map();

View file

@ -3,8 +3,11 @@
#include "AbstractMesh.h"
#include "Image.h"
#include "DiscretePoint.h"
#include <memory>
class FontsManager;
class AbstractVisualNode
{
public:
@ -21,11 +24,21 @@ public:
return mMesh.get();
}
virtual void update(FontsManager* fontsManager)
{
}
virtual void updateMesh()
{
}
virtual void updateTexture(FontsManager* fontsManager)
{
}
Image<unsigned char>* getImage() const
{
return mImage.get();
@ -36,8 +49,14 @@ public:
return mLocation;
}
Image<unsigned char>* getTexture() const
{
return mTexture.get();
}
protected:
DiscretePoint mLocation;
std::unique_ptr<AbstractMesh> mMesh;
std::unique_ptr<Image<unsigned char> > mImage;
std::unique_ptr<Image<unsigned char> > mTexture;
};

View file

@ -12,7 +12,7 @@ target_include_directories(visual_elements PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(visual_elements PUBLIC core geometry mesh image)
target_link_libraries(visual_elements PUBLIC core geometry fonts mesh image)
set_property(TARGET visual_elements PROPERTY FOLDER src)

View file

@ -33,6 +33,11 @@ unsigned RectangleNode::getHeight() const
return mHeight;
}
void RectangleNode::update(FontsManager* fontsManager)
{
updateMesh();
}
void RectangleNode::updateMesh()
{
const auto rect = Rectangle(mLocation, mWidth, mHeight);

View file

@ -15,9 +15,10 @@ public:
unsigned getWidth() const;
unsigned getHeight() const;
void updateMesh() override;
void update(FontsManager* fontsManager) override;
private:
void updateMesh() override;
unsigned mWidth{1};
unsigned mHeight{1};
};

View file

@ -3,16 +3,19 @@
#include "VisualLayer.h"
#include "GeometryNode.h"
#include "RectangleNode.h"
#include "TextNode.h"
#include "MeshBuilder.h"
#include "TriMesh.h"
#include "Image.h"
void Scene::syncLayers(const std::vector<VisualLayer*>& layers)
{
mLayers = layers;
}
void Scene::update(Image<unsigned char>* image)
void Scene::update(FontsManager* fontsManager, Image<unsigned char>* image)
{
if (image)
{
@ -28,11 +31,23 @@ void Scene::update(Image<unsigned char>* image)
auto node = layer->getShapeNode();
if (layer->getIsDirty())
{
node->updateMesh();
node->update(fontsManager);
layer->setIsDirty(false);
}
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
mTextures.push_back(nullptr);
}
else
{
auto node = layer->getTextNode();
if (layer->getIsDirty())
{
node->update(fontsManager);
layer->setIsDirty(false);
}
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
mTextures.push_back(node->getTexture());
}
}
}

View file

@ -5,6 +5,7 @@
class VisualLayer;
class TriMesh;
class FontsManager;
class RectangleNode;
@ -18,16 +19,19 @@ public:
void syncLayers(const std::vector<VisualLayer*>& layers);
void update(Image<unsigned char>* image = nullptr);
void update(FontsManager* fontsManager, Image<unsigned char>* image = nullptr);
unsigned getNumMeshes() const;
TriMesh* getMesh(std::size_t idx) const;
Image<unsigned char>* getTexture(std::size_t idx) const;
private:
void processRectangleNode(RectangleNode* node);
std::vector<TriMesh*> mWorkingMeshs;
std::vector<VisualLayer*> mLayers;
std::vector<Image<unsigned char>* > mTextures;
};

View file

@ -1,5 +1,10 @@
#include "TextNode.h"
#include "Rectangle.h"
#include "FontsManager.h"
#include "IFontEngine.h"
#include "MeshPrimitives.h"
#include "Color.h"
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
@ -55,3 +60,39 @@ void TextNode::setStrokeColor(const Color& color)
{
mStrokeColor = color;
}
void TextNode::update(FontsManager* drawingManager)
{
updateMesh();
updateTexture(drawingManager);
}
void TextNode::updateMesh()
{
double font_height = 16;
double font_width = 16;
double text_width = mContent.size() * font_width;
const auto rect = Rectangle(mLocation, text_width, font_height);
auto mesh = MeshPrimitives::build(rect);
auto color = Color(0, 0, 0, 1.0);
mesh->addConstantFaceVectorAttribute("Color", color.getAsVectorDouble());
mMesh = std::move(mesh);
}
void TextNode::updateTexture(FontsManager* fontsManager)
{
fontsManager->getFontEngine()->loadFontFace("truetype/msttcorefonts/arial.ttf");
auto glyph = fontsManager->getFontEngine()->loadGlyph('A');
if (!glyph)
{
return;
}
mTexture = std::make_unique<Image<unsigned char> >(glyph->getWidth(), glyph->getHeight());
mTexture->setData(glyph->getData());
}

View file

@ -28,7 +28,12 @@ public:
void setFillColor(const Color& color);
void setStrokeColor(const Color& color);
void update(FontsManager* fontsManager) override;
private:
void updateMesh() override;
void updateTexture(FontsManager* fontsManager) override;
std::string mContent;
std::string mFontLabel;
Color mFillColor;

View file

@ -1,19 +1,25 @@
#pragma once
#include <memory>
#include "IFontEngine.h"
#include "FontsManager.h"
namespace mt
{
class Window;
}
class DesktopManager;
class FontsManager;
class AbstractUIInterface
{
public:
AbstractUIInterface(DesktopManager* desktopManager, bool useHardware = false)
AbstractUIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false)
: mDesktopManager(desktopManager),
mUseHardwareRendering(useHardware)
mUseHardwareRendering(useHardware),
mFontsManager(std::move(fontsManager))
{
}
@ -32,5 +38,7 @@ protected:
virtual void initializeHardwareRendering() {};
DesktopManager* mDesktopManager{nullptr};
std::unique_ptr<FontsManager> mFontsManager;
bool mUseHardwareRendering{false};
};

View file

@ -7,18 +7,22 @@
#include "Win32UiInterface.h"
#endif
#include "FontsManager.h"
std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
{
auto fonts_manager = std::make_unique<FontsManager>();
#ifdef __linux__
if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
{
const bool use_hardware = (backend != Backend::X11_RASTER);
return std::make_unique<XcbInterface>(desktopManager, use_hardware);
return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
}
else
{
const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
return std::make_unique<WaylandInterface>(desktopManager, use_hardware);
return std::make_unique<WaylandInterface>(desktopManager, std::move(fonts_manager), use_hardware);
}
#else
return std::make_unique<Win32UiInterface>();

View file

@ -3,6 +3,7 @@
#include "FileLogger.h"
#include "DesktopManager.h"
#include "WindowManager.h"
#include "FontsManager.h"
#include "WaylandSurface.h"
#include "WaylandBuffer.h"
@ -43,8 +44,8 @@ void WaylandInterface::registryHandleGlobalRemoveEvent(void *data, struct wl_reg
}
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
mBuffer(std::make_shared<WaylandBuffer>())
{
mRegistryListener.global = registryHandleGlobalEvent;
@ -129,7 +130,7 @@ void WaylandInterface::doXdgPong(uint32_t serial)
void WaylandInterface::addWindow(mt::Window* window)
{
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mEglInterface.get());
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mFontsManager.get(), mEglInterface.get());
}
void WaylandInterface::showWindow(mt::Window* window)

View file

@ -18,7 +18,7 @@ class WaylandInterface : public AbstractUIInterface
{
public:
WaylandInterface(DesktopManager* desktopManager, bool useHardware = true);
WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);
~WaylandInterface();

View file

@ -2,14 +2,16 @@
#include "WaylandEglWindowInterface.h"
#include "ImagePrimitives.h"
#include "DrawingContext.h"
void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
#include "DrawingContext.h"
#include "FontsManager.h"
void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, FontsManager* fontsManager, WaylandEglInterface* eglInterface)
{
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
const auto drawing_mode = eglInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
window->setPlatformWindow(std::move(wayland_window), drawing_mode);
window->setPlatformWindow(std::move(wayland_window), fontsManager, drawing_mode);
}
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)

View file

@ -16,11 +16,13 @@ struct xdg_toplevel;
class WaylandEglInterface;
class WaylandEglWindowInterface;
class FontsManager;
class WaylandSurface : public IPlatformWindow
{
public:
static void add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
static void add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, FontsManager* fontsManager, WaylandEglInterface* eglInterface);
WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);

View file

@ -18,12 +18,13 @@
#include "XcbEventInterface.h"
#include "XcbGlInterface.h"
#include "FileLogger.h"
#include "FontsManager.h"
#include <iostream>
XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
XcbInterface::XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
mEventInterface(XcbEventInterface::Create())
{
@ -151,7 +152,7 @@ uint32_t XcbInterface::getEventMask()
void XcbInterface::addWindow(mt::Window* window)
{
auto screen = mDesktopManager->getDefaultScreen();
XcbWindow::add(window, mConnection, screen, getEventMask(), mGlInterface.get());
XcbWindow::add(window, mConnection, screen, getEventMask(), mFontsManager.get(), mGlInterface.get());
}
void XcbInterface::onPaint()

View file

@ -25,7 +25,7 @@ namespace mt
class XcbInterface : public AbstractUIInterface
{
public:
XcbInterface(DesktopManager* desktopManager, bool useHardware = true);
XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);
~XcbInterface();

View file

@ -7,7 +7,9 @@
#include "Screen.h"
#include "ImagePrimitives.h"
#include "XcbGlWindowInterface.h"
#include "DrawingContext.h"
#include "FontsManager.h"
#include <xcb/xcb.h>
@ -27,7 +29,7 @@ XcbWindow::~XcbWindow()
xcb_destroy_window(mConnection, mHandle);
}
void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, XcbGlInterface* xcbGlInterface)
void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, FontsManager* fontsManager, XcbGlInterface* xcbGlInterface)
{
if (!screen)
{
@ -52,7 +54,7 @@ void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface);
const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
window->setPlatformWindow(std::move(xcb_window), drawing_mode);
window->setPlatformWindow(std::move(xcb_window), fontsManager, drawing_mode);
}
int XcbWindow::getHandle() const

View file

@ -6,6 +6,9 @@ class XcbImage;
class XcbScreen;
class XcbGlWindowInterface;
class XcbGlInterface;
class FontsManager;
struct xcb_connection_t;
namespace mt
@ -19,7 +22,7 @@ public:
XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection, XcbGlInterface* xcbGlInterface);
virtual ~XcbWindow();
static void add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, XcbGlInterface* xcbGlInterface);
static void add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, FontsManager* fontsManager, XcbGlInterface* xcbGlInterface);
int getHandle() const;
unsigned getGraphicsContext() const;

View file

@ -1,5 +1,6 @@
#include "FreeTypeFontEngine.h"
#include "Image.h"
#include <iostream>

View file

@ -1,6 +1,5 @@
#include "Image.h"
#include "PngWriter.h"
#include "DrawingManager.h"
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "Grid.h"
@ -12,11 +11,13 @@
int main()
{
/*
DrawingManager manager;
manager.InitalizeSurface(200, 200);
manager.InitializeContext();
auto line = LineSegment::Create(Point(10.0, 10.0), Point(190.0, 190.0));
*/
return 0;
}