PDF4QT/Pdf4QtLib/sources/pdfglobal.h

177 lines
4.5 KiB
C
Raw Normal View History

2021-04-30 20:12:10 +02:00
// Copyright (C) 2018-2021 Jakub Melka
2018-11-17 16:48:30 +01:00
//
2021-08-10 19:22:56 +02:00
// This file is part of PDF4QT.
2018-11-17 16:48:30 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is free software: you can redistribute it and/or modify
2018-11-17 16:48:30 +01:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
2021-04-30 20:12:10 +02:00
// with the written consent of the copyright owner, any later version.
2018-11-17 16:48:30 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is distributed in the hope that it will be useful,
2018-11-17 16:48:30 +01:00
// 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.
//
// You should have received a copy of the GNU Lesser General Public License
2021-08-10 19:22:56 +02:00
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
2018-11-17 16:48:30 +01:00
#ifndef PDFGLOBAL_H
#define PDFGLOBAL_H
2018-12-14 19:41:12 +01:00
#include <QtCore>
2018-11-17 16:48:30 +01:00
#include <QtGlobal>
#include <limits>
#include <tuple>
2021-01-14 19:33:23 +01:00
#include <array>
2018-11-17 16:48:30 +01:00
2021-08-10 19:22:56 +02:00
#if defined(PDF4QTLIB_LIBRARY)
# define PDF4QTLIBSHARED_EXPORT Q_DECL_EXPORT
2018-11-17 16:48:30 +01:00
#else
2021-08-10 19:22:56 +02:00
# define PDF4QTLIBSHARED_EXPORT Q_DECL_IMPORT
2018-11-17 16:48:30 +01:00
#endif
namespace pdf
{
using PDFInteger = int64_t;
using PDFReal = double;
2021-01-14 19:33:23 +01:00
using PDFColorComponent = float;
using PDFGray = PDFColorComponent;
using PDFRGB = std::array<PDFColorComponent, 3>;
using PDFCMYK = std::array<PDFColorComponent, 4>;
2018-11-17 16:48:30 +01:00
// These constants define minimum/maximum integer and are defined in such a way,
// that even 100 times bigger integers are representable.
constexpr PDFInteger PDF_INTEGER_MIN = std::numeric_limits<int64_t>::min() / 100;
constexpr PDFInteger PDF_INTEGER_MAX = std::numeric_limits<int64_t>::max() / 100;
2019-08-31 14:37:18 +02:00
constexpr PDFReal PDF_EPSILON = 0.000001;
2018-11-17 16:48:30 +01:00
static constexpr bool isValidInteger(PDFInteger integer)
{
return integer >= PDF_INTEGER_MIN && integer <= PDF_INTEGER_MAX;
}
2019-08-31 14:37:18 +02:00
static inline bool isZero(PDFReal value)
{
return std::fabs(value) < PDF_EPSILON;
}
2018-11-17 16:48:30 +01:00
/// This structure represents a reference to the object - consisting of the
/// object number, and generation number.
struct PDFObjectReference
{
constexpr inline PDFObjectReference() :
objectNumber(0),
generation(0)
{
}
constexpr inline PDFObjectReference(PDFInteger objectNumber, PDFInteger generation) :
objectNumber(objectNumber),
generation(generation)
{
}
PDFInteger objectNumber;
PDFInteger generation;
constexpr bool operator==(const PDFObjectReference& other) const
{
return objectNumber == other.objectNumber && generation == other.generation;
}
constexpr bool operator!=(const PDFObjectReference& other) const { return !(*this == other); }
constexpr bool operator<(const PDFObjectReference& other) const
{
return std::tie(objectNumber, generation) < std::tie(other.objectNumber, other.generation);
}
2020-03-07 17:38:50 +01:00
constexpr bool isValid() const { return objectNumber > 0; }
2018-11-17 16:48:30 +01:00
};
/// Represents version identification
struct PDFVersion
{
constexpr explicit PDFVersion() = default;
constexpr explicit PDFVersion(uint16_t major, uint16_t minor) :
major(major),
minor(minor)
{
}
uint16_t major = 0;
uint16_t minor = 0;
bool isValid() const { return major > 0; }
};
2018-12-14 19:41:12 +01:00
struct PDFTranslationContext
{
Q_DECLARE_TR_FUNCTIONS(pdf::PDFTranslationContext)
};
2019-01-20 17:55:06 +01:00
constexpr PDFReal PDF_POINT_TO_INCH = 1.0 / 72.0;
2019-01-27 17:55:22 +01:00
constexpr PDFReal PDF_INCH_TO_MM = 25.4; // [mm / inch]
constexpr PDFReal PDF_POINT_TO_MM = PDF_POINT_TO_INCH * PDF_INCH_TO_MM;
constexpr PDFReal PDF_MM_TO_POINT = 1.0 / PDF_POINT_TO_MM;
2019-01-27 17:55:22 +01:00
/// This is default "DPI", but in milimeters, so the name is DPMM (device pixel per milimeter)
constexpr PDFReal PDF_DEFAULT_DPMM = 96.0 / PDF_INCH_TO_MM;
2019-01-20 17:55:06 +01:00
constexpr PDFReal convertPDFPointToMM(PDFReal point)
{
return point * PDF_POINT_TO_MM;
}
constexpr PDFReal convertMMToPDFPoint(PDFReal point)
{
return point * PDF_MM_TO_POINT;
}
2019-01-27 17:55:22 +01:00
class PDFBoolGuard final
{
public:
inline explicit PDFBoolGuard(bool& value) :
m_value(value),
m_oldValue(value)
{
m_value = true;
}
inline ~PDFBoolGuard()
{
m_value = m_oldValue;
}
private:
bool& m_value;
bool m_oldValue;
};
2019-09-06 19:07:52 +02:00
enum class RendererEngine
{
Software,
OpenGL
};
2019-10-04 17:21:26 +02:00
enum class RenderingIntent
{
Auto, ///< Rendering intent is automatically selected
2019-10-04 17:21:26 +02:00
Perceptual,
AbsoluteColorimetric,
RelativeColorimetric,
Saturation,
Unknown
};
2018-11-17 16:48:30 +01:00
} // namespace pdf
#endif // PDFGLOBAL_H