// // Page.cpp // // $Id: //poco/Main/PDF/src/Page.cpp#2 $ // // Library: PDF // Package: PDFCore // Module: Page // // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // and Contributors. // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // #include "Poco/PDF/Page.h" #include "Poco/PDF/PDFException.h" #include namespace Poco { namespace PDF { Page::Page(HPDF_Doc* pPDF, const HPDF_Page& page, Size pageSize, Orientation orientation): _pPDF(pPDF), _page(page), _size(pageSize), _orientation(orientation), _pCurrentFont(0) { } Page::Page(const Page& other): _pPDF(other._pPDF), _page(other._page), _size(other._size), _orientation(other._orientation) { } Page::~Page() { } Page& Page::operator = (const Page& page) { Page tmp(page); swap(tmp); return *this; } void Page::swap(Page& other) { using std::swap; swap(_pPDF, other._pPDF); swap(_page, other._page); swap(_size, other._size); swap(_orientation, other._orientation); } void Page::writeOnce(float xPos, float yPos, const std::string& text) { beginText(); write(xPos, yPos, text); endText(); } int Page::writeOnceInRectangle(float left, float top, float right, float bottom, const std::string& text, TextAlignment align) { beginText(); int ret = writeInRectangle(left, top, right, bottom, text, align); endText(); return ret; } float Page::textWidth(const std::string& text) { return HPDF_Page_TextWidth(_page, text.c_str()); } void Page::setRotation(int angle) { if (0 != angle % 90 || angle > std::numeric_limits::max()) throw InvalidArgumentException("Invalid angle value."); HPDF_Page_SetRotate(_page, static_cast(angle)); } const Destination& Page::createDestination(const std::string& name) { DestinationContainer::iterator it = _destinations.find(name); if (_destinations.end() == it) throw InvalidArgumentException("Destination already exists."); Destination dest(_pPDF, HPDF_Page_CreateDestination(_page), name); std::pair ret = _destinations.insert(DestinationContainer::value_type(name, dest)); if (ret.second) return ret.first->second; throw IllegalStateException("Could not create destination."); } const TextAnnotation& Page::createTextAnnotation(const std::string& name, const Rectangle& rect, const std::string& text, const Encoder& encoder) { TextAnnotationContainer::iterator it = _textAnnotations.find(name); if (_textAnnotations.end() == it) throw InvalidArgumentException("Annotation already exists."); TextAnnotation ann(_pPDF, HPDF_Page_CreateTextAnnot(_page, rect, text.c_str(), encoder), name); std::pair ret = _textAnnotations.insert(TextAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; throw IllegalStateException("Could not create annotation."); } const LinkAnnotation& Page::createLinkAnnotation(const std::string& name, const Rectangle& rect, const Destination& dest) { LinkAnnotationContainer::iterator it = _linkAnnotations.find(name); if (_linkAnnotations.end() == it) throw InvalidArgumentException("Annotation already exists."); LinkAnnotation ann(_pPDF, HPDF_Page_CreateLinkAnnot(_page, rect, dest), name); std::pair ret = _linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; throw IllegalStateException("Could not create annotation."); } const LinkAnnotation& Page::createURILinkAnnotation(const std::string& name, const Rectangle& rect, const std::string& uri) { LinkAnnotationContainer::iterator it = _linkAnnotations.find(name); if (_linkAnnotations.end() == it) throw InvalidArgumentException("Annotation already exists."); LinkAnnotation ann(_pPDF, HPDF_Page_CreateURILinkAnnot(_page, rect, uri.c_str()), name); std::pair ret = _linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; throw IllegalStateException("Could not create annotation."); } } } // namespace Poco::PDF