Commit 44a38db3 by Jessica Hawkwell

starting on NitroCairo

1 parent d8fe66d4
cmake_minimum_required (VERSION 3.10) cmake_minimum_required (VERSION 3.10)
project(Nitrogen VERSION 1.0.0 DESCRIPTION "Nitrogen Desktop Experience") project(Nitrogen VERSION 1.0.0 DESCRIPTION "Nitrogen Desktop Experience")
option(USE_CAIRO "Use Cairo for rendering" ON)
execute_process(COMMAND ./ver.sh OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ./ver.sh OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_PROJECT_VERSION_TWEAK ${GIT_COMMIT}) set(CMAKE_PROJECT_VERSION_TWEAK ${GIT_COMMIT})
set(PROJECT_VERSION_TWEAK ${GIT_COMMIT}) set(PROJECT_VERSION_TWEAK ${GIT_COMMIT})
...@@ -24,16 +26,37 @@ if (EXISTS /usr/local/include) ...@@ -24,16 +26,37 @@ if (EXISTS /usr/local/include)
include_directories(/usr/local/include) include_directories(/usr/local/include)
endif() endif()
find_package(X11)
find_library(BoehmGC_C NAMES gc-threaded REQUIRED) find_library(BoehmGC_C NAMES gc-threaded REQUIRED)
find_library(BoehmGC_CPP NAMES gccpp-threaded REQUIRED) find_library(BoehmGC_CPP NAMES gccpp-threaded REQUIRED)
set(BoehmGC ${BoehmGC_C} ${BoehmGC_CPP}) set(BoehmGC ${BoehmGC_C} ${BoehmGC_CPP})
find_package(X11) if(USE_CAIRO)
find_library(Cairo_P cairo)
find_library(CairoMM_P cairomm)
else()
set(Cairo_P "")
set(CairoMM_P "")
endif()
set(Cairo "")
if(${Cairo_P} STREQUAL "NOTFOUND")
set(Cairo ${Cairo_P})
endif()
if(${CairoMM_P} STREQUAL "NOTFOUND")
set(Cairo ${Cairo} ${CairoMM_P})
endif()
#include_directories(AFTER SYSTEM ${CMAKE_BINARY_DIR}/deps/resvg/capi/include/) #include_directories(AFTER SYSTEM ${CMAKE_BINARY_DIR}/deps/resvg/capi/include/)
#add_subdirectory(deps) #add_subdirectory(deps)
add_subdirectory(src/nde) add_subdirectory(src/nde)
if(USE_CAIRO)
add_subdirectory(src/NitroCairo)
endif()
#add_subdirectory(src/NitroSVG)
add_subdirectory(src/ntk) add_subdirectory(src/ntk)
add_subdirectory(src/NitroWin) add_subdirectory(src/NitroWin)
cmake_minimum_required (VERSION 3.10)
project (NitroCairo DESCRIPTION "Cairo for Nitrogen")
configure_file(${PROJECT_NAME}.h.in ${PROJECT_NAME}.h)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build/share/doc/nitrogen/${PROJECT_NAME})
configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile)
add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(doc doc_${PROJECT_NAME})
add_library(${PROJECT_NAME} SHARED
nitrogen/cairo/CairoStatus.cpp
nitrogen/cairo/ContentTypes.cpp
nitrogen/cairo/FormatTypes.cpp
nitrogen/cairo/Surface.cpp
nitrogen/cairo/SurfaceTypes.cpp
)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC nde ${BoehmGC} ${X11_LIBRARIES} ${Cairo})
target_include_directories (NitroCairo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(FILES ${PROJECT_NAME}.h DESTINATION include)
install(DIRECTORY nitrogen DESTINATION include FILES_MATCHING PATTERN "*.h")
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: NitroCairo.h
* Author: jlhawkwell
*/
#ifndef NITROCAIRO_H
#define NITROCAIRO_H
#ifndef GC_NAME_CONFLICT
#define GC_NAME_CONFLICT
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>
#include <gc/gc_backptr.h>
#endif
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-ps.h>
#include <cairo/cairo-svg.h>
#if defined(BEOS)
#include <cairo/cairo-beos.h>
#elif defined(OS2)
#include <cairo/cairo-os2.h>
#elif defined(TARGET_OS_MAC)
#include <cairo/cairo-quartz.h>
#elif defined(WIN32) || defined(_WIN32)
#include <cairo/cairo-win32.h>
#else
#include <cairo/cairo-xcb.h>
#include <cairo/cairo-xlib.h>
#include <cairo/cairo-xlib-xrender.h>
#endif
#define NITROCAIRO_NAME "NitroCairo"
#define NITROCAIRO_VERSION_MAJOR 1
#define NITROCAIRO_VERSION_MINOR 0
#define NITROCAIRO_VERSION_PATCH 0
#define NITROCAIRO_VERSION_TWEAK de85c12a
#define NITROCAIRO_VERSION "1.0.0.de85c12a"
#endif /* NITROCAIRO_H */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: NitroCairo.h
* Author: jlhawkwell
*/
#ifndef NITROCAIRO_H
#define NITROCAIRO_H
#ifndef GC_NAME_CONFLICT
#define GC_NAME_CONFLICT
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>
#include <gc/gc_backptr.h>
#endif
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-ps.h>
#include <cairo/cairo-svg.h>
#if defined(BEOS)
#include <cairo/cairo-beos.h>
#elif defined(OS2)
#include <cairo/cairo-os2.h>
#elif defined(TARGET_OS_MAC)
#include <cairo/cairo-quartz.h>
#elif defined(WIN32) || defined(_WIN32)
#include <cairo/cairo-win32.h>
#else
#include <cairo/cairo-xcb.h>
#include <cairo/cairo-xlib.h>
#include <cairo/cairo-xlib-xrender.h>
#endif
#define NITROCAIRO_NAME "@PROJECT_NAME@"
#define NITROCAIRO_VERSION_MAJOR @Nitrogen_VERSION_MAJOR@
#define NITROCAIRO_VERSION_MINOR @Nitrogen_VERSION_MINOR@
#define NITROCAIRO_VERSION_PATCH @Nitrogen_VERSION_PATCH@
#define NITROCAIRO_VERSION_TWEAK @Nitrogen_VERSION_TWEAK@
#define NITROCAIRO_VERSION "@Nitrogen_VERSION_MAJOR@.@Nitrogen_VERSION_MINOR@.@Nitrogen_VERSION_PATCH@.@Nitrogen_VERSION_TWEAK@"
#endif /* NITROCAIRO_H */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: CairoStatus.cpp
* Author: jlhawkwell
*/
#include <unordered_map>
#include <nitrogen/cairo/CairoStatus.h>
namespace nitrogen {
namespace cairo {
static std::unordered_map<CairoStatus,cairo_status_t> CairoStatusList = {
#include <nitrogen/cairo/util/ListHelper.h>
#include <nitrogen/cairo/enums/CairoStatusEnum.h>
};
cairo_status_t convert(Status s) {
for (auto it = CairoStatusList.begin(); it != CairoStatusList.end(); ++it) {
if (it->first == s) { return it->second; }
}
return cairo_status_t::CAIRO_STATUS_NULL_POINTER;
}
CairoStatus convert(cairo_status_t s) {
for (auto it = CairoStatusList.begin(); it != CairoStatusList.end(); ++it) {
if (it->second == s) { return it->first; }
}
return CairoStatus::NullPointer;
}
}
}
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: CairoStatus.h
* Author: jlhawkwell
*/
#ifndef CairoStatus_h
#define CairoStatus_h
#include <NitroCairo.h>
namespace nitrogen {
namespace cairo {
enum CairoStatus {
#include <nitrogen/cairo/util/EnumHelper.h>
#include <nitrogen/cairo/enums/CairoStatusEnum.h>
};
cairo_status_t convert(Status s);
CairoStatus convert(cairo_status_t s);
}
}
#endif /* CairoStatus_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: ContentTypes.cpp
* Author: jlhawkwell
*/
#include <unordered_map>
#include <nitrogen/cairo/ContentTypes.h>
namespace nitrogen {
namespace cairo {
static std::unordered_map<ContentTypes,cairo_content_t> ContentTypesList = {
#include <nitrogen/cairo/util/ListHelper.h>
#include <nitrogen/cairo/enums/ContentTypesEnum.h>
};
cairo_content_t convert(ContentTypes ct) {
for (auto it = ContentTypesList.begin(); it != ContentTypesList.end(); ++it) {
if (it->first == ct) { return it->second; }
}
return cairo_content_t::CAIRO_CONTENT_COLOR;
}
ContentTypes convert(cairo_content_t ct) {
for (auto it = ContentTypesList.begin(); it != ContentTypesList.end(); ++it) {
if (it->second == ct) { return it->first; }
}
return ContentTypes::Color;
}
}
}
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: ContentTypes.h
* Author: jlhawkwell
*/
#ifndef ContentTypes_h
#define ContentTypes_h
#include <NitroCairo.h>
namespace nitrogen {
namespace cairo {
enum ContentTypes {
#include <nitrogen/cairo/util/EnumHelper.h>
#include <nitrogen/cairo/enums/ContentTypesEnum.h>
};
cairo_content_t convert(ContentTypes ct);
ContentTypes convert(cairo_content_t ct);
}
}
#endif /* ContentTypes_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Device.h
* Author: jlhawkwell
*/
#ifndef Device_h
#define Device_h
#include <nitrogen/cairo/CairoStatus.h>
#include <NitroCairo.h>
#include <nitrogen/cairo/ContentTypes.h>
#include <nitrogen/cairo/FormatTypes.h>
namespace nitrogen {
namespace cairo {
class Device : public gc {
friend class Surface;
public:
protected:
Device(cairo_device_t* device);
cairo_device_t* dev;
private:
};
}
}
#endif /* Device_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: FormatTypes.cpp
* Author: jlhawkwell
*/
#include <unordered_map>
#include <nitrogen/cairo/FormatTypes.h>
namespace nitrogen {
namespace cairo {
static std::unordered_map<FormatTypes,cairo_format_t> FormatTypesList = {
#include <nitrogen/cairo/util/ListHelper.h>
#include <nitrogen/cairo/enums/FormatTypesEnum.h>
};
cairo_format_t convert(FormatTypes ft) {
for (auto it = FormatTypesList.begin(); it != FormatTypesList.end(); ++it) {
if (it->first == ft) { return it->second; }
}
return cairo_format_t::CAIRO_FORMAT_INVALID;
}
FormatTypes convert(cairo_format_t ft) {
for (auto it = FormatTypesList.begin(); it != FormatTypesList.end(); ++it) {
if (it->second == ft) { return it->first; }
}
return FormatTypes::Invalid;
}
}
}
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: FormatTypes.h
* Author: jlhawkwell
*/
#ifndef FormatTypes_h
#define FormatTypes_h
#include <NitroCairo.h>
namespace nitrogen {
namespace cairo {
enum FormatTypes {
#include <nitrogen/cairo/util/EnumHelper.h>
#include <nitrogen/cairo/enums/FormatTypesEnum.h>
};
cairo_format_t convert(FormatTypes ft);
FormatTypes convert(cairo_format_t ft);
}
}
#endif /* FormatTypes_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Rectangle.h
* Author: jlhawkwell
*/
#ifndef Rectangle_h
#define Rectangle_h
//#include <NitroCairo.h>
namespace nitrogen {
namespace cairo {
template<class T>
struct Rectangle {
T x;
T y;
T width;
T height;
};
}
}
#endif /* Rectangle_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Surface.cpp
* Author: jlhawkwell
*/
#include <nitrogen/cairo/Surface.h>
namespace nitrogen {
namespace cairo {
Surface::Surface(ContentTypes ctype, int width, int height) {
surface = nullptr;
}
Surface::~Surface() {
destroy();
}
Surface* Surface::createSimilar(ContentTypes ctype, int width, int height) {
cairo_surface_t* st =
cairo_surface_create_similar(surface, convert(ctype), width, height);
Surface* pt = new Surface(st);
return pt;
}
Surface* Surface::createSimilarImage(FormatTypes ftype, int width, int height) {
cairo_surface_t* st =
cairo_surface_create_similar_image(surface, convert(ftype), width, height);
Surface* pt = new Surface(st);
return pt;
}
Surface* Surface::createRect(double x, double y, double width, double height) {
cairo_surface_t* st =
cairo_surface_create_for_rectangle(surface, x, y, width, height);
Surface* pt = new Surface(st);
return pt;
}
Surface* Surface::reference() {
cairo_surface_t* st = cairo_surface_reference(surface);
Surface* pt = new Surface(st);
return pt;
}
void Surface::destroy() { cairo_surface_destroy(surface); }
Status Surface::status() {
return convert(cairo_surface_status(surface));
}
void Surface::finish() { cairo_surface_finish(surface); }
void Surface::flush() { cairo_surface_flush(surface); }
Device* Surface::getDevice() {
cairo_device_t* dt = cairo_surface_get_device(surface);
Device* pt = new Device(dt);
return pt;
}
void Surface::getFontOptions(cairo_font_options_t* options) {
cairo_surface_get_font_options(surface, options);
}
ContentTypes Surface::getContent() {
return convert(cairo_surface_get_content(surface));
}
void Surface::markDirty() { cairo_surface_mark_dirty(surface); }
void Surface::markDirtyRectangle(int x, int y, int width, int height) {
cairo_surface_mark_dirty_rectangle(surface, x, y, width, height);
}
void Surface::getDeviceOffset(double* x, double* y) {
cairo_surface_get_device_offset(surface, x, y);
}
void Surface::setDeviceOffset(double x, double y) {
cairo_surface_set_device_offset(surface, x, y);
}
void Surface::getDeviceScale(double* x, double* y) {
cairo_surface_get_device_scale(surface, x, y);
}
void Surface::setDeviceScale(double x, double y) {
cairo_surface_set_device_scale(surface, x, y);
}
void Surface::getFallbackResolution(double* x, double* y) {
cairo_surface_get_fallback_resolution(surface, x, y);
}
void Surface::setFallbackResolution(double x, double y) {
cairo_surface_set_fallback_resolution(surface, x, y);
}
SurfaceTypes Surface::getType() {
return convert(cairo_surface_get_type(surface));
}
unsigned int Surface::getReferenceCount() {
return cairo_surface_get_reference_count(surface);
}
void* Surface::getUserData(const cairo_user_data_key_t* key) {
return cairo_surface_get_user_data(surface, key);
}
Status Surface::setUserData(const cairo_user_data_key_t* key,
void* user_data, cairo_destroy_func_t destroy) {
return convert(cairo_surface_set_user_data(surface, key, user_data, destroy));
}
void Surface::copyPage() { cairo_surface_copy_page(surface); }
void Surface::showPage() { cairo_surface_show_page(surface); }
bool Surface::hasShowTextGlyphs() {
return cairo_surface_has_show_text_glyphs(surface);
}
CairoStatus Surface::setMimeData(std::string* mimeType,
const unsigned char* data, unsigned long length,
cairo_destroy_func_t destroy, void* closure) {
cairo_status_t st = cairo_surface_set_mime_data(surface, mimeType->c_str(),
data, length, destroy, closure);
return convert(st);
}
void Surface::getMimeData(std::string* mimeType,
const unsigned char** data, unsigned long * length) {
}
bool Surface::supportsMimeType(std::string* mimeType) {
return cairo_surface_supports_mime_type(surface, mimeType->c_str());
}
Surface* Surface::mapToImage(Rectangle<int>* region) {
const _cairo_rectangle_int* rect = new _cairo_rectangle_int{
region->x, region->y, region->width, region->height};
cairo_surface_t* st = cairo_surface_map_to_image(surface, rect);
Surface* pt = new Surface(st);
return pt;
}
void Surface::unmapImage(Surface* img) { cairo_surface_unmap_image(surface, img->surface); }
Surface::Surface(cairo_surface_t* sfc) { surface = sfc; }
}
}
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Surface.h
* Author: jlhawkwell
*/
#ifndef Surface_h
#define Surface_h
#include <iostream>
#include <NitroCairo.h>
#include <nitrogen/cairo/CairoStatus.h>
#include <nitrogen/cairo/ContentTypes.h>
#include <nitrogen/cairo/Device.h>
#include <nitrogen/cairo/FormatTypes.h>
#include <nitrogen/cairo/Rectangle.h>
#include <nitrogen/cairo/SurfaceTypes.h>
namespace nitrogen {
namespace cairo {
class Surface : public gc {
public:
Surface(ContentTypes ctype, int width, int height);
virtual ~Surface();
virtual Surface* createSimilar(ContentTypes ctype, int width, int height);
virtual Surface* createSimilarImage(FormatTypes ftype, int width, int height);
virtual Surface* createRect(double x, double y, double width, double height);
virtual Surface* reference();
virtual void destroy();
virtual Status status();
virtual void finish();
virtual void flush();
virtual Device* getDevice();
virtual void getFontOptions(cairo_font_options_t* options);
virtual ContentTypes getContent();
virtual void markDirty();
virtual void markDirtyRectangle(int x, int y, int width, int height);
virtual void getDeviceOffset(double* x, double* y);
virtual void setDeviceOffset(double x, double y);
virtual void getDeviceScale(double* x, double* y);
virtual void setDeviceScale(double x, double y);
virtual void getFallbackResolution(double* x, double* y);
virtual void setFallbackResolution(double x, double y);
virtual SurfaceTypes getType();
virtual unsigned int getReferenceCount();
virtual void* getUserData(const cairo_user_data_key_t* key);
virtual Status setUserData(const cairo_user_data_key_t* key,
void* user_data, cairo_destroy_func_t destroy);
virtual void copyPage();
virtual void showPage();
virtual bool hasShowTextGlyphs();
virtual CairoStatus setMimeData(std::string* mimeType, const unsigned char *data,
unsigned long length, cairo_destroy_func_t destroy, void *closure);
virtual void getMimeData(std::string* mimeType, const unsigned char **data,
unsigned long *length);
virtual bool supportsMimeType(std::string* mimeType);
virtual Surface* mapToImage(Rectangle<int>* region);
virtual void unmapImage(Surface* img);
protected:
cairo_surface_t* surface;
Surface(cairo_surface_t* sfc);
private:
};
}
}
#endif /* Surface_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: SurfaceTypes.cpp
* Author: jlhawkwell
*/
#include <unordered_map>
#include <nitrogen/cairo/SurfaceTypes.h>
namespace nitrogen {
namespace cairo {
static std::unordered_map<SurfaceTypes,cairo_surface_type_t> SurfaceTypesList = {
#include <nitrogen/cairo/util/ListHelper.h>
#include <nitrogen/cairo/enums/SurfaceTypesEnum.h>
};
cairo_surface_type_t convert(SurfaceTypes st) {
for (auto it = SurfaceTypesList.begin(); it != SurfaceTypesList.end(); ++it) {
if (it->first == st) { return it->second; }
}
return cairo_surface_type_t::CAIRO_SURFACE_TYPE_IMAGE;
}
SurfaceTypes convert(cairo_surface_type_t st) {
for (auto it = SurfaceTypesList.begin(); it != SurfaceTypesList.end(); ++it) {
if (it->second == st) { return it->first; }
}
return SurfaceTypes::Image;
}
}
}
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: SurfaceTypes.h
* Author: jlhawkwell
*/
#ifndef SurfaceTypes_h
#define SurfaceTypes_h
#include <NitroCairo.h>
namespace nitrogen {
namespace cairo {
enum SurfaceTypes {
#include <nitrogen/cairo/util/EnumHelper.h>
#include <nitrogen/cairo/enums/SurfaceTypesEnum.h>
};
cairo_surface_type_t convert(SurfaceTypes st);
SurfaceTypes convert(cairo_surface_type_t st);
}
}
#endif /* SurfaceTypes_h */
NVPAIR(cSuccess, CAIRO_STATUS_SUCCESS)
NVPAIR(NoMemory, CAIRO_STATUS_NO_MEMORY)
NVPAIR(InvalidRestore, CAIRO_STATUS_INVALID_RESTORE)
NVPAIR(InvalidPopGroup, CAIRO_STATUS_INVALID_POP_GROUP)
NVPAIR(NoCurrentPoint, CAIRO_STATUS_NO_CURRENT_POINT)
NVPAIR(InvalidMatrix, CAIRO_STATUS_INVALID_MATRIX)
NVPAIR(InvalidStatus, CAIRO_STATUS_INVALID_STATUS)
NVPAIR(NullPointer, CAIRO_STATUS_NULL_POINTER)
NVPAIR(InvalidString, CAIRO_STATUS_INVALID_STRING)
NVPAIR(InvalidPathData, CAIRO_STATUS_INVALID_PATH_DATA)
NVPAIR(ReadError, CAIRO_STATUS_READ_ERROR)
NVPAIR(WriteError, CAIRO_STATUS_WRITE_ERROR)
NVPAIR(SurfaceFinished, CAIRO_STATUS_SURFACE_FINISHED)
NVPAIR(SurfaceTypeMismatch, CAIRO_STATUS_SURFACE_TYPE_MISMATCH)
NVPAIR(PatternTypeMismatch, CAIRO_STATUS_PATTERN_TYPE_MISMATCH)
NVPAIR(InvalidContent, CAIRO_STATUS_INVALID_CONTENT)
NVPAIR(InvalidFormat, CAIRO_STATUS_INVALID_FORMAT)
NVPAIR(InvalidVisual, CAIRO_STATUS_INVALID_VISUAL)
NVPAIR(FileNotFound, CAIRO_STATUS_FILE_NOT_FOUND)
NVPAIR(InvalidDash, CAIRO_STATUS_INVALID_DASH)
NVPAIR(InvalidComment, CAIRO_STATUS_INVALID_DSC_COMMENT)
NVPAIR(InvalidIndex, CAIRO_STATUS_INVALID_INDEX)
NVPAIR(ClipNotRepresentable, CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
NVPAIR(TempFileError, CAIRO_STATUS_TEMP_FILE_ERROR)
NVPAIR(InvalidStride, CAIRO_STATUS_INVALID_STRIDE)
NVPAIR(FontTypeMismatch, CAIRO_STATUS_FONT_TYPE_MISMATCH)
NVPAIR(UserFontImmutable, CAIRO_STATUS_USER_FONT_IMMUTABLE)
NVPAIR(UserFontError, CAIRO_STATUS_USER_FONT_ERROR)
NVPAIR(NegativeCount, CAIRO_STATUS_NEGATIVE_COUNT)
NVPAIR(InvalidClusters, CAIRO_STATUS_INVALID_CLUSTERS)
NVPAIR(InvalidSlant, CAIRO_STATUS_INVALID_SLANT)
NVPAIR(InvalidWeight, CAIRO_STATUS_INVALID_WEIGHT)
NVPAIR(InvalidSize, CAIRO_STATUS_INVALID_SIZE)
NVPAIR(FontNotImplemented, CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED)
NVPAIR(DeviceTypeMismatch, CAIRO_STATUS_DEVICE_TYPE_MISMATCH)
NVPAIR(DeviceError, CAIRO_STATUS_DEVICE_ERROR)
NVPAIR(InvalidMeshConstruction, CAIRO_STATUS_INVALID_MESH_CONSTRUCTION)
NVPAIR(DeviceFinished, CAIRO_STATUS_DEVICE_FINISHED)
NVPAIR(JBig2GlobalMissing, CAIRO_STATUS_JBIG2_GLOBAL_MISSING)
NVPAIR(PNGError, CAIRO_STATUS_PNG_ERROR)
NVPAIR(FreeTypeError, CAIRO_STATUS_FREETYPE_ERROR)
NVPAIR(Win32GDIError, CAIRO_STATUS_WIN32_GDI_ERROR)
NVPAIR(TagError, CAIRO_STATUS_TAG_ERROR)
NVPAIR(LastStatus, CAIRO_STATUS_LAST_STATUS)
NVPAIR(Alpha, CAIRO_CONTENT_ALPHA)
NVPAIR(Color, CAIRO_CONTENT_COLOR)
NVPAIR(AlphaColor, CAIRO_CONTENT_COLOR_ALPHA)
NVPAIR(Invalid, CAIRO_FORMAT_INVALID)
NVPAIR(ARGB32, CAIRO_FORMAT_ARGB32)
NVPAIR(RGB24, CAIRO_FORMAT_RGB24)
NVPAIR(Alpha8, CAIRO_FORMAT_A8)
NVPAIR(Alpha1, CAIRO_FORMAT_A1)
NVPAIR(RGB16, CAIRO_FORMAT_RGB16_565)
NVPAIR(RGB30, CAIRO_FORMAT_RGB30)
NVPAIR(Image, CAIRO_SURFACE_TYPE_IMAGE)
NVPAIR(PDF, CAIRO_SURFACE_TYPE_PDF)
NVPAIR(PostScript, CAIRO_SURFACE_TYPE_PS)
NVPAIR(Xlib, CAIRO_SURFACE_TYPE_XLIB)
NVPAIR(XCB, CAIRO_SURFACE_TYPE_XCB)
NVPAIR(Glitz, CAIRO_SURFACE_TYPE_GLITZ)
NVPAIR(Quartz, CAIRO_SURFACE_TYPE_QUARTZ)
NVPAIR(Win32, CAIRO_SURFACE_TYPE_WIN32)
NVPAIR(BeOS, CAIRO_SURFACE_TYPE_BEOS)
NVPAIR(DirectFB, CAIRO_SURFACE_TYPE_DIRECTFB)
NVPAIR(SVG, CAIRO_SURFACE_TYPE_SVG)
NVPAIR(OS2, CAIRO_SURFACE_TYPE_OS2)
NVPAIR(Win32Printing, CAIRO_SURFACE_TYPE_WIN32_PRINTING)
NVPAIR(QuartzImage, CAIRO_SURFACE_TYPE_QUARTZ_IMAGE)
NVPAIR(Script, CAIRO_SURFACE_TYPE_SCRIPT)
NVPAIR(Qt, CAIRO_SURFACE_TYPE_QT)
NVPAIR(Recording, CAIRO_SURFACE_TYPE_RECORDING)
NVPAIR(VG, CAIRO_SURFACE_TYPE_VG)
NVPAIR(OpenGL, CAIRO_SURFACE_TYPE_GL)
NVPAIR(DRM, CAIRO_SURFACE_TYPE_DRM)
NVPAIR(tee, CAIRO_SURFACE_TYPE_TEE)
NVPAIR(XML, CAIRO_SURFACE_TYPE_XML)
NVPAIR(Skia, CAIRO_SURFACE_TYPE_SKIA)
NVPAIR(Subsurface, CAIRO_SURFACE_TYPE_SUBSURFACE)
NVPAIR(COGL, CAIRO_SURFACE_TYPE_COGL)
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Convert.h
* Author: jlhawkwell
*/
#ifndef Convert_h
#define Convert_h
#include <NitroCairo.h>
#include <unordered_map>
namespace nitrogen {
namespace cairo {
namespace util {
template<class I, class O>
O convert<I,O>(I in, O def, std::unordered_map<I,O>* list) {
for (auto it = list->begin(); it != list->end(); ++it) {
if (it->first == in) { return it->second; }
}
return def;
}
template<class I, class O>
O convert<I,O>(I in, O def, std::unordered_map<O,I>* list) {
for (auto it = list->begin(); it != list->end(); ++it) {
if (it->second == in) { return it->first; }
}
return def;
}
}
}
}
#endif /* Convert_h */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: EnumHelper.h
* Author: jlhawkwell
*/
#ifdef NVPAIR
#undef NVPAIR
#endif
#define NVPAIR(n, v) n = v,
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: Convert.h
* Author: jlhawkwell
*/
#ifdef NVPAIR
#undef NVPAIR
#endif
#define NVPAIR(n, v) {n, v},
cmake_minimum_required (VERSION 3.10)
project (NitroSVG DESCRIPTION "Nitrogen SVG Renderer")
configure_file(${PROJECT_NAME}.h.in ${PROJECT_NAME}.h)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build/share/doc/nitrogen/${PROJECT_NAME})
configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile)
add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(doc doc_${PROJECT_NAME})
add_library(${PROJECT_NAME} SHARED )
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC nde ${BoehmGC} ${X11_LIBRARIES} ${Cairo})
target_include_directories (NitroSVG PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(FILES ${PROJECT_NAME}.h DESTINATION include)
install(DIRECTORY nitrogen DESTINATION include FILES_MATCHING PATTERN "*.h")
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: nde.h
* Author: jlhawkwell
*
* Created on March 16, 2018, 12:49 PM
*/
#ifndef NDE_H
#define NDE_H
#ifndef GC_NAME_CONFLICT
#define GC_NAME_CONFLICT
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>
#include <gc/gc_backptr.h>
#endif
#define NDE_NAME "NitroSVG"
#define NDE_VERSION_MAJOR 1
#define NDE_VERSION_MINOR 0
#define NDE_VERSION_PATCH 0
#define NDE_VERSION_TWEAK de85c12a
#define NDE_VERSION "1.0.0.de85c12a"
#include <typeinfo>
#include <iosfwd>
#include <string>
namespace nitrogen {
template <typename T>
char * getTypeName(const T obj) {
return (char *)typeid(obj).name();
}
}
#endif /* NDE_H */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: NitroSVG.h
* Author: jlhawkwell
*
* Created on March 16, 2020 02:49 AM
*/
#ifndef NITROSVG_H
#define NITROSVG_H
#ifndef GC_NAME_CONFLICT
#define GC_NAME_CONFLICT
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>
#include <gc/gc_backptr.h>
#endif
#define NITROSVG_NAME "@PROJECT_NAME@"
#define NITROSVG_VERSION_MAJOR @Nitrogen_VERSION_MAJOR@
#define NITROSVG_VERSION_MINOR @Nitrogen_VERSION_MINOR@
#define NITROSVG_VERSION_PATCH @Nitrogen_VERSION_PATCH@
#define NITROSVG_VERSION_TWEAK @Nitrogen_VERSION_TWEAK@
#define NITROSVG_VERSION "@Nitrogen_VERSION_MAJOR@.@Nitrogen_VERSION_MINOR@.@Nitrogen_VERSION_PATCH@.@Nitrogen_VERSION_TWEAK@"
#include <typeinfo>
#include <iosfwd>
#include <string>
#endif /* NITROSVG_H */
/*
* Copyright (c) 2020, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: nde.h
* Author: jlhawkwell
*/
#ifndef BoundingBox_H
#define BoundingBox_h
#include <NitroSVG.h>
namespace nitrogen {
namespace svg {
namespace util {
class BoundingBox : public gc {
public:
void calculate();
// def calculate_bounding_box(surface, node):
// """Calculate ``node``'s bounding box.
//
// See https://www.w3.org/TR/SVG/coords.html#ObjectBoundingBox
//
// """
// if 'bounding_box' not in node and node.tag in BOUNDING_BOX_METHODS:
// bounding_box = BOUNDING_BOX_METHODS[node.tag](surface, node)
// if is_non_empty_bounding_box(bounding_box):
// node['bounding_box'] = bounding_box
// return node.get('bounding_box')
//
//
// def bounding_box_rect(surface, node):
// """Get the bounding box of a ``rect`` node."""
// x, y = size(surface, node.get('x'), 'x'), size(surface, node.get('y'), 'y')
// width = size(surface, node.get('width'), 'x')
// height = size(surface, node.get('height'), 'y')
// return x, y, width, height
//
//
// def bounding_box_circle(surface, node):
// """Get the bounding box of a ``circle`` node."""
// cx = size(surface, node.get('cx'), 'x')
// cy = size(surface, node.get('cy'), 'y')
// r = size(surface, node.get('r'))
// return cx - r, cy - r, 2 * r, 2 * r
//
//
// def bounding_box_ellipse(surface, node):
// """Get the bounding box of an ``ellipse`` node."""
// rx = size(surface, node.get('rx'), 'x')
// ry = size(surface, node.get('ry'), 'y')
// cx = size(surface, node.get('cx'), 'x')
// cy = size(surface, node.get('cy'), 'y')
// return cx - rx, cy - ry, 2 * rx, 2 * ry
//
//
// def bounding_box_line(surface, node):
// """Get the bounding box of a ``line`` node."""
// x1, y1, x2, y2 = tuple(
// size(surface, node.get(position), position[0])
// for position in ('x1', 'y1', 'x2', 'y2'))
// x, y = min(x1, x2), min(y1, y2)
// width, height = max(x1, x2) - x, max(y1, y2) - y
// return x, y, width, height
//
//
// def bounding_box_polyline(surface, node):
// """Get the bounding box of a ``polyline`` or ``polygon`` node."""
// bounding_box = EMPTY_BOUNDING_BOX
// points = []
// normalized_points = normalize(node.get('points', ''))
// while normalized_points:
// x, y, normalized_points = point(surface, normalized_points)
// points.append((x, y))
// return extend_bounding_box(bounding_box, points)
//
//
// def bounding_box_path(surface, node):
// """Get the bounding box of a ``path`` node."""
// path_data = node.get('d', '')
//
// # Normalize path data for correct parsing
// for letter in PATH_LETTERS:
// path_data = path_data.replace(letter, ' {} '.format(letter))
// path_data = normalize(path_data)
//
// bounding_box = EMPTY_BOUNDING_BOX
// previous_x = 0
// previous_y = 0
// letter = 'M' # Move as default
// while path_data:
// path_data = path_data.strip()
// if path_data.split(' ', 1)[0] in PATH_LETTERS:
// letter, path_data = (path_data + ' ').split(' ', 1)
//
// if letter in 'aA':
// # Elliptical arc curve
// rx, ry, path_data = point(None, path_data)
// rotation, path_data = path_data.split(' ', 1)
// rotation = radians(float(rotation))
//
// # The large and sweep values are not always separated from the
// # following values, here is the crazy parser
// large, path_data = path_data[0], path_data[1:].strip()
// while not large[-1].isdigit():
// large, path_data = large + path_data[0], path_data[1:].strip()
// sweep, path_data = path_data[0], path_data[1:].strip()
// while not sweep[-1].isdigit():
// sweep, path_data = sweep + path_data[0], path_data[1:].strip()
//
// large, sweep = bool(int(large)), bool(int(sweep))
//
// x, y, path_data = point(None, path_data)
//
// # Relative coordinate, convert to absolute
// if letter == 'a':
// x += previous_x
// y += previous_y
//
// # Extend bounding box with start and end coordinates
// arc_bounding_box = bounding_box_elliptical_arc(
// previous_x, previous_y, rx, ry, rotation, large, sweep, x, y)
// x1, y1, width, height = arc_bounding_box
// x2 = x1 + width
// y2 = y1 + height
// points = (x1, y1), (x2, y2)
// bounding_box = extend_bounding_box(bounding_box, points)
// previous_x = x
// previous_y = y
//
// elif letter in 'cC':
// # Curve
// x1, y1, path_data = point(None, path_data)
// x2, y2, path_data = point(None, path_data)
// x, y, path_data = point(None, path_data)
//
// # Relative coordinates, convert to absolute
// if letter == 'c':
// x1 += previous_x
// y1 += previous_y
// x2 += previous_x
// y2 += previous_y
// x += previous_x
// y += previous_y
//
// # Extend bounding box with all coordinates
// bounding_box = extend_bounding_box(
// bounding_box, ((x1, y1), (x2, y2), (x, y)))
// previous_x = x
// previous_y = y
//
// elif letter in 'hH':
// # Horizontal line
// x, path_data = (path_data + ' ').split(' ', 1)
// x = size(surface, x, 'x')
//
// # Relative coordinate, convert to absolute
// if letter == 'h':
// x += previous_x
//
// # Extend bounding box with coordinate
// bounding_box = extend_bounding_box(
// bounding_box, ((x, previous_y),))
// previous_x = x
//
// elif letter in 'lLmMtT':
// # Line/Move/Smooth quadratic curve
// x, y, path_data = point(None, path_data)
//
// # Relative coordinate, convert to absolute
// if letter in 'lmt':
// x += previous_x
// y += previous_y
//
// # Extend bounding box with coordinate
// bounding_box = extend_bounding_box(bounding_box, ((x, y),))
// previous_x = x
// previous_y = y
//
// elif letter in 'qQsS':
// # Quadratic curve/Smooth curve
// x1, y1, path_data = point(None, path_data)
// x, y, path_data = point(None, path_data)
//
// # Relative coordinates, convert to absolute
// if letter in 'qs':
// x1 += previous_x
// y1 += previous_y
// x += previous_x
// y += previous_y
//
// # Extend bounding box with coordinates
// bounding_box = extend_bounding_box(
// bounding_box, ((x1, y1), (x, y)))
// previous_x = x
// previous_y = y
//
// elif letter in 'vV':
// # Vertical line
// y, path_data = (path_data + ' ').split(' ', 1)
// y = size(surface, y, 'y')
//
// # Relative coordinate, convert to absolute
// if letter == 'v':
// y += previous_y
//
// # Extend bounding box with coordinate
// bounding_box = extend_bounding_box(
// bounding_box, ((previous_x, y),))
// previous_y = y
//
// path_data = path_data.strip()
//
// return bounding_box
//
//
// def bounding_box_text(surface, node):
// """Get the bounding box of a ``text`` node."""
// return node.get('text_bounding_box')
//
//
// def angle(bx, by):
// """Get the angle between vector (1,0) and vector (bx,by)."""
// return fmod(
// 2 * pi + (1 if by > 0 else -1) * acos(bx / sqrt(bx * bx + by * by)),
// 2 * pi)
//
//
// def bounding_box_elliptical_arc(x1, y1, rx, ry, phi, large, sweep, x, y):
// """Get the bounding box of an elliptical arc described by the parameters.
//
// See following website for original code:
// http://fridrich.blogspot.nl/2011/06/bounding-box-of-svg-elliptical-arc.html
//
// """
// rx, ry = abs(rx), abs(ry)
// if rx == 0 or ry == 0:
// return min(x, x1), min(y, y1), abs(x - x1), abs(y - y1)
//
// x1prime = cos(phi) * (x1 - x) / 2 + sin(phi) * (y1 - y) / 2
// y1prime = -sin(phi) * (x1 - x) / 2 + cos(phi) * (y1 - y) / 2
//
// radicant = (
// rx ** 2 * ry ** 2 - rx ** 2 * y1prime ** 2 - ry ** 2 * x1prime ** 2)
// radicant /= rx ** 2 * y1prime ** 2 + ry ** 2 * x1prime ** 2
// cxprime = cyprime = 0
//
// if radicant < 0:
// ratio = rx / ry
// radicant = y1prime ** 2 + x1prime ** 2 / ratio ** 2
// if radicant < 0:
// return min(x, x1), min(y, y1), abs(x - x1), abs(y - y1)
// ry = sqrt(radicant)
// rx = ratio * ry
// else:
// factor = (-1 if large == sweep else 1) * sqrt(radicant)
//
// cxprime = factor * rx * y1prime / ry
// cyprime = -factor * ry * x1prime / rx
//
// cx = cxprime * cos(phi) - cyprime * sin(phi) + (x1 + x) / 2
// cy = cxprime * sin(phi) + cyprime * cos(phi) + (y1 + y) / 2
//
// if phi == 0 or phi == pi:
// minx = cx - rx
// tminx = angle(-rx, 0)
// maxx = cx + rx
// tmaxx = angle(rx, 0)
// miny = cy - ry
// tminy = angle(0, -ry)
// maxy = cy + ry
// tmaxy = angle(0, ry)
// elif phi == pi / 2 or phi == 3 * pi / 2:
// minx = cx - ry
// tminx = angle(-ry, 0)
// maxx = cx + ry
// tmaxx = angle(ry, 0)
// miny = cy - rx
// tminy = angle(0, -rx)
// maxy = cy + rx
// tmaxy = angle(0, rx)
// else:
// tminx = -atan(ry * tan(phi) / rx)
// tmaxx = pi - atan(ry * tan(phi) / rx)
// minx = cx + rx * cos(tminx) * cos(phi) - ry * sin(tminx) * sin(phi)
// maxx = cx + rx * cos(tmaxx) * cos(phi) - ry * sin(tmaxx) * sin(phi)
// if minx > maxx:
// minx, maxx = maxx, minx
// tminx, tmaxx = tmaxx, tminx
// tmp_y = cy + rx * cos(tminx) * sin(phi) + ry * sin(tminx) * cos(phi)
// tminx = angle(minx - cx, tmp_y - cy)
// tmp_y = cy + rx * cos(tmaxx) * sin(phi) + ry * sin(tmaxx) * cos(phi)
// tmaxx = angle(maxx - cx, tmp_y - cy)
//
// tminy = atan(ry / (tan(phi) * rx))
// tmaxy = atan(ry / (tan(phi) * rx)) + pi
// miny = cy + rx * cos(tminy) * sin(phi) + ry * sin(tminy) * cos(phi)
// maxy = cy + rx * cos(tmaxy) * sin(phi) + ry * sin(tmaxy) * cos(phi)
// if miny > maxy:
// miny, maxy = maxy, miny
// tminy, tmaxy = tmaxy, tminy
// tmp_x = cx + rx * cos(tminy) * cos(phi) - ry * sin(tminy) * sin(phi)
// tminy = angle(tmp_x - cx, miny - cy)
// tmp_x = cx + rx * cos(tmaxy) * cos(phi) - ry * sin(tmaxy) * sin(phi)
// tmaxy = angle(tmp_x - cx, maxy - cy)
//
// angle1 = angle(x1 - cx, y1 - cy)
// angle2 = angle(x - cx, y - cy)
//
// if not sweep:
// angle1, angle2 = angle2, angle1
//
// other_arc = False
// if angle1 > angle2:
// angle1, angle2 = angle2, angle1
// other_arc = True
//
// if ((not other_arc and (angle1 > tminx or angle2 < tminx)) or
// (other_arc and not (angle1 > tminx or angle2 < tminx))):
// minx = min(x, x1)
// if ((not other_arc and (angle1 > tmaxx or angle2 < tmaxx)) or
// (other_arc and not (angle1 > tmaxx or angle2 < tmaxx))):
// maxx = max(x, x1)
// if ((not other_arc and (angle1 > tminy or angle2 < tminy)) or
// (other_arc and not (angle1 > tminy or angle2 < tminy))):
// miny = min(y, y1)
// if ((not other_arc and (angle1 > tmaxy or angle2 < tmaxy)) or
// (other_arc and not (angle1 > tmaxy or angle2 < tmaxy))):
// maxy = max(y, y1)
//
// return minx, miny, maxx - minx, maxy - miny
//
//
// def bounding_box_group(surface, node):
// """Get the bounding box of a ``g`` node."""
// bounding_box = EMPTY_BOUNDING_BOX
// for child in node.children:
// bounding_box = combine_bounding_box(
// bounding_box, calculate_bounding_box(surface, child))
// return bounding_box
//
//
// def bounding_box_use(surface, node):
// """Get the bounding box of a ``use`` node."""
// href = parse_url(node.get_href()).geturl()
// tree = Tree(
// url=href, url_fetcher=node.url_fetcher, parent=node,
// unsafe=node.unsafe)
// if not match_features(tree.xml_tree):
// return None
// return calculate_bounding_box(surface, tree)
//
//
// def extend_bounding_box(bounding_box, points):
// """Extend the ``bounding_box`` by the points."""
// minx, miny, width, height = bounding_box
// maxx, maxy = (
// float('-inf') if isinf(minx) else minx + width,
// float('-inf') if isinf(miny) else miny + height)
// x_list, y_list = zip(*points)
// minx, miny, maxx, maxy = (
// min(minx, *x_list), min(miny, *y_list),
// max(maxx, *x_list), max(maxy, *y_list))
// return minx, miny, maxx - minx, maxy - miny
//
//
// def combine_bounding_box(bounding_box, another_bounding_box):
// """Combine the ``bounding_box`` with ``another_bounding_box``."""
// if is_valid_bounding_box(another_bounding_box):
// minx, miny, width, height = another_bounding_box
// maxx, maxy = minx + width, miny + height
// bounding_box = extend_bounding_box(
// bounding_box, ((minx, miny), (maxx, maxy)))
// return bounding_box
//
//
// def is_valid_bounding_box(bounding_box):
// """Know whether bounding box has been initialized."""
// # If 'minx' or 'miny' is set, 'maxx' and 'maxy' will also be set (resulting
// # in a valid bounding box)
// return bounding_box and not isinf(bounding_box[0] + bounding_box[1])
//
//
// def is_non_empty_bounding_box(bounding_box):
// """Know whether bounding box is valid and has a size."""
// return is_valid_bounding_box(bounding_box) and 0 not in bounding_box[2:]
//
//
// BOUNDING_BOX_METHODS = {
// 'rect': bounding_box_rect,
// 'circle': bounding_box_circle,
// 'ellipse': bounding_box_ellipse,
// 'line': bounding_box_line,
// 'polyline': bounding_box_polyline,
// 'polygon': bounding_box_polyline,
// 'path': bounding_box_path,
// 'text': bounding_box_text,
// 'tspan': bounding_box_text,
// 'textPath': bounding_box_text,
// 'g': bounding_box_group,
// 'use': bounding_box_use,
// 'marker': bounding_box_group,
// }
};
}
}
}
#endif /* BoundingBox_h */
...@@ -7,9 +7,7 @@ configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile) ...@@ -7,9 +7,7 @@ configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile)
add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(doc doc_${PROJECT_NAME}) add_dependencies(doc doc_${PROJECT_NAME})
link_libraries(${X11_LIBRARIES})
add_executable(${PROJECT_NAME} NUtils.cpp NWMAction.cpp NWManager.cpp main.cpp) add_executable(${PROJECT_NAME} NUtils.cpp NWMAction.cpp NWManager.cpp main.cpp)
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${BoehmGC} nde) target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${BoehmGC} ${X11_LIBRARIES} nde)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
...@@ -7,11 +7,6 @@ configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile) ...@@ -7,11 +7,6 @@ configure_file(${CMAKE_BINARY_DIR}/Doxyfile.in Doxyfile)
add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(doc_${PROJECT_NAME} COMMAND doxygen Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(doc doc_${PROJECT_NAME}) add_dependencies(doc doc_${PROJECT_NAME})
find_package(X11)
find_library(BoehmGC gc-threaded)
find_library(Cairo cairo)
find_library(CairoMM cairomm)
add_library(${PROJECT_NAME} SHARED ntkMain.cpp add_library(${PROJECT_NAME} SHARED ntkMain.cpp
nitrogen/Object.cpp nitrogen/Object.cpp
nitrogen/nwt/ActionEvent.cpp nitrogen/nwt/ActionEvent.cpp
......
...@@ -41,10 +41,10 @@ namespace nitrogen { ...@@ -41,10 +41,10 @@ namespace nitrogen {
} }
std::string* Object::toString() { std::string* Object::toString() {
std::string* out std::string* out;
out->append(getTypeName(*this)); out->append(getTypeName(*this));
out->append("("); out->append("(");
out->append(std::to_string((uintptr_t)*this)); out->append(std::to_string((uintptr_t)this));
out->append(")"); out->append(")");
return out; return out;
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "NativeGraphics.h" #include "NativeGraphics.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <typeinfo>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
...@@ -48,13 +49,13 @@ namespace nitrogen { ...@@ -48,13 +49,13 @@ namespace nitrogen {
width = 32; width = 32;
height = 32; height = 32;
std::string* fnt = std::string("serif"); std::string* fnt = new std::string("serif");
font = new Font(fnt, 12, 12); font = new Font(fnt, 12, 12);
color = new Color(0,0,0); color = new Color(0,0,0);
xdisp = XOpenDisplay(nullptr); xdisp = XOpenDisplay(nullptr);
xdraw = XCreateSimpleWindow(xdisp, DefaultRootWindow(xdisp), tx, ty, width, height, 0, 0, 0); xdraw = nullptr; //XCreateSimpleWindow(xdisp, DefaultRootWindow(xdisp), tx, ty, width, height, 0, 0, 0);
xgc = XCreateGC(xdisp, 0, 0, nullptr); xgc = nullptr; //XCreateGC(xdisp, 0, 0, nullptr);
} }
NativeGraphics::NativeGraphics(NativeGraphics& ng) { NativeGraphics::NativeGraphics(NativeGraphics& ng) {
...@@ -105,7 +106,7 @@ namespace nitrogen { ...@@ -105,7 +106,7 @@ namespace nitrogen {
} }
void NativeGraphics::drawString(std::string* str, int x, int y) { void NativeGraphics::drawString(std::string* str, int x, int y) {
XDrawString(xdisp, xdraw, xgc, x, y, str->c_str(), str->length()); //XDrawString(xdisp, xdraw, xgc, x, y, str->c_str(), str->length());
} }
void NativeGraphics::drawString(std::string& str, int x, int y) { void NativeGraphics::drawString(std::string& str, int x, int y) {
...@@ -163,12 +164,21 @@ namespace nitrogen { ...@@ -163,12 +164,21 @@ namespace nitrogen {
// overrides // overrides
NativeGraphics& NativeGraphics::operator()() { NativeGraphics& NativeGraphics::operator()() {
NativeGraphics* ng = new NativeGraphics(); NativeGraphics* ng = new NativeGraphics();
return ng; return *ng;
}
Graphics& NativeGraphics::operator=(Graphics& right) {
const char * tid_l = typeid(this).name();
const char * tid_r = typeid(right).name();
if (std::strcmp(tid_l, tid_r)) {
return (Graphics&)operator=((NativeGraphics&)right);
}
return right;
} }
NativeGraphics& NativeGraphics::operator=(NativeGraphics& right) { NativeGraphics& NativeGraphics::operator=(NativeGraphics& right) {
if (*this != right) { if (*this != right) {
*mask = *right.mask; mask = right.mask;
cx = right.cx; cx = right.cx;
cy = right.cy; cy = right.cy;
tx = right.tx; tx = right.tx;
...@@ -176,18 +186,27 @@ namespace nitrogen { ...@@ -176,18 +186,27 @@ namespace nitrogen {
width = right.width; width = right.width;
height = right.height; height = right.height;
*font = *right.font; font = right.font;
*color = *right.color; color = right.color;
*xdisp = *right.xdisp; xdisp = right.xdisp;
*xdraw = *right.xdraw; xdraw = right.xdraw;
*xgc = *right.xgc; xgc = right.xgc;
} }
return *this; return *this;
} }
//bool operator!=(Graphics& right)
bool NativeGraphics::operator==(Graphics& right) {
const char * tid_l = typeid(this).name();
const char * tid_r = typeid(right).name();
if (std::strcmp(tid_l, tid_r)) {
return operator==((NativeGraphics&)right);
}
return false;
}
bool NativeGraphics::operator==(NativeGraphics& right) { bool NativeGraphics::operator==(NativeGraphics& right) {
if ( *mask != *right.mask ) { return false; } if ( mask != right.mask ) { return false; }
if ( cx != right.cx ) { return false; } if ( cx != right.cx ) { return false; }
if ( cy != right.cy ) { return false; } if ( cy != right.cy ) { return false; }
if ( tx != right.tx ) { return false; } if ( tx != right.tx ) { return false; }
...@@ -198,9 +217,9 @@ namespace nitrogen { ...@@ -198,9 +217,9 @@ namespace nitrogen {
if ( *font != *right.font ) { return false; } if ( *font != *right.font ) { return false; }
if ( *color != *right.color ) { return false; } if ( *color != *right.color ) { return false; }
if ( *xdisp != *right.xdisp ) { return false; } if ( xdisp != right.xdisp ) { return false; }
if ( *xdraw != *right.xdraw ) { return false; } if ( xdraw != right.xdraw ) { return false; }
if ( *xgc != *right.xgc ) { return false; } if ( xgc != right.xgc ) { return false; }
return true; return true;
} }
......
...@@ -72,9 +72,10 @@ namespace nitrogen { ...@@ -72,9 +72,10 @@ namespace nitrogen {
//std::string* toString(); //std::string* toString();
NativeGraphics& operator()() override; NativeGraphics& operator()() override;
NativeGraphics& operator=(NativeGraphics& right) override; Graphics& operator=(Graphics& right) override;
//bool operator!=(NativeGraphics& right); NativeGraphics& operator=(NativeGraphics& right);
bool operator==(NativeGraphics& right) override; bool operator==(Graphics& right) override;
bool operator==(NativeGraphics& right);
protected: protected:
unsigned long mask; unsigned long mask;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!