Skip to content

Commit

Permalink
Initial CairoHelper
Browse files Browse the repository at this point in the history
Added a new class for common cairo functions.

* #25
* NatronGitHub/Natron#970
  • Loading branch information
rodlie committed Jun 11, 2024
1 parent ac12134 commit 61543e4
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Bundle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PLUGINOBJECTS += \
Text.o \
Morphology.o \
MagickPlugin.o \
CairoHelper.o \
ofxsOGLTextRenderer.o \
ofxsOGLFontData.o \
ofxsRectangleInteract.o \
Expand Down Expand Up @@ -147,6 +148,7 @@ VPATH += \
$(SRCDIR)/Magick/Roll \
$(SRCDIR)/Magick/Wave \
$(SRCDIR)/Magick/Morphology \
$(SRCDIR)/Helpers \
$(SRCDIR)/lodepng

ifeq ($(AUDIO), ON)
Expand All @@ -156,6 +158,7 @@ endif
CXXFLAGS += \
-I$(SRCDIR)/Extra \
-I$(SRCDIR)/Magick \
-I$(SRCDIR)/Helpers \
-I$(SRCDIR)/lodepng

include $(SRCDIR)/Makefile.master
Expand Down Expand Up @@ -187,7 +190,7 @@ CXXFLAGS += $(SOX_CXXFLAGS)
LINKFLAGS += $(SOX_LINKFLAGS)
endif

CXXFLAGS += -I. -I$(SRCDIR)/Magick -I$(SRCDIR)/Text -I$(SRCDIR)/lodepng
CXXFLAGS += -I. -I$(SRCDIR)/Magick -I$(SRCDIR)/Text -I$(SRCDIR)/Helpers -I$(SRCDIR)/lodepng

ifneq ($(LICENSE),COMMERCIAL)
CXXFLAGS += $(POPPLER_CXXFLAGS)
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Extra)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Audio)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Bundle)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Text)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Helpers)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lodepng)
#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/OCL)

Expand Down Expand Up @@ -161,6 +162,7 @@ FILE(GLOB SOURCES
"Extra/OpenRaster.cpp"
"Extra/ReadCDR.cpp"
"Extra/ReadKrita.cpp"
"Helpers/CairoHelper.cpp"
"Magick/Arc.cpp"
"Magick/Charcoal.cpp"
"Magick/Edges.cpp"
Expand Down
4 changes: 3 additions & 1 deletion Extra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ PLUGINOBJECTS += ReadPDF.o
endif

PLUGINOBJECTS += \
CairoHelper.o \
ofxsTransform3x3.o \
ofxsTransformInteract.o \
ofxsShutter.o \
Expand Down Expand Up @@ -40,7 +41,7 @@ SRCDIR = ..
include $(SRCDIR)/Makefile.master
include $(SRCDIR)/Makefile.io

VPATH += $(SRCDIR)/lodepng
VPATH += $(SRCDIR)/lodepng $(SRCDIR)/Helpers

CXXFLAGS += \
$(FCONFIG_CXXFLAGS) \
Expand All @@ -49,6 +50,7 @@ CXXFLAGS += \
$(XML_CXXFLAGS) \
$(ZIP_CXXFLAGS) \
$(GLIB_CXXFLAGS) \
-I$(SRCDIR)/Helpers \
-I$(SRCDIR)/lodepng

LINKFLAGS += \
Expand Down
41 changes: 41 additions & 0 deletions Helpers/CairoHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
####################################################################
#
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
####################################################################
*/

#include "CairoHelper.h"

#include <cmath>

void CairoHelper::applyRotate(cairo_t *cr,
double rotate,
XY origin)
{
if (!cr || rotate == 0.) { return; }

cairo_translate(cr, origin.x, origin.y);
cairo_rotate(cr, -rotate * (M_PI / 180.0));
cairo_translate(cr, -origin.x, -origin.y);
}

void CairoHelper::applyFlip(cairo_t *cr,
int height)
{
if (!cr || height < 1) { return; }

cairo_scale(cr, 1.0f, -1.0f);
cairo_translate(cr, 0.0f, -height);
}
41 changes: 41 additions & 0 deletions Helpers/CairoHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
####################################################################
#
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
####################################################################
*/

#ifndef CAIROHELPER_H
#define CAIROHELPER_H

#include <cairo.h>

class CairoHelper
{
public:
struct XY
{
double x;
double y;
};
/** @brief apply rotate */
static void applyRotate(cairo_t *cr,
double rotate,
XY origin);
/** @brief apply flip */
static void applyFlip(cairo_t *cr,
int height);
};

#endif // CAIROHELPER_H

0 comments on commit 61543e4

Please sign in to comment.