Skip to content

Commit

Permalink
Merge branch 'experimental/freetype' into autobuild/freetype
Browse files Browse the repository at this point in the history
  • Loading branch information
c-lipka committed Jan 17, 2019
2 parents 744a48c + eb30e26 commit 617efbf
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 53 deletions.
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ New Features
- The parser now checks for proper balancing of `#end` directives, braces,
parentheses etc. within each include file, and will report any imbalance
via warnings or, in case of `#end`, outright errors.
- The `text` object now supports file formats other than TrueType.
- The `text` syntax has been extended to specify installed fonts without
knowing their actual file name or location (currently Windows only).

Performance Improvements
------------------------
Expand Down
67 changes: 67 additions & 0 deletions platform/unix/osfontresolver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//******************************************************************************
///
/// @file platform/unix/osfontresolver.cpp
///
/// Unix-specific implementation of the @ref pov_base::OSFontResolver class.
///
/// @copyright
/// @parblock
///
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
///
/// POV-Ray is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// POV-Ray is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// ----------------------------------------------------------------------------
///
/// POV-Ray is based on the popular DKB raytracer version 2.12.
/// DKBTrace was originally written by David K. Buck.
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
///
/// @endparblock
///
//******************************************************************************

// Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config)
#include "osfontresolver.h"

// POV-Ray header files (parser module)
#include "parser/parsertypes.h"

// this must be the last file included
#include "base/povdebug.h"

namespace pov_base
{

using namespace pov_parser;

class UnixFontResolver final : public FontResolver
{
public:
virtual FontReferencePtr GetFont(const UCS2String& name, FontStyle style) override;
};

FontReferencePtr UnixFontResolver::GetFont(const UCS2String& name, FontStyle style)
{
return nullptr;
}

FontResolver& OSGetFontResolver()
{
thread_local UnixFontResolver fontResolverInstance;
return fontResolverInstance;
}

} // end of namespace pov_base
51 changes: 51 additions & 0 deletions platform/unix/osfontresolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//******************************************************************************
///
/// @file platform/unix/osfontresolver.h
///
/// Unix-specific declaration of the @ref pov_base::OSFontResolver class.
///
/// @copyright
/// @parblock
///
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
///
/// POV-Ray is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// POV-Ray is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// ----------------------------------------------------------------------------
///
/// POV-Ray is based on the popular DKB raytracer version 2.12.
/// DKBTrace was originally written by David K. Buck.
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
///
/// @endparblock
///
//******************************************************************************

#ifndef POVRAY_UNIX_OSFONTRESOLVER_H
#define POVRAY_UNIX_OSFONTRESOLVER_H

#include "base/configbase.h"

namespace pov_parser
{
class FontResolver;
}

namespace pov_base
{
pov_parser::FontResolver& OSGetFontResolver();
}

#endif // POVRAY_UNIX_OSFONTRESOLVER_H
120 changes: 120 additions & 0 deletions platform/windows/osfontresolver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//******************************************************************************
///
/// @file platform/windows/osfontresolver.cpp
///
/// Windows-specific implementation of the @ref pov_base::OSFontResolver class.
///
/// @copyright
/// @parblock
///
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
///
/// POV-Ray is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// POV-Ray is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// ----------------------------------------------------------------------------
///
/// POV-Ray is based on the popular DKB raytracer version 2.12.
/// DKBTrace was originally written by David K. Buck.
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
///
/// @endparblock
///
//******************************************************************************

// Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config)
#include "osfontresolver.h"

// C++ standard header files
#include <vector>

// platform-specific library headers
#include <windows.h>

// POV-Ray header files (parser module)
#include "parser/font.h"
#include "parser/parsertypes.h"

// this must be the last file included
#include "base/povdebug.h"

namespace pov_base
{

using namespace pov_parser;

class WindowsFontResolver final : public FontResolver
{
public:
virtual FontReferencePtr GetFont(const UCS2String& name, FontStyle style) override;
};

FontReferencePtr WindowsFontResolver::GetFont(const UCS2String& name, FontStyle style)
{
if (name.length() >= LF_FACESIZE)
// Too long to be a valid system font name.
return nullptr;

char* buffer = nullptr;

HDC hdc = CreateCompatibleDC(nullptr);
if (hdc == nullptr)
; // TODO throw tantrum

bool bold = ((style & FontStyle::kBold) != FontStyle::kRegular);
bool italic = ((style & FontStyle::kItalic) != FontStyle::kRegular);
int weight = (bold ? 700 : 400);

HFONT fontHandle = CreateFontW(
0, // cHeight
0, // cWidth
0, // cEscapement
0, // cOrientation
(int)weight, // cWeight
(DWORD)italic, // bItalic
FALSE, // bUnderline
FALSE, // bStrikeOut
DEFAULT_CHARSET, // iCharSet
OUT_DEFAULT_PRECIS, // iOutPrecision
CLIP_DEFAULT_PRECIS, // iClipPrecision
DEFAULT_QUALITY, // iQuality
DEFAULT_PITCH | FF_DONTCARE, // iPitchAndFamily
(LPCWSTR)name.c_str() // pszFaceName
);

SelectObject(hdc, fontHandle);
auto size = ::GetFontData(hdc, 0, 0, nullptr, 0);

if (size == 0)
return nullptr;

buffer = new char[size];
if (GetFontData(hdc, 0, 0, buffer, size) != size)
{
delete[] buffer;
return nullptr;
}

DeleteDC(hdc);

return std::make_shared<BufferedFontFile>(buffer, size, BufferedFontFile::Mode::kTransferOwnership);
}

FontResolver& OSGetFontResolver()
{
thread_local WindowsFontResolver fontResolverInstance;
return fontResolverInstance;
}

} // end of namespace pov_base
51 changes: 51 additions & 0 deletions platform/windows/osfontresolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//******************************************************************************
///
/// @file platform/windows/osfontresolver.h
///
/// Windows-specific declaration of the @ref pov_base::OSFontResolver class.
///
/// @copyright
/// @parblock
///
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
///
/// POV-Ray is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License, or (at your option) any later version.
///
/// POV-Ray is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// ----------------------------------------------------------------------------
///
/// POV-Ray is based on the popular DKB raytracer version 2.12.
/// DKBTrace was originally written by David K. Buck.
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
///
/// @endparblock
///
//******************************************************************************

#ifndef POVRAY_WINDOWS_OSFONTRESOLVER_H
#define POVRAY_WINDOWS_OSFONTRESOLVER_H

#include "base/configbase.h"

namespace pov_parser
{
class FontResolver;
}

namespace pov_base
{
pov_parser::FontResolver& OSGetFontResolver();
}

#endif // POVRAY_WINDOWS_OSFONTRESOLVER_H
31 changes: 31 additions & 0 deletions source/base/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <algorithm>
#include <limits>
#include <string>
#include <type_traits>
#include <vector>

#include "base/pov_mem.h"
Expand Down Expand Up @@ -405,6 +406,36 @@ class ThreadData
virtual ~ThreadData() { }
};

//------------------------------------------------------------------------------

/// Cast enum to underlying type.
template<typename T>
inline typename std::underlying_type<T>::type underlying_cast(T value)
{
return static_cast<typename std::underlying_type<T>::type>(value);
}

/// Apply bitwise OR to scoped enum.
template<typename T>
inline T EnumOr(T a, T b)
{
return static_cast<T>(underlying_cast(a) | underlying_cast(b));
}

/// Apply bitwise AND to scoped enum.
template<typename T>
inline T EnumAnd(T a, T b)
{
return static_cast<T>(underlying_cast(a) & underlying_cast(b));
}

/// Apply bitwise NOT to scoped enum.
template<typename T>
inline T EnumNot(T a)
{
return static_cast<T>(~underlying_cast(a));
}

/// @}
///
//##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion source/base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
/// where `N` is a serial number starting at 1 in each phase, `TIME` is the number of minutes
/// since 2000-01-01 00:00, and `FEATURE` is an arbitrary alphanumeric moniker for a particular
/// experimental feature.
#define POV_RAY_PRERELEASE "x.freetype.1"
#define POV_RAY_PRERELEASE "x.freetype.2"

#if defined(DOXYGEN) && !defined(POV_RAY_PRERELEASE)
// Work around doxygen being unable to document undefined macros.
Expand Down
Loading

0 comments on commit 617efbf

Please sign in to comment.