2012-04-29 18:52:25 +00:00

172 lines
4.1 KiB
C++

//
// Font.h
//
// $Id: //poco/Main/PDF/include/Poco/PDF/Font.h#4 $
//
// Library: PDF
// Package: PDFCore
// Module: Font
//
// Definition of the Font class.
//
// 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.
//
#ifndef PDF_Font_INCLUDED
#define PDF_Font_INCLUDED
#include "Poco/PDF/PDF.h"
#include "Poco/PDF/Resource.h"
namespace Poco {
namespace PDF {
class PDF_API Font: public Resource<HPDF_Font>
/// Font class represents font resource.
{
public:
Font(HPDF_Doc* pPDF, const HPDF_Font& resource);
/// Creates the font.
~Font();
/// Destroys the font.
std::string encodingName() const;
/// Returns the name of the encoding.
int unicodeWidth(Poco::UInt16 ch) const;
/// Returns the screen width of 16-bit Unicode character.
Rectangle boundingBox() const;
/// Returns the font's bounding box.
int ascent() const;
/// Returns the vertical ascent of the font.
int descent() const;
/// Returns the vertical ascent of the font.
int lowerHeight() const;
/// Returns the distance from the baseline of lowercase letters.
int upperHeight() const;
/// Returns the distance from the baseline of uppercase letters.
TextWidth textWidth(const std::string& text);
/// Returns total width of the text, number of characters and number of the words.
int measureText(const std::string& text,
float width,
float fontSize,
float charSpace,
float wordSpace,
bool wordWrap);
/// Calculates the byte length which can be included within the specified width.
};
//
// inlines
//
inline std::string Font::encodingName() const
{
return HPDF_Font_GetEncodingName(handle());
}
inline int Font::unicodeWidth(Poco::UInt16 ch) const
{
return HPDF_Font_GetUnicodeWidth(handle(), ch);
}
inline Rectangle Font::boundingBox() const
{
return HPDF_Font_GetBBox(handle());
}
inline int Font::ascent() const
{
return HPDF_Font_GetAscent(handle());
}
inline int Font::descent() const
{
return HPDF_Font_GetDescent(handle());
}
inline int Font::lowerHeight() const
{
return static_cast<int>(HPDF_Font_GetXHeight(handle()));
}
inline int Font::upperHeight() const
{
return static_cast<int>(HPDF_Font_GetCapHeight(handle()));
}
inline TextWidth Font::textWidth(const std::string& text)
{
return HPDF_Font_TextWidth(handle(),
reinterpret_cast<const HPDF_BYTE*>(text.data()),
static_cast<HPDF_UINT>(text.size()));
}
inline int Font::measureText(const std::string& text,
float width,
float fontSize,
float charSpace,
float wordSpace,
bool wordWrap)
{
return static_cast<int>(HPDF_Font_MeasureText(handle(),
reinterpret_cast<const HPDF_BYTE*>(text.data()),
static_cast<HPDF_UINT>(text.size()),
width,
fontSize,
charSpace,
wordSpace,
wordWrap,
0));
}
} } // namespace Poco::PDF
#endif // PDF_Font_INCLUDED