Skip to content

Commit 61543e4

Browse files
committed
Initial CairoHelper
Added a new class for common cairo functions. * #25 * NatronGitHub/Natron#970
1 parent ac12134 commit 61543e4

File tree

5 files changed

+91
-2
lines changed

5 files changed

+91
-2
lines changed

Bundle/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PLUGINOBJECTS += \
5151
Text.o \
5252
Morphology.o \
5353
MagickPlugin.o \
54+
CairoHelper.o \
5455
ofxsOGLTextRenderer.o \
5556
ofxsOGLFontData.o \
5657
ofxsRectangleInteract.o \
@@ -147,6 +148,7 @@ VPATH += \
147148
$(SRCDIR)/Magick/Roll \
148149
$(SRCDIR)/Magick/Wave \
149150
$(SRCDIR)/Magick/Morphology \
151+
$(SRCDIR)/Helpers \
150152
$(SRCDIR)/lodepng
151153

152154
ifeq ($(AUDIO), ON)
@@ -156,6 +158,7 @@ endif
156158
CXXFLAGS += \
157159
-I$(SRCDIR)/Extra \
158160
-I$(SRCDIR)/Magick \
161+
-I$(SRCDIR)/Helpers \
159162
-I$(SRCDIR)/lodepng
160163

161164
include $(SRCDIR)/Makefile.master
@@ -187,7 +190,7 @@ CXXFLAGS += $(SOX_CXXFLAGS)
187190
LINKFLAGS += $(SOX_LINKFLAGS)
188191
endif
189192

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

192195
ifneq ($(LICENSE),COMMERCIAL)
193196
CXXFLAGS += $(POPPLER_CXXFLAGS)

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Extra)
115115
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Audio)
116116
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Bundle)
117117
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Text)
118+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/Helpers)
118119
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lodepng)
119120
#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/OCL)
120121

@@ -161,6 +162,7 @@ FILE(GLOB SOURCES
161162
"Extra/OpenRaster.cpp"
162163
"Extra/ReadCDR.cpp"
163164
"Extra/ReadKrita.cpp"
165+
"Helpers/CairoHelper.cpp"
164166
"Magick/Arc.cpp"
165167
"Magick/Charcoal.cpp"
166168
"Magick/Edges.cpp"

Extra/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PLUGINOBJECTS += ReadPDF.o
1212
endif
1313

1414
PLUGINOBJECTS += \
15+
CairoHelper.o \
1516
ofxsTransform3x3.o \
1617
ofxsTransformInteract.o \
1718
ofxsShutter.o \
@@ -40,7 +41,7 @@ SRCDIR = ..
4041
include $(SRCDIR)/Makefile.master
4142
include $(SRCDIR)/Makefile.io
4243

43-
VPATH += $(SRCDIR)/lodepng
44+
VPATH += $(SRCDIR)/lodepng $(SRCDIR)/Helpers
4445

4546
CXXFLAGS += \
4647
$(FCONFIG_CXXFLAGS) \
@@ -49,6 +50,7 @@ CXXFLAGS += \
4950
$(XML_CXXFLAGS) \
5051
$(ZIP_CXXFLAGS) \
5152
$(GLIB_CXXFLAGS) \
53+
-I$(SRCDIR)/Helpers \
5254
-I$(SRCDIR)/lodepng
5355

5456
LINKFLAGS += \

Helpers/CairoHelper.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
####################################################################
3+
#
4+
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie>
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
####################################################################
17+
*/
18+
19+
#include "CairoHelper.h"
20+
21+
#include <cmath>
22+
23+
void CairoHelper::applyRotate(cairo_t *cr,
24+
double rotate,
25+
XY origin)
26+
{
27+
if (!cr || rotate == 0.) { return; }
28+
29+
cairo_translate(cr, origin.x, origin.y);
30+
cairo_rotate(cr, -rotate * (M_PI / 180.0));
31+
cairo_translate(cr, -origin.x, -origin.y);
32+
}
33+
34+
void CairoHelper::applyFlip(cairo_t *cr,
35+
int height)
36+
{
37+
if (!cr || height < 1) { return; }
38+
39+
cairo_scale(cr, 1.0f, -1.0f);
40+
cairo_translate(cr, 0.0f, -height);
41+
}

Helpers/CairoHelper.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
####################################################################
3+
#
4+
# Copyright (C) 2024 Ole-André Rodlie <https://github.com/rodlie>
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 2.1 of the License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
####################################################################
17+
*/
18+
19+
#ifndef CAIROHELPER_H
20+
#define CAIROHELPER_H
21+
22+
#include <cairo.h>
23+
24+
class CairoHelper
25+
{
26+
public:
27+
struct XY
28+
{
29+
double x;
30+
double y;
31+
};
32+
/** @brief apply rotate */
33+
static void applyRotate(cairo_t *cr,
34+
double rotate,
35+
XY origin);
36+
/** @brief apply flip */
37+
static void applyFlip(cairo_t *cr,
38+
int height);
39+
};
40+
41+
#endif // CAIROHELPER_H

0 commit comments

Comments
 (0)