SharpFont + ScalableFont implementation

https://github.com/Robmaister/SharpFont

TODO: replace Code Bold.otf with the full version, fix any bugs, build on Linux, possibly move ToolBox string wrapping and limiting logic to ScalableFont class for better results.
This commit is contained in:
juanjp600
2017-03-07 13:44:42 -03:00
parent 88a76f0c9f
commit d6c292a2cc
231 changed files with 28528 additions and 94 deletions

52
SharpFont/.gitignore vendored Normal file
View File

@@ -0,0 +1,52 @@
#Output Directory
/[Bb]inaries
#OS junk files
[Tt]humbs.db
*.DS_Store
#Visual Studio files
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
#Subversion files
.svn
# Office Temp Files
~$*
#MonoDevelop files
*.userprefs
*.pidb
#NuGet
*.nupkg

4
SharpFont/.gitmodules vendored Normal file
View File

@@ -0,0 +1,4 @@
[submodule "Dependencies"]
path = Dependencies
url = https://github.com/Robmaister/SharpFont.Dependencies.git
ignore = dirty

View File

@@ -0,0 +1,5 @@
# Notes about these builds
These builds are statically linked with Zlib 1.2.8, LibPNG 1.6.16, BZip2 1.0.6, and HarfBuzz 0.9.36 (From the ShiftMedia Project).
The Freetype sources were patched with the fttypes-h-win32.patch file in the patches directory. This patch changes the fttypes.h file's usage of long to __int64 on Windows.

View File

@@ -0,0 +1,58 @@
--- .\freetype-2.5.4\include\fttypes.h Tue Dec 2 07:12:12 2014
+++ .\freetype-2.5.4-patched\include\fttypes.h Sun Dec 28 13:54:21 2014
@@ -239,9 +239,12 @@
/* <Description> */
/* A typedef for signed long. */
/* */
+#ifdef _WIN32
+ typedef signed __int64 FT_Long;
+#else
typedef signed long FT_Long;
+#endif
-
/*************************************************************************/
/* */
/* <Type> */
@@ -250,9 +253,12 @@
/* <Description> */
/* A typedef for unsigned long. */
/* */
+#ifdef _WIN32
+ typedef unsigned __int64 FT_ULong;
+#else
typedef unsigned long FT_ULong;
+#endif
-
/*************************************************************************/
/* */
/* <Type> */
@@ -273,9 +279,12 @@
/* A signed 26.6 fixed-point type used for vectorial pixel */
/* coordinates. */
/* */
+#ifdef _WIN32
+ typedef signed __int64 FT_F26Dot6;
+#else
typedef signed long FT_F26Dot6;
+#endif
-
/*************************************************************************/
/* */
/* <Type> */
@@ -285,9 +294,12 @@
/* This type is used to store 16.16 fixed-point values, like scaling */
/* values or matrix coefficients. */
/* */
+#ifdef _WIN32
+ typedef signed __int64 FT_Fixed;
+#else
typedef signed long FT_Fixed;
+#endif
-
/*************************************************************************/
/* */
/* <Type> */

View File

@@ -0,0 +1,5 @@
# Notes about these builds
These builds are statically linked with Zlib 1.2.8, LibPNG 1.6.16, BZip2 1.0.6, and HarfBuzz 0.9.36 (From the ShiftMedia Project).
The Freetype sources were patched with the fttypes-h-win32.patch file in the ../2.5.4-alldeps/patches directory. This patch changes the fttypes.h file's usage of long to __int64 on Windows.

View File

@@ -0,0 +1,169 @@
The FreeType Project LICENSE
----------------------------
2006-Jan-27
Copyright 1996-2002, 2006 by
David Turner, Robert Wilhelm, and Werner Lemberg
Introduction
============
The FreeType Project is distributed in several archive packages;
some of them may contain, in addition to the FreeType font engine,
various tools and contributions which rely on, or relate to, the
FreeType Project.
This license applies to all files found in such packages, and
which do not fall under their own explicit license. The license
affects thus the FreeType font engine, the test programs,
documentation and makefiles, at the very least.
This license was inspired by the BSD, Artistic, and IJG
(Independent JPEG Group) licenses, which all encourage inclusion
and use of free software in commercial and freeware products
alike. As a consequence, its main points are that:
o We don't promise that this software works. However, we will be
interested in any kind of bug reports. (`as is' distribution)
o You can use this software for whatever you want, in parts or
full form, without having to pay us. (`royalty-free' usage)
o You may not pretend that you wrote this software. If you use
it, or only parts of it, in a program, you must acknowledge
somewhere in your documentation that you have used the
FreeType code. (`credits')
We specifically permit and encourage the inclusion of this
software, with or without modifications, in commercial products.
We disclaim all warranties covering The FreeType Project and
assume no liability related to The FreeType Project.
Finally, many people asked us for a preferred form for a
credit/disclaimer to use in compliance with this license. We thus
encourage you to use the following text:
"""
Portions of this software are copyright © <year> The FreeType
Project (www.freetype.org). All rights reserved.
"""
Please replace <year> with the value from the FreeType version you
actually use.
Legal Terms
===========
0. Definitions
--------------
Throughout this license, the terms `package', `FreeType Project',
and `FreeType archive' refer to the set of files originally
distributed by the authors (David Turner, Robert Wilhelm, and
Werner Lemberg) as the `FreeType Project', be they named as alpha,
beta or final release.
`You' refers to the licensee, or person using the project, where
`using' is a generic term including compiling the project's source
code as well as linking it to form a `program' or `executable'.
This program is referred to as `a program using the FreeType
engine'.
This license applies to all files distributed in the original
FreeType Project, including all source code, binaries and
documentation, unless otherwise stated in the file in its
original, unmodified form as distributed in the original archive.
If you are unsure whether or not a particular file is covered by
this license, you must contact us to verify this.
The FreeType Project is copyright (C) 1996-2000 by David Turner,
Robert Wilhelm, and Werner Lemberg. All rights reserved except as
specified below.
1. No Warranty
--------------
THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO
USE, OF THE FREETYPE PROJECT.
2. Redistribution
-----------------
This license grants a worldwide, royalty-free, perpetual and
irrevocable right and license to use, execute, perform, compile,
display, copy, create derivative works of, distribute and
sublicense the FreeType Project (in both source and object code
forms) and derivative works thereof for any purpose; and to
authorize others to exercise some or all of the rights granted
herein, subject to the following conditions:
o Redistribution of source code must retain this license file
(`FTL.TXT') unaltered; any additions, deletions or changes to
the original files must be clearly indicated in accompanying
documentation. The copyright notices of the unaltered,
original files must be preserved in all copies of source
files.
o Redistribution in binary form must provide a disclaimer that
states that the software is based in part of the work of the
FreeType Team, in the distribution documentation. We also
encourage you to put an URL to the FreeType web page in your
documentation, though this isn't mandatory.
These conditions apply to any software derived from or based on
the FreeType Project, not just the unmodified files. If you use
our work, you must acknowledge us. However, no fee need be paid
to us.
3. Advertising
--------------
Neither the FreeType authors and contributors nor you shall use
the name of the other for commercial, advertising, or promotional
purposes without specific prior written permission.
We suggest, but do not require, that you use one or more of the
following phrases to refer to this software in your documentation
or advertising materials: `FreeType Project', `FreeType Engine',
`FreeType library', or `FreeType Distribution'.
As you have not signed this license, you are not required to
accept it. However, as the FreeType Project is copyrighted
material, only this license, or another one contracted with the
authors, grants you the right to use, distribute, and modify it.
Therefore, by using, distributing, or modifying the FreeType
Project, you indicate that you understand and accept all the terms
of this license.
4. Contacts
-----------
There are two mailing lists related to FreeType:
o freetype@nongnu.org
Discusses general use and applications of FreeType, as well as
future and wanted additions to the library and distribution.
If you are looking for support, start in this list if you
haven't found anything to help you in the documentation.
o freetype-devel@nongnu.org
Discusses bugs, as well as engine internals, design issues,
specific licenses, porting, etc.
Our home page can be found at
http://www.freetype.org
--- end of FTL.TXT ---

View File

@@ -0,0 +1,86 @@
FreeType2
=========
This directory contains all of the FreeType2 builds, a copy of the FreeType
Project License, and a patch file for when compiling new versions of freetype
for 64-bit Windows.
**WARNING**: These are not standard builds of FreeType on Windows (for 64-bit)
and will not work as a drop-in replacement for someone else's build. This is
why the package is distributed on NuGet as *SharpFont.Dependencies* instead of
*freetype2.redist* or something similar.
##Compiling FreeType on Windows
The copies of `freetype6.dll` that the Examples project uses by default are
chosen based on what works on my machine, and I will probably update it as
soon as a new version of FreeType is released. This means that it may not work
on older versions of Windows. If this is the case, you can either modify
the project file to point to another included version of freetype or you can
compile FreeType yourself from source.
**Note**: Any 32-bit copy of `freetype6.dll` works as a drop-in replacement,
including [this copy][1] from the GnuWin32 project. Older versions such as
that one may crash with a `EntryPointException` when using newer APIs. **This
is not true of 64-bit copies currently**
Thanks to [this StackOverflow answer][2] for the directions:
1. Download the latest [FreeType source code][3].
2. Open `builds\win32\vc2010\freetype.sln` (or whatever version of Visual
Studio you have) in Visual Studio.
3. Change the compile configuration from Debug to Release.
4. Open the project properties window through Project -> Properties.
5. In the `General` selection, change the `Target Name` to `freetype6` and
the `Configuration Type` to `Dynamic Library (.dll)`.
6. **If compiling for 64-bit**
- Apply a patch to the source code (see [Known Issues](#known-issues)).
- Open up Configuration Manager (the last option in the dropdown menu when
changing your compile configuration) and change `Platform` to `x64`.
7. Open up `ftoption.h` (in the project's `Header Files` section) and add the
following three lines near the `DLL export compilation` section:
```C
#define FT_EXPORT(x) __declspec(dllexport) x
#define FT_EXPORT_DEF(x) __declspec(dllexport) x
#define FT_BASE(x) __declspec(dllexport) x
```
Finally, complile the project (`F6` or Build -> Build Solution).
`freetype6.dll` will be output to `objs\win32\vc2010`. If this is a build that
isn't included in [Dependencies][4], consider forking and submitting a pull
request with your new build.
## Windows x64
A patch file, [win64.patch][5], is included in this directory that will force
several types to be 64 bits wide. On Linux and OS X, the native `long` type is
64 bits wide on x64, but on Windows, it's still 32 bits wide for backwards
compatibility of applications assuming `sizeof(long) == sizeof(int)`. A list
of the affected types:
- `FT_Long`
- `FT_ULong`
- `FT_Fixed`
- `FT_F26Dot6`
- `FT_Pos`
To apply the patch file, you need a copy of the `patch` utility built for
Windows. If using msysgit, it is already installed and is available from Git
Bash. Otherwise, a build is available from [GnuWin32][6]. Utilities such as
TortoiseDiff can provide a graphical way to do this same task.
After downloading and decompressing FreeType2, copy `win64.patch` into the
root folder (i.e. the folder containing `builds/`, `/include`, `/src`, etc.)
and run the following command:
```
patch -p0 < win64.patch
```
[1]: http://gnuwin32.sourceforge.net/packages/freetype.htm
[2]: http://stackoverflow.com/a/7387618/1122135
[3]: http://sourceforge.net/projects/freetype/files/freetype2/
[4]: https://github.com/Robmaister/SharpFont.Dependencies
[5]: https://github.com/Robmaister/SharpFont.Dependencies/blob/master/freetype2/win64.patch
[6]: http://gnuwin32.sourceforge.net/packages/patch.htm

View File

@@ -0,0 +1,71 @@
diff -pNaur include_old/ftimage.h include/ftimage.h
--- include_old/ftimage.h Sat Mar 7 18:56:10 2015
+++ include/ftimage.h Sat Mar 7 22:12:11 2015
@@ -55,7 +55,11 @@ FT_BEGIN_HEADER
/* on the context, these can represent distances in integer font */
/* units, or 16.16, or 26.6 fixed-point pixel coordinates. */
/* */
- typedef signed long FT_Pos;
+#if _WIN64
+ typedef signed __int64 FT_Pos;
+#else
+ typedef signed long FT_Pos;
+#endif
/*************************************************************************/
diff -pNaur include_old/fttypes.h include/fttypes.h
--- include_old/fttypes.h Sat Mar 7 21:46:14 2015
+++ include/fttypes.h Sat Mar 7 21:52:41 2015
@@ -239,7 +239,11 @@ FT_BEGIN_HEADER
/* <Description> */
/* A typedef for signed long. */
/* */
- typedef signed long FT_Long;
+#if _WIN64
+ typedef signed __int64 FT_Long;
+#else
+ typedef signed long FT_Long;
+#endif
/*************************************************************************/
@@ -250,7 +254,11 @@ FT_BEGIN_HEADER
/* <Description> */
/* A typedef for unsigned long. */
/* */
- typedef unsigned long FT_ULong;
+#if _WIN64
+ typedef unsigned __int64 FT_ULong;
+#else
+ typedef unsigned long FT_ULong;
+#endif
/*************************************************************************/
@@ -273,7 +281,11 @@ FT_BEGIN_HEADER
/* A signed 26.6 fixed-point type used for vectorial pixel */
/* coordinates. */
/* */
- typedef signed long FT_F26Dot6;
+#if _WIN64
+ typedef signed __int64 FT_F26Dot6;
+#else
+ typedef unsigned long FT_F26Dot6;
+#endif
/*************************************************************************/
@@ -285,7 +297,11 @@ FT_BEGIN_HEADER
/* This type is used to store 16.16 fixed-point values, like scaling */
/* values or matrix coefficients. */
/* */
- typedef signed long FT_Fixed;
+#if _WIN64
+ typedef signed __int64 FT_Fixed;
+#else
+ typedef unsigned long FT_Fixed;
+#endif
/*************************************************************************/

21
SharpFont/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

16
SharpFont/Makefile Normal file
View File

@@ -0,0 +1,16 @@
XBUILD := xbuild
XBUILDFLAGS_RELEASE := /p:Configuration=Release
XBUILDFLAGS_DEBUG := /p:Configuration=Debug
SOLUTION := Source/SharpFont.sln
release:
$(XBUILD) $(XBUILDFLAGS_RELEASE) $(SOLUTION)
debug:
$(XBUILD) $(XBUILDFLAGS_DEBUG) $(SOLUTION)
clean:
$(XBUILD) $(XBUILDFLAGS_DEBUG) $(SOLUTION) /t:Clean
$(XBUILD) $(XBUILDFLAGS_RELEASE) $(SOLUTION) /t:Clean
.SUFFIXES:
.PHONY: release debug clean

120
SharpFont/README.md Normal file
View File

@@ -0,0 +1,120 @@
SharpFont [![NuGet Version](https://img.shields.io/nuget/vpre/SharpFont.svg)](https://www.nuget.org/packages/SharpFont) [![Gratipay Tips](https://img.shields.io/gratipay/Robmaister.svg)](https://gratipay.com/Robmaister)
=========
### Cross-platform FreeType bindings for .NET
SharpFont is a library that provides FreeType bindings for .NET. It's MIT
licensed to make sure licensing doesn't get in the way of using the library in
your own projects. Unlike [Tao.FreeType][1], SharpFont provides the full
public API and not just the basic methods needed to render simple text.
Everything from format-specific APIs to the caching subsystem are included.
SharpFont simplifies the FreeType API in a few ways:
- The error codes that most FreeType methods return are converted to
exceptions.
- Since the return values are no longer error codes, methods with a single
`out` parameter are returned instead.
- Most methods are instance methods instead of static methods. This avoids
unnecessary redundancy in method calls and creates an API with a .NET
look-and-feel.
For example, a regular FreeType method looks like this:
```C
Face face;
int err = FT_New_Face(library, "./myfont.ttf", 0, &face);
```
The equivalent code in C# with SharpFont is:
```CSharp
Face face = new Face(library, "./myfont.ttf");
```
##Quick Start
###NuGet
SharpFont is available on [NuGet][2]. It can be installed by issuing the
following command in the package manager console:
```
PM> Install-Package SharpFont
```
###From Source
Clone the repository and compile the solution. Copy `SharpFont.dll` to your
project and include it as a reference. On Windows, you must include a compiled
copy of FreeType2 as `freetype6.dll` in the project's output directory. It is
possible to rename the file by changing the filename constant in
[FT.Internal.cs][3] and recompile. On Linux and OSX (and any other Mono
supported platform), you must also copy `SharpFont.dll.config` to the
project's output directory.
Two extensions for Visual Studio make it easy to follow the coding format in
this project and prevent lots of spurious whitespace changes.
The [.editorconfig](http://editorconfig.org/) file in the project works with the
[EditorConfig](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328)
extension and the [Format document on Save](https://visualstudiogallery.msdn.microsoft.com/3ea1c920-69c4-441f-9979-ccc2752dac56)
extension makes it basically automatic.
####Mono
With the removal of the `WIN64` configurations, the included `Makefile` is
effectively redundant. However, you can still build SharpFont by calling
`make` while in the root directory of this project.
####FreeType
A large number of FreeType builds for Windows are now available in the
[SharpFont.Dependencies][4] repository.
##Known Issues
While SharpFont is fully compatible with and runs on 64-bit Windows, it relies
on a patch for FreeType to do this. This patch is already included in
[SharpFont.Dependencies/freetype2][5]. You do not need to worry about this as
a user of the library. If you are compiling FreeType from source, you can find
the patch and instructions at the same location.
##License
As metioned earlier, SharpFont is licensed under the MIT License. The terms of
the MIT license are included in both the [LICENSE][6] file and below:
```
Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
The Windows binary of FreeType that is included in the Examples project and in
the NuGet package is redistributed under the FreeType License (FTL).
```
Portions of this software are copyright (c) 2016 The FreeType Project
(www.freetype.org). All rights reserved.
```
[1]: http://taoframework.svn.sourceforge.net/viewvc/taoframework/trunk/src/Tao.FreeType/
[2]: https://nuget.org/packages/SharpFont/
[3]: SharpFont/FT.Internal.cs
[4]: https://github.com/Robmaister/SharpFont.Dependencies
[5]: https://github.com/Robmaister/SharpFont.Dependencies/tree/master/freetype2
[6]: LICENSE

View File

@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = crlf
indent_style = tab
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true

View File

@@ -0,0 +1,97 @@
<StyleCopSettings Version="105">
<Parsers>
<Parser ParserId="StyleCop.CSharp.CsParser">
<ParserSettings>
<CollectionProperty Name="GeneratedFileFilters">
<Value>Rec\.cs$</Value>
<Value>Marhsaler\.cs$</Value>
</CollectionProperty>
</ParserSettings>
</Parser>
</Parsers>
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="PrefixLocalCallsWithThis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.SpacingRules">
<Rules>
<Rule Name="TabsMustNotBeUsed">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentsMustBeginWithSingleSpace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.LayoutRules">
<Rules>
<Rule Name="CurlyBracketsMustNotBeOmitted">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="FileMustHaveHeader">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustBeSpelledCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings>
<BooleanProperty Name="IgnoreInternals">True</BooleanProperty>
<BooleanProperty Name="IgnorePrivates">True</BooleanProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.MaintainabilityRules">
<Rules>
<Rule Name="ArithmeticExpressionsMustDeclarePrecedence">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="FieldNamesMustNotUseHungarianNotation">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<dllmap dll="freetype6" os="linux" target="libfreetype.so.6" />
<dllmap dll="freetype6" os="osx" target="/Library/Frameworks/Mono.framework/Libraries/libfreetype.6.dylib" />
<dllmap dll="freetype6" os="freebsd" target="libfreetype.so.6" />
</configuration>

View File

@@ -0,0 +1,45 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpFont", "SharpFont\SharpFont.csproj", "{C293DB32-FA42-486D-B128-5A12522FAE4E}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharpFontShared", "SharpFontShared\SharpFontShared.shproj", "{2E4773B7-961A-4328-9D77-9749F9071CA2}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SharpFontShared\SharpFontShared.projitems*{2e4773b7-961a-4328-9d77-9749f9071ca2}*SharedItemsImports = 13
SharpFontShared\SharpFontShared.projitems*{c293db32-fa42-486d-b128-5a12522fae4e}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C293DB32-FA42-486D-B128-5A12522FAE4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C293DB32-FA42-486D-B128-5A12522FAE4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Examples\Examples.csproj
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = None
$1.ResourceNamePolicy = FileFormatDefault
$0.StandardHeader = $2
$2.Text =
$2.IncludeInNewFiles = True
$0.VersionControlPolicy = $3
$3.inheritsSet = Mono
$0.ChangeLogPolicy = $4
$4.UpdateMode = None
$4.MessageStyle = $5
$5.LineAlign = 0
$4.inheritsSet = Mono
EndGlobalSection
EndGlobal

Binary file not shown.

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C293DB32-FA42-486D-B128-5A12522FAE4E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SharpFont</RootNamespace>
<AssemblyName>SharpFont</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Binaries\SharpFont\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\SharpFont.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Binaries\SharpFont\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\SharpFont.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\SharpFont.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<None Include="..\SharpFont.dll.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\SharpFont.snk" />
</ItemGroup>
<ItemGroup />
<Import Project="..\SharpFontShared\SharpFontShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,138 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// A list of constants used for the glyph-to-script-map property to specify the script submodule the auto-hinter
/// should use for hinting a particular glyph.
/// </summary>
public enum AutoHinterScript
{
/// <summary>
/// Don't auto-hint this glyph.
/// </summary>
None = 0,
/// <summary>
/// Apply the latin auto-hinter. For the auto-hinter, latin is a very broad term, including Cyrillic and
/// Greek also since characters from those scripts share the same design constraints.
/// </summary>
/// <remarks><para>
/// By default, characters from the following Unicode ranges are assigned to this submodule.
/// </para><para><code>
/// U+0020 - U+007F // Basic Latin (no control characters)
/// U+00A0 - U+00FF // Latin-1 Supplement (no control characters)
/// U+0100 - U+017F // Latin Extended-A
/// U+0180 - U+024F // Latin Extended-B
/// U+0250 - U+02AF // IPA Extensions
/// U+02B0 - U+02FF // Spacing Modifier Letters
/// U+0300 - U+036F // Combining Diacritical Marks
/// U+0370 - U+03FF // Greek and Coptic
/// U+0400 - U+04FF // Cyrillic
/// U+0500 - U+052F // Cyrillic Supplement
/// U+1D00 - U+1D7F // Phonetic Extensions
/// U+1D80 - U+1DBF // Phonetic Extensions Supplement
/// U+1DC0 - U+1DFF // Combining Diacritical Marks Supplement
/// U+1E00 - U+1EFF // Latin Extended Additional
/// U+1F00 - U+1FFF // Greek Extended
/// U+2000 - U+206F // General Punctuation
/// U+2070 - U+209F // Superscripts and Subscripts
/// U+20A0 - U+20CF // Currency Symbols
/// U+2150 - U+218F // Number Forms
/// U+2460 - U+24FF // Enclosed Alphanumerics
/// U+2C60 - U+2C7F // Latin Extended-C
/// U+2DE0 - U+2DFF // Cyrillic Extended-A
/// U+2E00 - U+2E7F // Supplemental Punctuation
/// U+A640 - U+A69F // Cyrillic Extended-B
/// U+A720 - U+A7FF // Latin Extended-D
/// U+FB00 - U+FB06 // Alphab. Present. Forms (Latin Ligatures)
/// U+1D400 - U+1D7FF // Mathematical Alphanumeric Symbols
/// U+1F100 - U+1F1FF // Enclosed Alphanumeric Supplement
/// </code></para></remarks>
Latin = 1,
/// <summary>
/// Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old Vietnamese, and some other scripts.
/// </summary>
/// <remarks><para>
/// By default, characters from the following Unicode ranges are assigned to this submodule.
/// </para><para><code>
/// U+1100 - U+11FF // Hangul Jamo
/// U+2E80 - U+2EFF // CJK Radicals Supplement
/// U+2F00 - U+2FDF // Kangxi Radicals
/// U+2FF0 - U+2FFF // Ideographic Description Characters
/// U+3000 - U+303F // CJK Symbols and Punctuation
/// U+3040 - U+309F // Hiragana
/// U+30A0 - U+30FF // Katakana
/// U+3100 - U+312F // Bopomofo
/// U+3130 - U+318F // Hangul Compatibility Jamo
/// U+3190 - U+319F // Kanbun
/// U+31A0 - U+31BF // Bopomofo Extended
/// U+31C0 - U+31EF // CJK Strokes
/// U+31F0 - U+31FF // Katakana Phonetic Extensions
/// U+3200 - U+32FF // Enclosed CJK Letters and Months
/// U+3300 - U+33FF // CJK Compatibility
/// U+3400 - U+4DBF // CJK Unified Ideographs Extension A
/// U+4DC0 - U+4DFF // Yijing Hexagram Symbols
/// U+4E00 - U+9FFF // CJK Unified Ideographs
/// U+A960 - U+A97F // Hangul Jamo Extended-A
/// U+AC00 - U+D7AF // Hangul Syllables
/// U+D7B0 - U+D7FF // Hangul Jamo Extended-B
/// U+F900 - U+FAFF // CJK Compatibility Ideographs
/// U+FE10 - U+FE1F // Vertical forms
/// U+FE30 - U+FE4F // CJK Compatibility Forms
/// U+FF00 - U+FFEF // Halfwidth and Fullwidth Forms
/// U+1B000 - U+1B0FF // Kana Supplement
/// U+1D300 - U+1D35F // Tai Xuan Hing Symbols
/// U+1F200 - U+1F2FF // Enclosed Ideographic Supplement
/// U+20000 - U+2A6DF // CJK Unified Ideographs Extension B
/// U+2A700 - U+2B73F // CJK Unified Ideographs Extension C
/// U+2B740 - U+2B81F // CJK Unified Ideographs Extension D
/// U+2F800 - U+2FA1F // CJK Compatibility Ideographs Supplement
/// </code></para></remarks>
Cjk = 2,
/// <summary>
/// Apply the indic auto-hinter, covering all major scripts from the Indian sub-continent and some other
/// related scripts like Thai, Lao, or Tibetan.
/// </summary>
/// <remarks><para>
/// By default, characters from the following Unicode ranges are assigned to this submodule.
/// </para><para><code>
/// U+0900 - U+0DFF // Indic Range
/// U+0F00 - U+0FFF // Tibetan
/// U+1900 - U+194F // Limbu
/// U+1B80 - U+1BBF // Sundanese
/// U+1C80 - U+1CDF // Meetei Mayak
/// U+A800 - U+A82F // Syloti Nagri
/// U+11800 - U+118DF // Sharada
/// </code></para><para>
/// Note that currently Indic support is rudimentary only, missing blue zone support.
/// </para></remarks>
Indic = 3
}
}

View File

@@ -0,0 +1,190 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont
{
/// <summary>
/// A structure used to hold an outline's bounding box, i.e., the
/// coordinates of its extrema in the horizontal and vertical directions.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct BBox : IEquatable<BBox>
{
#region Fields
private FT_Long xMin, yMin;
private FT_Long xMax, yMax;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="BBox"/> struct.
/// </summary>
/// <param name="left">The left bound.</param>
/// <param name="bottom">The bottom bound.</param>
/// <param name="right">The right bound.</param>
/// <param name="top">The upper bound.</param>
public BBox(int left, int bottom, int right, int top)
{
xMin = (IntPtr)left;
yMin = (IntPtr)bottom;
xMax = (IntPtr)right;
yMax = (IntPtr)top;
}
#endregion
#region Properties
/// <summary>
/// Gets the horizontal minimum (left-most).
/// </summary>
public int Left
{
get
{
return (int)xMin;
}
}
/// <summary>
/// Gets the vertical minimum (bottom-most).
/// </summary>
public int Bottom
{
get
{
return (int)yMin;
}
}
/// <summary>
/// Gets the horizontal maximum (right-most).
/// </summary>
public int Right
{
get
{
return (int)xMax;
}
}
/// <summary>
/// Gets the vertical maximum (top-most).
/// </summary>
public int Top
{
get
{
return (int)yMax;
}
}
#endregion
#region Operators
/// <summary>
/// Compares two instances of <see cref="BBox"/> for equality.
/// </summary>
/// <param name="left">A <see cref="BBox"/>.</param>
/// <param name="right">Another <see cref="BBox"/>.</param>
/// <returns>A value indicating equality.</returns>
public static bool operator ==(BBox left, BBox right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="BBox"/> for inequality.
/// </summary>
/// <param name="left">A <see cref="BBox"/>.</param>
/// <param name="right">Another <see cref="BBox"/>.</param>
/// <returns>A value indicating inequality.</returns>
public static bool operator !=(BBox left, BBox right)
{
return !left.Equals(right);
}
#endregion
#region Methods
/// <summary>
/// Compares this instance of <see cref="BBox"/> to another for equality.
/// </summary>
/// <param name="other">A <see cref="BBox"/>.</param>
/// <returns>A value indicating equality.</returns>
public bool Equals(BBox other)
{
return
xMin == other.xMin &&
yMin == other.yMin &&
xMax == other.xMax &&
yMax == other.yMax;
}
/// <summary>
/// Compares this instance of <see cref="BBox"/> to an object for equality.
/// </summary>
/// <param name="obj">An object.</param>
/// <returns>A value indicating equality.</returns>
public override bool Equals(object obj)
{
if (obj is BBox)
return this.Equals((BBox)obj);
return false;
}
/// <summary>
/// Gets a unique hash code for this instance.
/// </summary>
/// <returns>A hash code.</returns>
public override int GetHashCode()
{
//TODO better hash algo
return xMin.GetHashCode() ^ yMin.GetHashCode() ^ xMax.GetHashCode() ^ yMax.GetHashCode();
}
/// <summary>
/// Gets a string that represents this instance.
/// </summary>
/// <returns>A string representation of this instance.</returns>
public override string ToString()
{
return "Min: (" + (int)xMin + ", " + (int)yMin + "), Max: (" + (int)xMax + ", " + (int)yMax + ")";
}
#endregion
}
}

View File

@@ -0,0 +1,45 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Bdf.Internal
{
[StructLayout(LayoutKind.Explicit, Pack = 0)]
internal struct PropertyRec
{
[FieldOffset(0)]
internal PropertyType type;
[FieldOffset(4)]
internal IntPtr atom;
[FieldOffset(4)]
internal int integer;
[FieldOffset(4)]
internal uint cardinal;
}
}

View File

@@ -0,0 +1,121 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Bdf.Internal;
namespace SharpFont.Bdf
{
/// <summary>
/// This structure models a given BDF/PCF property.
/// </summary>
public class Property
{
#region Fields
private IntPtr reference;
private PropertyRec rec;
#endregion
#region Constructors
internal Property(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the property type.
/// </summary>
public PropertyType Type
{
get
{
return rec.type;
}
}
/// <summary>
/// Gets the atom string, if type is <see cref="PropertyType.Atom"/>.
/// </summary>
public string Atom
{
get
{
// only this property throws an exception because the pointer could be to unmanaged memory not owned by
// the process.
if (rec.type != PropertyType.Atom)
throw new InvalidOperationException("The property type is not Atom.");
return Marshal.PtrToStringAnsi(rec.atom);
}
}
/// <summary>
/// Gets a signed integer, if type is <see cref="PropertyType.Integer"/>.
/// </summary>
public int Integer
{
get
{
return rec.integer;
}
}
/// <summary>
/// Gets an unsigned integer, if type is <see cref="PropertyType.Cardinal"/>.
/// </summary>
[CLSCompliant(false)]
public uint Cardinal
{
get
{
return rec.cardinal;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<PropertyRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,46 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Bdf
{
/// <summary>
/// A list of BDF property types.
/// </summary>
public enum PropertyType
{
/// <summary>Value 0 is used to indicate a missing property.</summary>
None = 0,
/// <summary>Property is a string atom.</summary>
Atom = 1,
/// <summary>Property is a 32-bit signed integer.</summary>
Integer = 2,
/// <summary>Property is a 32-bit unsigned integer.</summary>
Cardinal = 3
}
}

View File

@@ -0,0 +1,207 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A structure used for bitmap glyph images. This really is a sub-class of <see cref="Glyph"/>.
/// </summary>
/// <remarks><para>
/// You can typecast an <see cref="Glyph"/> to <see cref="BitmapGlyph"/> if you have <see cref="Glyph.Format"/> ==
/// <see cref="GlyphFormat.Bitmap"/>. This lets you access the bitmap's contents easily.
/// </para><para>
/// The corresponding pixel buffer is always owned by <see cref="BitmapGlyph"/> and is thus created and destroyed
/// with it.
/// </para></remarks>
public sealed class BitmapGlyph : IDisposable
{
#region Fields
private Glyph original;
private BitmapGlyphRec rec;
#endregion
#region Constructors
internal BitmapGlyph(Glyph original)
{
this.original = original;
Reference = original.Reference; //generates the rec.
}
/// <summary>
/// Finalizes an instance of the <see cref="BitmapGlyph"/> class.
/// </summary>
~BitmapGlyph()
{
Dispose(false);
}
#endregion
#region Properties
/// <summary>
/// Gets a value indicating whether the object has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return original.IsDisposed;
}
}
/// <summary>
/// Gets the root <see cref="Glyph"/> fields.
/// </summary>
public Glyph Root
{
get
{
if (IsDisposed)
throw new ObjectDisposedException("Root", "Cannot access a disposed object.");
return original;
}
}
/// <summary>
/// Gets the left-side bearing, i.e., the horizontal distance from the current pen position to the left border
/// of the glyph bitmap.
/// </summary>
public int Left
{
get
{
if (IsDisposed)
throw new ObjectDisposedException("Left", "Cannot access a disposed object.");
return rec.left;
}
}
/// <summary>
/// Gets the top-side bearing, i.e., the vertical distance from the current pen position to the top border of
/// the glyph bitmap. This distance is positive for upwards y!
/// </summary>
public int Top
{
get
{
if (IsDisposed)
throw new ObjectDisposedException("Top", "Cannot access a disposed object.");
return rec.top;
}
}
/// <summary>
/// Gets a descriptor for the bitmap.
/// </summary>
public FTBitmap Bitmap
{
get
{
if (IsDisposed)
throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object.");
return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf<BitmapGlyphRec>(Reference, "bitmap"), rec.bitmap, null);
}
}
internal IntPtr Reference
{
get
{
if (IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
return original.Reference;
}
set
{
if (IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot modify a disposed object.");
rec = PInvokeHelper.PtrToStructure<BitmapGlyphRec>(original.Reference);
}
}
#endregion
#region Operators
/// <summary>
/// Casts a <see cref="BitmapGlyph"/> back up to a <see cref="Glyph"/>. The eqivalent of
/// <see cref="BitmapGlyph.Root"/>.
/// </summary>
/// <param name="g">A <see cref="BitmapGlyph"/>.</param>
/// <returns>A <see cref="Glyph"/>.</returns>
public static implicit operator Glyph(BitmapGlyph g)
{
return g.original;
}
#endregion
#region Methods
/// <summary>
/// A CLS-compliant version of the implicit cast to <see cref="Glyph"/>.
/// </summary>
/// <returns>A <see cref="Glyph"/>.</returns>
public Glyph ToGlyph()
{
return (Glyph)this;
}
/// <summary>
/// Disposes an instance of the <see cref="BitmapGlyph"/> class.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposing)
{
original.Dispose();
original = null;
}
}
#endregion
}
}

View File

@@ -0,0 +1,145 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// This structure models the metrics of a bitmap strike (i.e., a set of
/// glyphs for a given point size and resolution) in a bitmap font. It is
/// used for the <see cref="Face.AvailableSizes"/> field of
/// <see cref="Face"/>.
/// </summary>
/// <remarks><para>
/// Windows FNT: The nominal size given in a FNT font is not reliable. Thus
/// when the driver finds it incorrect, it sets size to some calculated
/// values and sets x_ppem and y_ppem to the pixel width and height
/// given in the font, respectively.
/// </para><para>
/// TrueType embedded bitmaps: size, width, and height values are not
/// contained in the bitmap strike itself. They are computed from the
/// global font parameters.
/// </para></remarks>
public sealed class BitmapSize
{
#region Fields
private IntPtr reference;
private BitmapSizeRec rec;
#endregion
#region Constructors
internal BitmapSize(IntPtr reference)
{
Reference = reference;
}
internal BitmapSize(BitmapSizeRec bmpSizeInt)
{
this.rec = bmpSizeInt;
}
#endregion
#region Properties
/// <summary>
/// Gets the vertical distance, in pixels, between two consecutive
/// baselines. It is always positive.
/// </summary>
public short Height
{
get
{
return rec.height;
}
}
/// <summary>
/// Gets the average width, in pixels, of all glyphs in the strike.
/// </summary>
public short Width
{
get
{
return rec.width;
}
}
/// <summary>
/// Gets the nominal size of the strike in 26.6 fractional points. This
/// field is not very useful.
/// </summary>
public Fixed26Dot6 Size
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.size);
}
}
/// <summary>
/// Gets the horizontal ppem (nominal width) in 26.6 fractional pixels.
/// </summary>
public Fixed26Dot6 NominalWidth
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.x_ppem);
}
}
/// <summary>
/// Gets the vertical ppem (nominal height) in 26.6 fractional pixels.
/// </summary>
public Fixed26Dot6 NominalHeight
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.y_ppem);
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<BitmapSizeRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,100 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Cache
{
/// <summary>
/// An opaque handle used to model a charmap cache. This cache is to hold character codes -> glyph indices
/// mappings.
/// </summary>
public class CMapCache
{
#region Fields
private IntPtr reference;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CMapCache"/> class.
/// </summary>
/// <remarks>
/// Like all other caches, this one will be destroyed with the cache manager.
/// </remarks>
/// <param name="manager">A handle to the cache manager.</param>
public CMapCache(Manager manager)
{
IntPtr cacheRef;
Error err = FT.FTC_CMapCache_New(manager.Reference, out cacheRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
Reference = cacheRef;
}
#endregion
#region Properties
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
}
}
#endregion
#region Methods
/// <summary>
/// Translate a character code into a glyph index, using the charmap cache.
/// </summary>
/// <param name="faceId">The source face ID.</param>
/// <param name="cmapIndex">
/// The index of the charmap in the source face. Any negative value means to use the cache <see cref="Face"/>'s
/// default charmap.
/// </param>
/// <param name="charCode">The character code (in the corresponding charmap).</param>
/// <returns>Glyph index. 0 means no glyph.</returns>
[CLSCompliant(false)]
public uint Lookup(IntPtr faceId, int cmapIndex, uint charCode)
{
return FT.FTC_CMapCache_Lookup(Reference, faceId, cmapIndex, charCode);
}
#endregion
}
}

View File

@@ -0,0 +1,47 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache
{
/// <summary>
/// A callback function provided by client applications. It is used by the cache manager to translate a given
/// FTC_FaceID into a new valid <see cref="Face"/> object, on demand.
/// </summary>
/// <remarks><para>
/// The third parameter req_data is the same as the one passed by the client when
/// <see cref="Manager(Library, uint, uint, ulong, FaceRequester, IntPtr)"/> is called.
/// </para><para>
/// The face requester should not perform funny things on the returned face object, like creating a new
/// <see cref="FTSize"/> for it, or setting a transformation through <see cref="Face.SetTransform()"/>!
/// </para></remarks>
/// <param name="faceId">The face ID to resolve.</param>
/// <param name="library">A handle to a FreeType library object.</param>
/// <param name="requestData">Application-provided request data (see note below).</param>
/// <param name="aface">A new <see cref="Face"/> handle.</param>
/// <returns>FreeType error code. 0 means success.</returns>
public delegate Error FaceRequester(IntPtr faceId, IntPtr library, IntPtr requestData, out IntPtr aface);
}

View File

@@ -0,0 +1,173 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Cache
{
/// <summary>
/// A handle to an glyph image cache object. They are designed to hold many distinct glyph images while not
/// exceeding a certain memory threshold.
/// </summary>
public class ImageCache
{
#region Fields
private IntPtr reference;
private Manager parentManager;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ImageCache"/> class.
/// </summary>
/// <param name="manager">The parent manager for the image cache.</param>
public ImageCache(Manager manager)
{
if (manager == null)
throw new ArgumentNullException("manager");
IntPtr cacheRef;
Error err = FT.FTC_ImageCache_New(manager.Reference, out cacheRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
parentManager = manager;
Reference = cacheRef;
}
#endregion
#region Properties
internal IntPtr Reference
{
get
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
return reference;
}
set
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
reference = value;
}
}
#endregion
#region Methods
/// <summary>
/// Retrieve a given glyph image from a glyph image cache.
/// </summary>
/// <remarks><para>
/// The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it
/// manually! You can however create a copy with <see cref="Glyph.Copy"/> and modify the new one.
/// </para><para>
/// If node is not NULL, it receives the address of the cache node containing the glyph image,
/// after increasing its reference count. This ensures that the node (as well as the <see cref="Glyph"/>) will
/// always be kept in the cache until you call <see cref="Node.Unref"/> to release it.
/// </para><para>
/// If node is NULL, the cache node is left unchanged, which means that the <see cref="Glyph"/>
/// could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that
/// it is persistent!
/// </para></remarks>
/// <param name="type">A pointer to a glyph image type descriptor.</param>
/// <param name="gIndex">The glyph index to retrieve.</param>
/// <param name="node">
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
/// note below).
/// </param>
/// <returns>The corresponding <see cref="Glyph"/> object. 0 in case of failure.</returns>
[CLSCompliant(false)]
public Glyph Lookup(ImageType type, uint gIndex, out Node node)
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
IntPtr glyphRef, nodeRef;
Error err = FT.FTC_ImageCache_Lookup(Reference, type.Reference, gIndex, out glyphRef, out nodeRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
node = new Node(nodeRef);
return new Glyph(glyphRef, null);
}
/// <summary>
/// A variant of <see cref="ImageCache.Lookup"/> that uses a <see cref="Scaler"/> to specify the face ID and its
/// size.
/// </summary>
/// <remarks><para>
/// The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it
/// manually! You can however create a copy with <see cref="Glyph.Copy"/> and modify the new one.
/// </para><para>
/// If node is not NULL, it receives the address of the cache node containing the glyph image,
/// after increasing its reference count. This ensures that the node (as well as the <see cref="Glyph"/>) will
/// always be kept in the cache until you call <see cref="Node.Unref"/> to release it.
/// </para><para>
/// If node is NULL, the cache node is left unchanged, which means that the <see cref="Glyph"/>
/// could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that
/// it is persistent!
/// </para><para>
/// Calls to <see cref="Face.SetCharSize"/> and friends have no effect on cached glyphs; you should always use
/// the FreeType cache API instead.
/// </para></remarks>
/// <param name="scaler">A pointer to a scaler descriptor.</param>
/// <param name="loadFlags">The corresponding load flags.</param>
/// <param name="gIndex">The glyph index to retrieve.</param>
/// <param name="node">
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
/// note below).
/// </param>
/// <returns>The corresponding <see cref="Glyph"/> object. 0 in case of failure.</returns>
[CLSCompliant(false)]
public Glyph LookupScaler(Scaler scaler, LoadFlags loadFlags, uint gIndex, out Node node)
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
IntPtr glyphRef, nodeRef;
Error err = FT.FTC_ImageCache_LookupScaler(Reference, scaler.Reference, loadFlags, gIndex, out glyphRef, out nodeRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
node = new Node(nodeRef);
return new Glyph(glyphRef, null);
}
#endregion
}
}

View File

@@ -0,0 +1,116 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Cache.Internal;
namespace SharpFont.Cache
{
/// <summary>
/// A structure used to model the type of images in a glyph cache.
/// </summary>
public class ImageType
{
#region Fields
private IntPtr reference;
private ImageTypeRec rec;
#endregion
#region Constructors
internal ImageType(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the face ID.
/// </summary>
public IntPtr FaceId
{
get
{
return rec.face_id;
}
}
/// <summary>
/// Gets the width in pixels.
/// </summary>
public int Width
{
get
{
return rec.width;
}
}
/// <summary>
/// Gets the height in pixels.
/// </summary>
public int Height
{
get
{
return rec.height;
}
}
/// <summary>
/// Gets the load flags, as in <see cref="Face.LoadGlyph"/>
/// </summary>
[CLSCompliant(false)]
public LoadFlags Flags
{
get
{
return rec.flags;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<ImageTypeRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,34 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct CMapCacheRec
{
}
}

View File

@@ -0,0 +1,34 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ImageCacheRec
{
}
}

View File

@@ -0,0 +1,38 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ImageTypeRec
{
internal IntPtr face_id;
internal int width;
internal int height;
internal LoadFlags flags;
}
}

View File

@@ -0,0 +1,34 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ManagerRec
{
}
}

View File

@@ -0,0 +1,34 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct NodeRec
{
}
}

View File

@@ -0,0 +1,34 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct SBitCacheRec
{
}
}

View File

@@ -0,0 +1,46 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct SBitRec
{
internal byte width;
internal byte height;
internal byte left;
internal byte top;
internal byte format;
internal byte max_grays;
internal short pitch;
internal byte xadvance;
internal byte yadvance;
internal IntPtr buffer;
}
}

View File

@@ -0,0 +1,40 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ScalerRec
{
internal IntPtr face_id;
internal uint width;
internal uint height;
internal int pixel;
internal uint x_res;
internal uint y_res;
}
}

View File

@@ -0,0 +1,274 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Collections.Generic;
namespace SharpFont.Cache
{
/// <summary><para>
/// This object corresponds to one instance of the cache-subsystem. It is used to cache one or more
/// <see cref="Face"/> objects, along with corresponding <see cref="FTSize"/> objects.
/// </para><para>
/// The manager intentionally limits the total number of opened <see cref="Face"/> and <see cref="FTSize"/> objects
/// to control memory usage. See the max_faces and max_sizes parameters of
/// <see cref="Manager(Library, uint, uint, ulong, FaceRequester, IntPtr)"/>.
/// </para><para>
/// The manager is also used to cache nodes of various types while limiting their total memory usage.
/// </para><para>
/// All limitations are enforced by keeping lists of managed objects in most-recently-used order, and flushing old
/// nodes to make room for new ones.
/// </para></summary>
public sealed class Manager : IDisposable
{
#region Fields
private IntPtr reference;
private Library parentLibrary;
private bool disposed;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the Manager class.
/// </summary>
/// <param name="library">The parent FreeType library handle to use.</param>
/// <param name="maxFaces">
/// Maximum number of opened <see cref="Face"/> objects managed by this cache instance. Use 0 for defaults.
/// </param>
/// <param name="maxSizes">
/// Maximum number of opened <see cref="FTSize"/> objects managed by this cache instance. Use 0 for defaults.
/// </param>
/// <param name="maxBytes">
/// Maximum number of bytes to use for cached data nodes. Use 0 for defaults. Note that this value does not
/// account for managed <see cref="Face"/> and <see cref="FTSize"/> objects.
/// </param>
/// <param name="requester">
/// An application-provided callback used to translate face IDs into real <see cref="Face"/> objects.
/// </param>
/// <param name="requestData">
/// A generic pointer that is passed to the requester each time it is called (see <see cref="FaceRequester"/>).
/// </param>
[CLSCompliant(false)]
public Manager(Library library, uint maxFaces, uint maxSizes, ulong maxBytes, FaceRequester requester, IntPtr requestData)
{
if (library == null)
throw new ArgumentNullException("library");
IntPtr mgrRef;
Error err = FT.FTC_Manager_New(library.Reference, maxFaces, maxSizes, maxBytes, requester, requestData, out mgrRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
Reference = mgrRef;
this.parentLibrary = library;
library.AddChildManager(this);
}
/// <summary>
/// Finalizes an instance of the Manager class.
/// </summary>
~Manager()
{
Dispose(false);
}
#endregion
#region Properties
/// <summary>
/// Gets a value indicating whether the object has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return disposed;
}
}
internal IntPtr Reference
{
get
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
return reference;
}
set
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
reference = value;
}
}
#endregion
#region Public Members
/// <summary>
/// Empty a given cache manager. This simply gets rid of all the currently cached <see cref="Face"/> and
/// <see cref="FTSize"/> objects within the manager.
/// </summary>
public void Reset()
{
if (disposed)
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
FT.FTC_Manager_Reset(Reference);
}
/// <summary>
/// Retrieve the <see cref="Face"/> object that corresponds to a given face ID through a cache manager.
/// </summary>
/// <remarks><para>
/// The returned <see cref="Face"/> object is always owned by the manager. You should never try to discard it
/// yourself.
/// </para><para>
/// The <see cref="Face"/> object doesn't necessarily have a current size object (i.e., <see cref="Face.Size"/>
/// can be 0). If you need a specific font size, use <see cref="Manager.LookupSize"/> instead.
/// </para><para>
/// Never change the face's transformation matrix (i.e., never call the <see cref="Face.SetTransform()"/>
/// function) on a returned face! If you need to transform glyphs, do it yourself after glyph loading.
/// </para><para>
/// When you perform a lookup, out-of-memory errors are detected within the lookup and force incremental
/// flushes of the cache until enough memory is released for the lookup to succeed.
/// </para><para>
/// If a lookup fails with <see cref="Error.OutOfMemory"/> the cache has already been completely flushed, and
/// still no memory was available for the operation.
/// </para></remarks>
/// <param name="faceId">The ID of the face object.</param>
/// <returns>A handle to the face object.</returns>
public Face LookupFace(IntPtr faceId)
{
if (disposed)
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
IntPtr faceRef;
Error err = FT.FTC_Manager_LookupFace(Reference, faceId, out faceRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
//HACK fix this later.
return new Face(faceRef, null);
}
/// <summary>
/// Retrieve the <see cref="FTSize"/> object that corresponds to a given <see cref="Scaler"/> pointer through a
/// cache manager.
/// </summary>
/// <remarks><para>
/// The returned <see cref="FTSize"/> object is always owned by the/ manager. You should never try to discard
/// it by yourself.
/// </para><para>
/// You can access the parent <see cref="Face"/> object simply as <see cref="FTSize.Face"/> if you need it.
/// Note that this object is also owned by the manager.
/// </para><para>
/// When you perform a lookup, out-of-memory errors are detected within the lookup and force incremental
/// flushes of the cache until enough memory is released for the lookup to succeed.
/// </para><para>
/// If a lookup fails with <see cref="Error.OutOfMemory"/> the cache has already been completely flushed, and
/// still no memory is available for the operation.
/// </para></remarks>
/// <param name="scaler">A scaler handle.</param>
/// <returns>A handle to the size object.</returns>
public FTSize LookupSize(Scaler scaler)
{
if (disposed)
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
IntPtr sizeRef;
Error err = FT.FTC_Manager_LookupSize(Reference, scaler.Reference, out sizeRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
//HACK fix this later.
return new FTSize(sizeRef, false, null);
}
/// <summary>
/// A special function used to indicate to the cache manager that a given FTC_FaceID is no longer valid, either
/// because its content changed, or because it was deallocated or uninstalled.
/// </summary>
/// <remarks><para>
/// This function flushes all nodes from the cache corresponding to this faceID, with the
/// exception of nodes with a non-null reference count.
/// </para><para>
/// Such nodes are however modified internally so as to never appear in later lookups with the same
/// faceID value, and to be immediately destroyed when released by all their users.
/// </para></remarks>
/// <param name="faceId">The FTC_FaceID to be removed.</param>
public void RemoveFaceId(IntPtr faceId)
{
if (disposed)
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
FT.FTC_Manager_RemoveFaceID(Reference, faceId);
}
#endregion
#region IDisposable Members
/// <summary>
/// Disposes the Manager.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposed)
{
disposed = true;
FT.FTC_Manager_Done(reference);
reference = IntPtr.Zero;
// removes itself from the parent Library, with a check to prevent this from happening when Library is
// being disposed (Library disposes all it's children with a foreach loop, this causes an
// InvalidOperationException for modifying a collection during enumeration)
if (!parentLibrary.IsDisposed)
parentLibrary.RemoveChildManager(this);
}
}
#endregion
}
}

View File

@@ -0,0 +1,87 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Cache
{
/// <summary><para>
/// An opaque handle to a cache node object. Each cache node is reference-counted. A node with a count of 0 might
/// be flushed out of a full cache whenever a lookup request is performed.
/// </para><para>
/// If you look up nodes, you have the ability to acquire them, i.e., to increment their reference count. This
/// will prevent the node from being flushed out of the cache until you explicitly release it.
/// </para></summary>
/// <see cref="Node.Unref"/>
/// <seealso cref="SBitCache.Lookup"/>
/// <seealso cref="ImageCache.Lookup"/>
public class Node
{
#region Fields
private IntPtr reference;
#endregion
#region Constructors
internal Node(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
}
}
#endregion
#region Public Methods
/// <summary>
/// Decrement a cache node's internal reference count. When the count reaches 0, it is not destroyed but
/// becomes eligible for subsequent cache flushes.
/// </summary>
/// <param name="manager">The cache manager handle.</param>
public void Unref(Manager manager)
{
FT.FTC_Node_Unref(Reference, manager.Reference);
}
#endregion
}
}

View File

@@ -0,0 +1,185 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Cache.Internal;
namespace SharpFont.Cache
{
/// <summary>
/// A handle to a small bitmap cache. These are special cache objects used to store small glyph bitmaps (and
/// anti-aliased pixmaps) in a much more efficient way than the traditional glyph image cache implemented by
/// <see cref="ImageCache"/>.
/// </summary>
public class SBit
{
#region Fields
private IntPtr reference;
private SBitRec rec;
#endregion
#region Constructors
internal SBit(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the bitmap width in pixels.
/// </summary>
public byte Width
{
get
{
return rec.width;
}
}
/// <summary>
/// Gets the bitmap height in pixels.
/// </summary>
public byte Height
{
get
{
return rec.height;
}
}
/// <summary>
/// Gets the horizontal distance from the pen position to the left bitmap border (a.k.a. left side bearing,
/// or lsb).
/// </summary>
public byte Left
{
get
{
return rec.left;
}
}
/// <summary>
/// Gets the vertical distance from the pen position (on the baseline) to the upper bitmap border (a.k.a. top
/// side bearing). The distance is positive for upwards y coordinates.
/// </summary>
public byte Top
{
get
{
return rec.top;
}
}
/// <summary>
/// Gets the format of the glyph bitmap (monochrome or gray).
/// </summary>
public byte Format
{
get
{
return rec.format;
}
}
/// <summary>
/// Gets the maximum gray level value (in the range 1 to 255).
/// </summary>
public byte MaxGrays
{
get
{
return rec.max_grays;
}
}
/// <summary>
/// Gets the number of bytes per bitmap line. May be positive or negative.
/// </summary>
public short Pitch
{
get
{
return rec.pitch;
}
}
/// <summary>
/// Gets the horizontal advance width in pixels.
/// </summary>
public byte AdvanceX
{
get
{
return rec.xadvance;
}
}
/// <summary>
/// Gets the vertical advance height in pixels.
/// </summary>
public byte AdvanceY
{
get
{
return rec.yadvance;
}
}
/// <summary>
/// Gets a pointer to the bitmap pixels.
/// </summary>
public IntPtr Buffer
{
get
{
return rec.buffer;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<SBitRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,173 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Cache
{
/// <summary>
/// A handle to a small bitmap cache. These are special cache objects used to store small glyph bitmaps (and
/// anti-aliased pixmaps) in a much more efficient way than the traditional glyph image cache implemented by
/// <see cref="ImageCache"/>.
/// </summary>
public class SBitCache
{
#region Fields
private IntPtr reference;
private Manager parentManager;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="SBitCache"/> class.
/// </summary>
/// <param name="manager">A handle to the source cache manager.</param>
public SBitCache(Manager manager)
{
if (manager == null)
throw new ArgumentNullException("manager");
IntPtr cacheRef;
Error err = FT.FTC_SBitCache_New(manager.Reference, out cacheRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
Reference = cacheRef;
parentManager = manager;
}
#endregion
#region Properties
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
}
}
#endregion
#region Methods
/// <summary>
/// Look up a given small glyph bitmap in a given sbit cache and lock it to prevent its flushing from the
/// cache until needed.
/// </summary>
/// <remarks><para>
/// The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the
/// application. They might as well disappear from memory on the next cache lookup, so don't treat them as
/// persistent data.
/// </para><para>
/// The descriptor's buffer field is set to 0 to indicate a missing glyph bitmap.
/// </para><para>
/// If node is not NULL, it receives the address of the cache node containing the bitmap, after
/// increasing its reference count. This ensures that the node (as well as the image) will always be kept in
/// the cache until you call <see cref="Node.Unref"/> to release it.
/// </para><para>
/// If node is NULL, the cache node is left unchanged, which means that the bitmap could be
/// flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is
/// persistent!
/// </para></remarks>
/// <param name="type">A pointer to the glyph image type descriptor.</param>
/// <param name="gIndex">The glyph index.</param>
/// <param name="node">
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
/// note below).
/// </param>
/// <returns>A handle to a small bitmap descriptor.</returns>
[CLSCompliant(false)]
public SBit Lookup(ImageType type, uint gIndex, out Node node)
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
IntPtr sbitRef, nodeRef;
Error err = FT.FTC_SBitCache_Lookup(Reference, type.Reference, gIndex, out sbitRef, out nodeRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
node = new Node(nodeRef);
return new SBit(sbitRef);
}
/// <summary>
/// A variant of <see cref="SBitCache.Lookup"/> that uses a <see cref="Scaler"/> to specify the face ID and its
/// size.
/// </summary>
/// <remarks><para>
/// The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the
/// application. They might as well disappear from memory on the next cache lookup, so don't treat them as
/// persistent data.
/// </para><para>
/// The descriptor's buffer field is set to 0 to indicate a missing glyph bitmap.
/// </para><para>
/// If node is not NULL, it receives the address of the cache node containing the bitmap, after
/// increasing its reference count. This ensures that the node (as well as the image) will always be kept in
/// the cache until you call <see cref="Node.Unref"/> to release it.
/// </para><para>
/// If node is NULL, the cache node is left unchanged, which means that the bitmap could be
/// flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is
/// persistent!
/// </para></remarks>
/// <param name="scaler">A pointer to the scaler descriptor.</param>
/// <param name="loadFlags">The corresponding load flags.</param>
/// <param name="gIndex">The glyph index.</param>
/// <param name="node">
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
/// note below).
/// </param>
/// <returns>A handle to a small bitmap descriptor.</returns>
[CLSCompliant(false)]
public SBit LookupScaler(Scaler scaler, LoadFlags loadFlags, uint gIndex, out Node node)
{
if (parentManager.IsDisposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
IntPtr sbitRef, nodeRef;
Error err = FT.FTC_SBitCache_LookupScaler(Reference, scaler.Reference, loadFlags, gIndex, out sbitRef, out nodeRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
node = new Node(nodeRef);
return new SBit(sbitRef);
}
#endregion
}
}

View File

@@ -0,0 +1,146 @@
#region MIT License
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Cache.Internal;
namespace SharpFont.Cache
{
/// <summary>
/// A structure used to describe a given character size in either pixels or points to the cache manager.
/// </summary>
/// <remarks>
/// This type is mainly used to retrieve <see cref="FTSize"/> objects through the cache manager.
/// </remarks>
/// <see cref="Manager.LookupSize"/>
public class Scaler
{
#region Fields
private IntPtr reference;
private ScalerRec rec;
#endregion
#region Constructors
internal Scaler(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the source face ID.
/// </summary>
public IntPtr FaceId
{
get
{
return rec.face_id;
}
}
/// <summary>
/// Gets the character width.
/// </summary>
[CLSCompliant(false)]
public uint Width
{
get
{
return rec.width;
}
}
/// <summary>
/// Gets the character height.
/// </summary>
[CLSCompliant(false)]
public uint Height
{
get
{
return rec.height;
}
}
/// <summary>
/// Gets a value indicating whether the width and height fields are interpreted as integer pixel character
/// sizes. Otherwise, they are expressed as 1/64th of points.
/// </summary>
public bool Pixel
{
get
{
return rec.pixel == 1;
}
}
/// <summary>
/// Gets the horizontal resolution in dpi; only used when pixel is value 0.
/// </summary>
[CLSCompliant(false)]
public uint ResolutionX
{
get
{
return rec.x_res;
}
}
/// <summary>
/// Gets the vertical resolution in dpi; only used when pixel is value 0.
/// </summary>
[CLSCompliant(false)]
public uint ResolutionY
{
get
{
return rec.y_res;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<ScalerRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,40 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Cff
{
/// <summary>
/// A list of constants used for the hinting-engine property to select the hinting engine for CFF fonts.
/// </summary>
public enum HintingEngine
{
/// <summary>Use the old FreeType hinting engine.</summary>
FreeType = 0,
/// <summary>Use the hinting engine contributed by Adobe.</summary>
Adobe = 1
}
}

View File

@@ -0,0 +1,170 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
using SharpFont.TrueType;
namespace SharpFont
{
/// <summary>
/// The base charmap structure.
/// </summary>
public sealed class CharMap
{
#region Fields
private IntPtr reference;
private CharMapRec rec;
private Face parentFace;
#endregion
#region Constructors
internal CharMap(IntPtr reference, Face parent)
{
Reference = reference;
this.parentFace = parent;
}
#endregion
#region Properties
/// <summary>
/// Gets a handle to the parent face object.
/// </summary>
public Face Face
{
get
{
return parentFace;
}
}
/// <summary>
/// Gets an <see cref="Encoding"/> tag identifying the charmap. Use this with
/// <see cref="SharpFont.Face.SelectCharmap"/>.
/// </summary>
[CLSCompliant(false)]
public Encoding Encoding
{
get
{
return rec.encoding;
}
}
/// <summary>
/// Gets an ID number describing the platform for the following encoding ID. This comes directly from the
/// TrueType specification and should be emulated for other formats.
/// </summary>
[CLSCompliant(false)]
public PlatformId PlatformId
{
get
{
return rec.platform_id;
}
}
/// <summary>
/// Gets a platform specific encoding number. This also comes from the TrueType specification and should be
/// emulated similarly.
/// </summary>
[CLSCompliant(false)]
public ushort EncodingId
{
get
{
//TODO find some way of getting a proper encoding ID enum...
return rec.encoding_id;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<CharMapRec>(reference);
}
}
#endregion
#region Methods
#region Base Interface
/// <summary>
/// Retrieve index of a given charmap.
/// </summary>
/// <returns>The index into the array of character maps within the face to which charmap belongs.</returns>
public int GetCharmapIndex()
{
return FT.FT_Get_Charmap_Index(Reference);
}
#endregion
#region TrueType Tables
/// <summary>
/// Return TrueType/sfnt specific cmap language ID. Definitions of language ID values are in
/// freetype/ttnameid.h.
/// </summary>
/// <returns>
/// The language ID of charmap. If charmap doesn't belong to a TrueType/sfnt face, just return 0 as the
/// default value.
/// </returns>
[CLSCompliant(false)]
public uint GetCMapLanguageId()
{
return FT.FT_Get_CMap_Language_ID(Reference);
}
/// <summary>
/// Return TrueType/sfnt specific cmap format.
/// </summary>
/// <returns>The format of charmap. If charmap doesn't belong to a TrueType/sfnt face, return -1.</returns>
public int GetCMapFormat()
{
return FT.FT_Get_CMap_Format(Reference);
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,47 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// A list of bit-field constants used with <see cref="Face.ClassicKernValidate"/> to indicate the classic kern
/// dialect or dialects. If the selected type doesn't fit, <see cref="Face.ClassicKernValidate"/> regards the table
/// as invalid.
/// </summary>
[Flags]
[CLSCompliant(false)]
public enum ClassicKernValidationFlags : uint
{
/// <summary>Handle the kern table as a classic Microsoft kern table.</summary>
Microsoft = 0x4000 << 0,
/// <summary>Handle the kern table as a classic Apple kern table.</summary>
Apple = 0x4000 << 1,
/// <summary>Handle the kern as either classic Apple or Microsoft kern table.</summary>
All = Microsoft | Apple
}
}

View File

@@ -0,0 +1,89 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// Read-only binary data represented as a pointer and a length.
/// </summary>
public sealed class Data
{
#region Fields
private IntPtr reference;
#endregion
#region Constructors
internal Data(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the data.
/// </summary>
public IntPtr Pointer
{
get
{
return Marshal.ReadIntPtr(reference, 0);
}
}
/// <summary>
/// Gets the length of the data in bytes.
/// </summary>
public int Length
{
get
{
return Marshal.ReadInt32(reference, IntPtr.Size);
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,88 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// A list of bit flags used in the fsType field of the OS/2 table in a
/// TrueType or OpenType font and the FSType entry in a PostScript font.
/// These bit flags are returned by FT_Get_FSType_Flags; they inform client
/// applications of embedding and subsetting restrictions associated with a
/// font.
/// </summary>
/// <remarks>
/// While the fsType flags can indicate that a font may be embedded, a
/// license with the font vendor may be separately required to use the font
/// in this way.
/// </remarks>
/// <see href="http://www.adobe.com/devnet/acrobat/pdfs/FontPolicies.pdf"/>
[Flags]
[CLSCompliant(false)]
public enum EmbeddingTypes : ushort
{
/// <summary>
/// Fonts with no fsType bit set may be embedded and permanently
/// installed on the remote system by an application.
/// </summary>
Installable = 0x0000,
/// <summary>
/// Fonts that have only this bit set must not be modified, embedded
/// or exchanged in any manner without first obtaining permission of
/// the font software copyright owner.
/// </summary>
RestrictedLicense = 0x0002,
/// <summary>
/// If this bit is set, the font may be embedded and temporarily loaded
/// on the remote system. Documents containing Preview &amp; Print
/// fonts must be opened read-only; no edits can be applied to the
/// document.
/// </summary>
PreviewAndPrint = 0x0004,
/// <summary>
/// If this bit is set, the font may be embedded but must only be
/// installed temporarily on other systems. In contrast to Preview
/// &amp; Print fonts, documents containing editable fonts may be
/// opened for reading, editing is permitted, and changes may be saved.
/// </summary>
Editable = 0x0008,
/// <summary>
/// If this bit is set, the font may not be subsetted prior to
/// embedding.
/// </summary>
NoSubsetting = 0x0100,
/// <summary>
/// If this bit is set, only bitmaps contained in the font may be
/// embedded; no outline data may be embedded. If there are no bitmaps
/// available in the font, then the font is unembeddable.
/// </summary>
BitmapOnly = 0x0200
}
}

View File

@@ -0,0 +1,135 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// An enumeration used to specify character sets supported by charmaps.
/// Used in the FT_Select_Charmap API function.
/// </summary>
/// <remarks><para>
/// Despite the name, this enumeration lists specific character repertories
/// (i.e., charsets), and not text encoding methods (e.g., UTF-8, UTF-16,
/// etc.).
/// </para><para>
/// Other encodings might be defined in the future.
/// </para></remarks>
[CLSCompliant(false)]
public enum Encoding : uint
{
/// <summary>
/// The encoding value 0 is reserved.
/// </summary>
None = 0,
/// <summary>
/// Corresponds to the Microsoft Symbol encoding, used to encode
/// mathematical symbols in the 32..255 character code range.
/// </summary>
/// <see href="http://www.ceviz.net/symbol.htm"/>
MicrosoftSymbol = ('s' << 24 | 'y' << 16 | 'm' << 8 | 'b'),
/// <summary><para>
/// Corresponds to the Unicode character set. This value covers all
/// versions of the Unicode repertoire, including ASCII and Latin-1.
/// Most fonts include a Unicode charmap, but not all of them.
/// </para><para>
/// For example, if you want to access Unicode value U+1F028 (and the
/// font contains it), use value 0x1F028 as the input value for
/// FT_Get_Char_Index.
/// </para></summary>
Unicode = ('u' << 24 | 'n' << 16 | 'i' << 8 | 'c'),
/// <summary>
/// Corresponds to Japanese SJIS encoding.
/// </summary>
/// <see href="http://langsupport.japanreference.com/encoding.shtml"/>
Sjis = ('s' << 24 | 'j' << 16 | 'i' << 8 | 's'),
/// <summary>
/// Corresponds to an encoding system for Simplified Chinese as used
/// used in mainland China.
/// </summary>
GB2312 = ('g' << 24 | 'b' << 16 | ' ' << 8 | ' '),
/// <summary>
/// Corresponds to an encoding system for Traditional Chinese as used
/// in Taiwan and Hong Kong.
/// </summary>
Big5 = ('b' << 24 | 'i' << 16 | 'g' << 8 | '5'),
/// <summary>
/// Corresponds to the Korean encoding system known as Wansung.
/// </summary>
/// <see href="http://www.microsoft.com/typography/unicode/949.txt"/>
Wansung = ('w' << 24 | 'a' << 16 | 'n' << 8 | 's'),
/// <summary>
/// The Korean standard character set (KS C 5601-1992), which
/// corresponds to MS Windows code page 1361. This character set
/// includes all possible Hangeul character combinations.
/// </summary>
Johab = ('j' << 24 | 'o' << 16 | 'h' << 8 | 'a'),
/// <summary>
/// Corresponds to the Adobe Standard encoding, as found in Type 1,
/// CFF, and OpenType/CFF fonts. It is limited to 256 character codes.
/// </summary>
AdobeStandard = ('A' << 24 | 'D' << 16 | 'O' << 8 | 'B'),
/// <summary>
/// Corresponds to the Adobe Expert encoding, as found in Type 1, CFF,
/// and OpenType/CFF fonts. It is limited to 256 character codes.
/// </summary>
AdobeExpert = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'E'),
/// <summary>
/// Corresponds to a custom encoding, as found in Type 1, CFF, and
/// OpenType/CFF fonts. It is limited to 256 character codes.
/// </summary>
AdobeCustom = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'C'),
/// <summary>
/// Corresponds to a Latin-1 encoding as defined in a Type 1 PostScript
/// font. It is limited to 256 character codes.
/// </summary>
AdobeLatin1 = ('l' << 24 | 'a' << 16 | 't' << 8 | '1'),
/// <summary>
/// This value is deprecated and was never used nor reported by
/// FreeType. Don't use or test for it.
/// </summary>
[Obsolete("Never used nor reported by FreeType")]
OldLatin2 = ('l' << 24 | 'a' << 16 | 't' << 8 | '2'),
/// <summary>
/// Corresponds to the 8-bit Apple roman encoding. Many TrueType and
/// OpenType fonts contain a charmap for this encoding, since older
/// versions of Mac OS are able to use it.
/// </summary>
AppleRoman = ('a' << 24 | 'r' << 16 | 'm' << 8 | 'n'),
}
}

View File

@@ -0,0 +1,298 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// FreeType error codes.
/// </summary>
public enum Error
{
/// <summary>No error.</summary>
Ok = 0x00,
/// <summary>Cannot open resource.</summary>
CannotOpenResource = 0x01,
/// <summary>Unknown file format.</summary>
UnknownFileFormat = 0x02,
/// <summary>Broken file.</summary>
InvalidFileFormat = 0x03,
/// <summary>Invalid FreeType version.</summary>
InvalidVersion = 0x04,
/// <summary>Module version is too low.</summary>
LowerModuleVersion = 0x05,
/// <summary>Invalid argument.</summary>
InvalidArgument = 0x06,
/// <summary>Unimplemented feature.</summary>
UnimplementedFeature = 0x07,
/// <summary>Broken table.</summary>
InvalidTable = 0x08,
/// <summary>Broken offset within table.</summary>
InvalidOffset = 0x09,
/// <summary>Array allocation size too large.</summary>
ArrayTooLarge = 0x0A,
/// <summary>Invalid glyph index.</summary>
InvalidGlyphIndex = 0x10,
/// <summary>Invalid character code.</summary>
InvalidCharacterCode = 0x11,
/// <summary>Unsupported glyph image format.</summary>
InvalidGlyphFormat = 0x12,
/// <summary>Cannot render this glyph format.</summary>
CannotRenderGlyph = 0x13,
/// <summary>Invalid outline.</summary>
InvalidOutline = 0x14,
/// <summary>Invalid composite glyph.</summary>
InvalidComposite = 0x15,
/// <summary>Too many hints.</summary>
TooManyHints = 0x16,
/// <summary>Invalid pixel size.</summary>
InvalidPixelSize = 0x17,
/// <summary>Invalid object handle.</summary>
InvalidHandle = 0x20,
/// <summary>Invalid library handle.</summary>
InvalidLibraryHandle = 0x21,
/// <summary>Invalid module handle.</summary>
InvalidDriverHandle = 0x22,
/// <summary>Invalid face handle.</summary>
InvalidFaceHandle = 0x23,
/// <summary>Invalid size handle.</summary>
InvalidSizeHandle = 0x24,
/// <summary>Invalid glyph slot handle.</summary>
InvalidSlotHandle = 0x25,
/// <summary>Invalid charmap handle.</summary>
InvalidCharMapHandle = 0x26,
/// <summary>Invalid cache manager handle.</summary>
InvalidCacheHandle = 0x27,
/// <summary>Invalid stream handle.</summary>
InvalidStreamHandle = 0x28,
/// <summary>Too many modules.</summary>
TooManyDrivers = 0x30,
/// <summary>Too many extensions.</summary>
TooManyExtensions = 0x31,
/// <summary>Out of memory.</summary>
OutOfMemory = 0x40,
/// <summary>Unlisted object.</summary>
UnlistedObject = 0x41,
/// <summary>Cannot open stream.</summary>
CannotOpenStream = 0x51,
/// <summary>Invalid stream seek.</summary>
InvalidStreamSeek = 0x52,
/// <summary>Invalid stream skip.</summary>
InvalidStreamSkip = 0x53,
/// <summary>Invalid stream read.</summary>
InvalidStreamRead = 0x54,
/// <summary>Invalid stream operation.</summary>
InvalidStreamOperation = 0x55,
/// <summary>Invalid frame operation.</summary>
InvalidFrameOperation = 0x56,
/// <summary>Nested frame access.</summary>
NestedFrameAccess = 0x57,
/// <summary>Invalid frame read.</summary>
InvalidFrameRead = 0x58,
/// <summary>Raster uninitialized.</summary>
RasterUninitialized = 0x60,
/// <summary>Raster corrupted.</summary>
RasterCorrupted = 0x61,
/// <summary>Raster overflow.</summary>
RasterOverflow = 0x62,
/// <summary>Negative height while rastering.</summary>
RasterNegativeHeight = 0x63,
/// <summary>Too many registered caches.</summary>
TooManyCaches = 0x70,
/// <summary>Invalid opcode.</summary>
InvalidOpCode = 0x80,
/// <summary>Too few arguments.</summary>
TooFewArguments = 0x81,
/// <summary>Stack overflow.</summary>
StackOverflow = 0x82,
/// <summary>Code overflow.</summary>
CodeOverflow = 0x83,
/// <summary>Bad argument.</summary>
BadArgument = 0x84,
/// <summary>Division by zero.</summary>
DivideByZero = 0x85,
/// <summary>Invalid reference.</summary>
InvalidReference = 0x86,
/// <summary>Found debug opcode.</summary>
DebugOpCode = 0x87,
/// <summary>Found ENDF opcode in execution stream.</summary>
EndfInExecStream = 0x88,
/// <summary>Nested DEFS.</summary>
NestedDefs = 0x89,
/// <summary>Invalid code range.</summary>
InvalidCodeRange = 0x8A,
/// <summary>Execution context too long.</summary>
ExecutionTooLong = 0x8B,
/// <summary>Too many function definitions.</summary>
TooManyFunctionDefs = 0x8C,
/// <summary>Too many instruction definitions.</summary>
TooManyInstructionDefs = 0x8D,
/// <summary>SFNT font table missing.</summary>
TableMissing = 0x8E,
/// <summary>Horizontal header (hhea) table missing.</summary>
HorizHeaderMissing = 0x8F,
/// <summary>Locations (loca) table missing.</summary>
LocationsMissing = 0x90,
/// <summary>Name table missing.</summary>
NameTableMissing = 0x91,
/// <summary>Character map (cmap) table missing.</summary>
CMapTableMissing = 0x92,
/// <summary>Horizontal metrics (hmtx) table missing.</summary>
HmtxTableMissing = 0x93,
/// <summary>PostScript (post) table missing.</summary>
PostTableMissing = 0x94,
/// <summary>Invalid horizontal metrics.</summary>
InvalidHorizMetrics = 0x95,
/// <summary>Invalid character map (cmap) format.</summary>
InvalidCharMapFormat = 0x96,
/// <summary>Invalid ppem value.</summary>
InvalidPPem = 0x97,
/// <summary>Invalid vertical metrics.</summary>
InvalidVertMetrics = 0x98,
/// <summary>Could not find context.</summary>
CouldNotFindContext = 0x99,
/// <summary>Invalid PostScript (post) table format.</summary>
InvalidPostTableFormat = 0x9A,
/// <summary>Invalid PostScript (post) table.</summary>
InvalidPostTable = 0x9B,
/// <summary>Opcode syntax error.</summary>
SyntaxError = 0xA0,
/// <summary>Argument stack underflow.</summary>
StackUnderflow = 0xA1,
/// <summary>Ignore this error.</summary>
Ignore = 0xA2,
/// <summary>No Unicode glyph name found.</summary>
NoUnicodeGlyphName = 0xA3,
/// <summary>`STARTFONT' field missing.</summary>
MissingStartfontField = 0xB0,
/// <summary>`FONT' field missing.</summary>
MissingFontField = 0xB1,
/// <summary>`SIZE' field missing.</summary>
MissingSizeField = 0xB2,
/// <summary>`FONTBOUNDINGBOX' field missing.</summary>
MissingFontboudingboxField = 0xB3,
/// <summary>`CHARS' field missing.</summary>
MissingCharsField = 0xB4,
/// <summary>`STARTCHAR' field missing.</summary>
MissingStartcharField = 0xB5,
/// <summary>`ENCODING' field missing.</summary>
MissingEncodingField = 0xB6,
/// <summary>`BBX' field missing.</summary>
MissingBbxField = 0xB7,
/// <summary>`BBX' too big.</summary>
BbxTooBig = 0xB8,
/// <summary>Font header corrupted or missing fields.</summary>
CorruptedFontHeader = 0xB9,
/// <summary>Font glyphs corrupted or missing fields.</summary>
CorruptedFontGlyphs = 0xBA
}
}

View File

@@ -0,0 +1,770 @@
#region MIT License
/*Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Cache;
using SharpFont.Internal;
using SharpFont.PostScript;
using SharpFont.TrueType;
namespace SharpFont
{
/// <content>
/// This file contains all the raw FreeType2 function signatures.
/// </content>
public static partial class FT
{
/// <summary>
/// Defines the location of the FreeType DLL. Update SharpFont.dll.config if you change this!
/// </summary>
#if SHARPFONT_PLATFORM_IOS
private const string FreetypeDll = "__Internal";
#else
private const string FreetypeDll = "freetype6";
#endif
/// <summary>
/// Defines the calling convention for P/Invoking the native freetype methods.
/// </summary>
private const CallingConvention CallConvention = CallingConvention.Cdecl;
#region Core API
#region FreeType Version
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Library_Version(IntPtr library, out int amajor, out int aminor, out int apatch);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool FT_Face_CheckTrueTypePatents(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool FT_Face_SetUnpatentedHinting(IntPtr face, [MarshalAs(UnmanagedType.U1)] bool value);
#endregion
#region Base Interface
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Init_FreeType(out IntPtr alibrary);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Done_FreeType(IntPtr library);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_New_Face(IntPtr library, string filepathname, int face_index, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Memory_Face(IntPtr library, IntPtr file_base, int file_size, int face_index, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Open_Face(IntPtr library, IntPtr args, int face_index, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Attach_File(IntPtr face, string filepathname);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Attach_Stream(IntPtr face, IntPtr parameters);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Reference_Face(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Done_Face(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Select_Size(IntPtr face, int strike_index);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Request_Size(IntPtr face, IntPtr req);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Char_Size(IntPtr face, IntPtr char_width, IntPtr char_height, uint horz_resolution, uint vert_resolution);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Pixel_Sizes(IntPtr face, uint pixel_width, uint pixel_height);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Load_Glyph(IntPtr face, uint glyph_index, int load_flags);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Load_Char(IntPtr face, uint char_code, int load_flags);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Set_Transform(IntPtr face, IntPtr matrix, IntPtr delta);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Render_Glyph(IntPtr slot, RenderMode render_mode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Kerning(IntPtr face, uint left_glyph, uint right_glyph, uint kern_mode, out FTVector26Dot6 akerning);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Track_Kerning(IntPtr face, IntPtr point_size, int degree, out IntPtr akerning);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Glyph_Name(IntPtr face, uint glyph_index, IntPtr buffer, uint buffer_max);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Get_Postscript_Name(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Select_Charmap(IntPtr face, Encoding encoding);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Charmap(IntPtr face, IntPtr charmap);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern int FT_Get_Charmap_Index(IntPtr charmap);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_Char_Index(IntPtr face, uint charcode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_First_Char(IntPtr face, out uint agindex);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_Next_Char(IntPtr face, uint char_code, out uint agindex);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_Name_Index(IntPtr face, IntPtr glyph_name);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_SubGlyph_Info(IntPtr glyph, uint sub_index, out int p_index, out SubGlyphFlags p_flags, out int p_arg1, out int p_arg2, out FTMatrix p_transform);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern EmbeddingTypes FT_Get_FSType_Flags(IntPtr face);
#endregion
#region Glyph Variants
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Face_GetCharVariantIndex(IntPtr face, uint charcode, uint variantSelector);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern int FT_Face_GetCharVariantIsDefault(IntPtr face, uint charcode, uint variantSelector);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Face_GetVariantSelectors(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Face_GetVariantsOfChar(IntPtr face, uint charcode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Face_GetCharsOfVariant(IntPtr face, uint variantSelector);
#endregion
#region Glyph Management
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Glyph(IntPtr slot, out IntPtr aglyph);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Glyph_Copy(IntPtr source, out IntPtr target);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Glyph_Transform(IntPtr glyph, ref FTMatrix matrix, ref FTVector delta);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Glyph_Get_CBox(IntPtr glyph, GlyphBBoxMode bbox_mode, out BBox acbox);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Glyph_To_Bitmap(ref IntPtr the_glyph, RenderMode render_mode, ref FTVector26Dot6 origin, [MarshalAs(UnmanagedType.U1)] bool destroy);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Done_Glyph(IntPtr glyph);
#endregion
#if !SHARPFONT_PLATFORM_IOS
#region Mac Specific Interface
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Face_From_FOND(IntPtr library, IntPtr fond, int face_index, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_GetFile_From_Mac_Name(string fontName, out IntPtr pathSpec, out int face_index);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_GetFile_From_Mac_ATS_Name(string fontName, out IntPtr pathSpec, out int face_index);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_GetFilePath_From_Mac_ATS_Name(string fontName, IntPtr path, int maxPathSize, out int face_index);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Face_From_FSSpec(IntPtr library, IntPtr spec, int face_index, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Face_From_FSRef(IntPtr library, IntPtr @ref, int face_index, out IntPtr aface);
#endregion
#endif
#region Size Management
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Size(IntPtr face, out IntPtr size);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Done_Size(IntPtr size);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Activate_Size(IntPtr size);
#endregion
#endregion
#region Format-Specific API
#region Multiple Masters
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Multi_Master(IntPtr face, out IntPtr amaster);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_MM_Var(IntPtr face, out IntPtr amaster);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_MM_Design_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Var_Design_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_MM_Blend_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Var_Blend_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
#endregion
#region TrueType Tables
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Get_Sfnt_Table(IntPtr face, SfntTag tag);
//TODO find FT_TRUETYPE_TAGS_H and create an enum for "tag"
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Load_Sfnt_Table(IntPtr face, uint tag, int offset, IntPtr buffer, ref uint length);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static unsafe extern Error FT_Sfnt_Table_Info(IntPtr face, uint table_index, SfntTag* tag, out uint length);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_CMap_Language_ID(IntPtr charmap);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern int FT_Get_CMap_Format(IntPtr charmap);
#endregion
#region Type 1 Tables
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool FT_Has_PS_Glyph_Names(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_PS_Font_Info(IntPtr face, out PostScript.Internal.FontInfoRec afont_info);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_PS_Font_Private(IntPtr face, out PostScript.Internal.PrivateRec afont_private);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern int FT_Get_PS_Font_Value(IntPtr face, DictionaryKeys key, uint idx, ref IntPtr value, int value_len);
#endregion
#region SFNT Names
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FT_Get_Sfnt_Name_Count(IntPtr face);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Sfnt_Name(IntPtr face, uint idx, out TrueType.Internal.SfntNameRec aname);
#endregion
#region BDF and PCF Files
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Get_BDF_Charset_ID(IntPtr face, out string acharset_encoding, out string acharset_registry);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Get_BDF_Property(IntPtr face, string prop_name, out IntPtr aproperty);
#endregion
#region CID Fonts
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Get_CID_Registry_Ordering_Supplement(IntPtr face, out string registry, out string ordering, out int aproperty);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_CID_Is_Internally_CID_Keyed(IntPtr face, out byte is_cid);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_CID_From_Glyph_Index(IntPtr face, uint glyph_index, out uint cid);
#endregion
#region PFR Fonts
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_PFR_Metrics(IntPtr face, out uint aoutline_resolution, out uint ametrics_resolution, out IntPtr ametrics_x_scale, out IntPtr ametrics_y_scale);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_PFR_Kerning(IntPtr face, uint left, uint right, out FTVector avector);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_PFR_Advance(IntPtr face, uint gindex, out int aadvance);
#endregion
#region Window FNT Files
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_WinFNT_Header(IntPtr face, out IntPtr aheader);
#endregion
#region Font Formats
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Get_X11_Font_Format(IntPtr face);
#endregion
#region Gasp Table
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Gasp FT_Get_Gasp(IntPtr face, uint ppem);
#endregion
#endregion
#region Support API
#region Computations
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_MulDiv(IntPtr a, IntPtr b, IntPtr c);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_MulFix(IntPtr a, IntPtr b);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_DivFix(IntPtr a, IntPtr b);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_RoundFix(IntPtr a);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_CeilFix(IntPtr a);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_FloorFix(IntPtr a);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Vector_Transform(ref FTVector vec, ref FTMatrix matrix);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Matrix_Multiply(ref FTMatrix a, ref FTMatrix b);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Matrix_Invert(ref FTMatrix matrix);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Sin(IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Cos(IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Tan(IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Atan2(IntPtr x, IntPtr y);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Angle_Diff(IntPtr angle1, IntPtr angle2);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Vector_Unit(out FTVector vec, IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Vector_Rotate(ref FTVector vec, IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Vector_Length(ref FTVector vec);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Vector_Polarize(ref FTVector vec, out IntPtr length, out IntPtr angle);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Vector_From_Polar(out FTVector vec, IntPtr length, IntPtr angle);
#endregion
#region List Processing
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_List_Find(IntPtr list, IntPtr data);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_List_Add(IntPtr list, IntPtr node);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_List_Insert(IntPtr list, IntPtr node);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_List_Remove(IntPtr list, IntPtr node);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_List_Up(IntPtr list, IntPtr node);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_List_Iterate(IntPtr list, ListIterator iterator, IntPtr user);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_List_Finalize(IntPtr list, ListDestructor destroy, IntPtr memory, IntPtr user);
#endregion
#region Outline Processing
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_New(IntPtr library, uint numPoints, int numContours, out IntPtr anoutline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_New_Internal(IntPtr memory, uint numPoints, int numContours, out IntPtr anoutline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Done(IntPtr library, IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Done_Internal(IntPtr memory, IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Copy(IntPtr source, ref IntPtr target);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Outline_Translate(IntPtr outline, int xOffset, int yOffset);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Outline_Transform(IntPtr outline, ref FTMatrix matrix);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Embolden(IntPtr outline, IntPtr strength);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_EmboldenXY(IntPtr outline, int xstrength, int ystrength);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Outline_Reverse(IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Check(IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Get_BBox(IntPtr outline, out BBox abbox);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Decompose(IntPtr outline, ref OutlineFuncsRec func_interface, IntPtr user);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Outline_Get_CBox(IntPtr outline, out BBox acbox);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Get_Bitmap(IntPtr library, IntPtr outline, IntPtr abitmap);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Outline_Render(IntPtr library, IntPtr outline, IntPtr @params);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Orientation FT_Outline_Get_Orientation(IntPtr outline);
#endregion
#region Quick retrieval of advance values
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Advance(IntPtr face, uint gIndex, LoadFlags load_flags, out IntPtr padvance);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Get_Advances(IntPtr face, uint start, uint count, LoadFlags load_flags, out IntPtr padvance);
#endregion
#region Bitmap Handling
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Bitmap_New(IntPtr abitmap);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Bitmap_Copy(IntPtr library, IntPtr source, IntPtr target);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Bitmap_Embolden(IntPtr library, IntPtr bitmap, IntPtr xStrength, IntPtr yStrength);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Bitmap_Convert(IntPtr library, IntPtr source, IntPtr target, int alignment);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_GlyphSlot_Own_Bitmap(IntPtr slot);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Bitmap_Done(IntPtr library, IntPtr bitmap);
#endregion
#region Glyph Stroker
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern StrokerBorder FT_Outline_GetInsideBorder(IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern StrokerBorder FT_Outline_GetOutsideBorder(IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_New(IntPtr library, out IntPtr astroker);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Stroker_Set(IntPtr stroker, int radius, StrokerLineCap line_cap, StrokerLineJoin line_join, IntPtr miter_limit);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Stroker_Rewind(IntPtr stroker);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_ParseOutline(IntPtr stroker, IntPtr outline, [MarshalAs(UnmanagedType.U1)] bool opened);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_BeginSubPath(IntPtr stroker, ref FTVector to, [MarshalAs(UnmanagedType.U1)] bool open);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_EndSubPath(IntPtr stroker);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_LineTo(IntPtr stroker, ref FTVector to);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_ConicTo(IntPtr stroker, ref FTVector control, ref FTVector to);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_CubicTo(IntPtr stroker, ref FTVector control1, ref FTVector control2, ref FTVector to);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_GetBorderCounts(IntPtr stroker, StrokerBorder border, out uint anum_points, out uint anum_contours);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Stroker_ExportBorder(IntPtr stroker, StrokerBorder border, IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stroker_GetCounts(IntPtr stroker, out uint anum_points, out uint anum_contours);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Stroker_Export(IntPtr stroker, IntPtr outline);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Stroker_Done(IntPtr stroker);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Glyph_Stroke(ref IntPtr pglyph, IntPtr stoker, [MarshalAs(UnmanagedType.U1)] bool destroy);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Glyph_StrokeBorder(ref IntPtr pglyph, IntPtr stoker, [MarshalAs(UnmanagedType.U1)] bool inside, [MarshalAs(UnmanagedType.U1)] bool destroy);
#endregion
#region Module Management
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Add_Module(IntPtr library, IntPtr clazz);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern IntPtr FT_Get_Module(IntPtr library, string module_name);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Remove_Module(IntPtr library, IntPtr module);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Property_Set(IntPtr library, string module_name, string property_name, IntPtr value);
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern Error FT_Property_Get(IntPtr library, string module_name, string property_name, IntPtr value);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Reference_Library(IntPtr library);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_New_Library(IntPtr memory, out IntPtr alibrary);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Done_Library(IntPtr library);
//TODO figure out the method signature for debug_hook. (FT_DebugHook_Func)
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Set_Debug_Hook(IntPtr library, uint hook_index, IntPtr debug_hook);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_Add_Default_Modules(IntPtr library);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern IntPtr FT_Get_Renderer(IntPtr library, GlyphFormat format);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Set_Renderer(IntPtr library, IntPtr renderer, uint num_params, IntPtr parameters);
#endregion
#region GZIP Streams
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stream_OpenGzip(IntPtr stream, IntPtr source);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Gzip_Uncompress(IntPtr memory, IntPtr output, ref IntPtr output_len, IntPtr input, IntPtr input_len);
#endregion
#region LZW Streams
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stream_OpenLZW(IntPtr stream, IntPtr source);
#endregion
#region BZIP2 Streams
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Stream_OpenBzip2(IntPtr stream, IntPtr source);
#endregion
#region LCD Filtering
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Library_SetLcdFilter(IntPtr library, LcdFilter filter);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_Library_SetLcdFilterWeights(IntPtr library, byte[] weights);
#endregion
#endregion
#region Caching Sub-system
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_Manager_New(IntPtr library, uint max_faces, uint max_sizes, ulong maxBytes, FaceRequester requester, IntPtr req_data, out IntPtr amanager);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FTC_Manager_Reset(IntPtr manager);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FTC_Manager_Done(IntPtr manager);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_Manager_LookupFace(IntPtr manager, IntPtr face_id, out IntPtr aface);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_Manager_LookupSize(IntPtr manager, IntPtr scaler, out IntPtr asize);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FTC_Node_Unref(IntPtr node, IntPtr manager);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FTC_Manager_RemoveFaceID(IntPtr manager, IntPtr face_id);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_CMapCache_New(IntPtr manager, out IntPtr acache);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern uint FTC_CMapCache_Lookup(IntPtr cache, IntPtr face_id, int cmap_index, uint char_code);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_ImageCache_New(IntPtr manager, out IntPtr acache);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_ImageCache_Lookup(IntPtr cache, IntPtr type, uint gindex, out IntPtr aglyph, out IntPtr anode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_ImageCache_LookupScaler(IntPtr cache, IntPtr scaler, LoadFlags load_flags, uint gindex, out IntPtr aglyph, out IntPtr anode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_SBitCache_New(IntPtr manager, out IntPtr acache);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_SBitCache_Lookup(IntPtr cache, IntPtr type, uint gindex, out IntPtr sbit, out IntPtr anode);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FTC_SBitCache_LookupScaler(IntPtr cache, IntPtr scaler, LoadFlags load_flags, uint gindex, out IntPtr sbit, out IntPtr anode);
#endregion
#region Miscellaneous
#region OpenType Validation
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_OpenType_Validate(IntPtr face, OpenTypeValidationFlags validation_flags, out IntPtr base_table, out IntPtr gdef_table, out IntPtr gpos_table, out IntPtr gsub_table, out IntPtr jsft_table);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern void FT_OpenType_Free(IntPtr face, IntPtr table);
#endregion
#region The TrueType Engine
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern EngineType FT_Get_TrueType_Engine_Type(IntPtr library);
#endregion
#region TrueTypeGX/AAT Validation
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_TrueTypeGX_Validate(IntPtr face, TrueTypeValidationFlags validation_flags, byte[][] tables, uint tableLength);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_TrueTypeGX_Free(IntPtr face, IntPtr table);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_ClassicKern_Validate(IntPtr face, ClassicKernValidationFlags validation_flags, out IntPtr ckern_table);
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
internal static extern Error FT_ClassicKern_Free(IntPtr face, IntPtr table);
#endregion
#endregion
}
}

View File

@@ -0,0 +1,262 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// Miscellaneous FreeType2 functions that don't fit anywhere else.
/// </summary>
public static partial class FT
{
#region Computations
/// <summary><para>
/// A very simple function used to perform the computation (a*b)/c with maximal accuracy (it uses a 64-bit
/// intermediate integer whenever necessary).
/// </para><para>
/// This function isn't necessarily as fast as some processor specific operations, but is at least completely
/// portable.
/// </para></summary>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier.</param>
/// <param name="c">The divisor.</param>
/// <returns>
/// The result of (a*b)/c. This function never traps when trying to divide by zero; it simply returns
/// MaxInt or MinInt depending on the signs of a and b.
/// </returns>
[Obsolete("Use Fixed16Dot16.MultiplyDivide() instead.")]
public static Fixed16Dot16 MulDiv(Fixed16Dot16 a, Fixed16Dot16 b, Fixed16Dot16 c)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_MulDiv((IntPtr)a.Value, (IntPtr)b.Value, (IntPtr)c.Value));
}
/// <summary>
/// A very simple function used to perform the computation (a*b)/0x10000 with maximal accuracy. Most of the
/// time this is used to multiply a given value by a 16.16 fixed float factor.
/// </summary>
/// <remarks><para>
/// This function has been optimized for the case where the absolute value of a is less than 2048, and b is
/// a 16.16 scaling factor. As this happens mainly when scaling from notional units to fractional pixels in
/// FreeType, it resulted in noticeable speed improvements between versions 2.x and 1.x.
/// </para><para>
/// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make
/// a great difference.
/// </para></remarks>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
/// <returns>The result of (a*b)/0x10000.</returns>
[Obsolete("Use Fixed16Dot16.MultiplyFix() instead.")]
public static Fixed16Dot16 MulFix(int a, Fixed16Dot16 b)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_MulFix((IntPtr)a, (IntPtr)b.Value));
}
/// <summary>
/// A very simple function used to perform the computation (a*0x10000)/b with maximal accuracy. Most of the
/// time, this is used to divide a given value by a 16.16 fixed float factor.
/// </summary>
/// <remarks>
/// The optimization for <see cref="DivFix"/> is simple: If (a &lt;&lt; 16) fits in 32 bits, then the division
/// is computed directly. Otherwise, we use a specialized version of <see cref="MulDiv"/>.
/// </remarks>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
/// <returns>The result of (a*0x10000)/b.</returns>
[Obsolete("Use Fixed16Dot16.DivideFix() instead.")]
public static Fixed16Dot16 DivFix(int a, Fixed16Dot16 b)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_DivFix((IntPtr)a, (IntPtr)b.Value));
}
/// <summary>
/// A very simple function used to round a 16.16 fixed number.
/// </summary>
/// <param name="a">The number to be rounded.</param>
/// <returns>The result of (a + 0x8000) &amp; -0x10000.</returns>
[Obsolete("Use Fixed16Dot16.RoundFix() instead.")]
public static Fixed16Dot16 RoundFix(Fixed16Dot16 a)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_RoundFix((IntPtr)a.Value));
}
/// <summary>
/// A very simple function used to compute the ceiling function of a 16.16 fixed number.
/// </summary>
/// <param name="a">The number for which the ceiling function is to be computed.</param>
/// <returns>The result of (a + 0x10000 - 1) &amp; -0x10000.</returns>
[Obsolete("Use Fixed16Dot16.CeilingFix() instead.")]
public static Fixed16Dot16 CeilFix(Fixed16Dot16 a)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_CeilFix((IntPtr)a.Value));
}
/// <summary>
/// A very simple function used to compute the floor function of a 16.16 fixed number.
/// </summary>
/// <param name="a">The number for which the floor function is to be computed.</param>
/// <returns>The result of a &amp; -0x10000.</returns>
[Obsolete("Use Fixed16Dot16.FloorFix() instead.")]
public static Fixed16Dot16 FloorFix(Fixed16Dot16 a)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_FloorFix((IntPtr)a.Value));
}
/// <summary>
/// Return the sinus of a given angle in fixed point format.
/// </summary>
/// <remarks>
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
/// </remarks>
/// <param name="angle">The input angle.</param>
/// <returns>The sinus value.</returns>
[Obsolete("Use Fixed16Dot16.Sin() instead.")]
public static Fixed16Dot16 Sin(Fixed16Dot16 angle)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)angle.Value));
}
/// <summary>
/// Return the cosinus of a given angle in fixed point format.
/// </summary>
/// <remarks>
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
/// </remarks>
/// <param name="angle">The input angle.</param>
/// <returns>The cosinus value.</returns>
[Obsolete("Use Fixed16Dot16.Cos() instead.")]
public static Fixed16Dot16 Cos(Fixed16Dot16 angle)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)angle.Value));
}
/// <summary>
/// Return the tangent of a given angle in fixed point format.
/// </summary>
/// <param name="angle">The input angle.</param>
/// <returns>The tangent value.</returns>
[Obsolete("Use Fixed16Dot16.Tan() instead.")]
public static Fixed16Dot16 Tan(Fixed16Dot16 angle)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)angle.Value));
}
/// <summary>
/// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane.
/// </summary>
/// <param name="x">The horizontal vector coordinate.</param>
/// <param name="y">The vertical vector coordinate.</param>
/// <returns>The arc-tangent value (i.e. angle).</returns>
[Obsolete("Use Fixed16Dot16.Atan2() instead.")]
public static Fixed16Dot16 Atan2(Fixed16Dot16 x, Fixed16Dot16 y)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Atan2((IntPtr)x.Value, (IntPtr)y.Value));
}
/// <summary>
/// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval.
/// </summary>
/// <param name="angle1">First angle.</param>
/// <param name="angle2">Second angle.</param>
/// <returns>Constrained value of value2-value1.</returns>
[Obsolete("Use Fixed16Dot16.AngleDiff() instead.")]
public static Fixed16Dot16 AngleDiff(Fixed16Dot16 angle1, Fixed16Dot16 angle2)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Angle_Diff((IntPtr)angle1.Value, (IntPtr)angle2.Value));
}
#endregion
#if !SHARPFONT_PLATFORM_IOS
#region Mac Specific Interface
/// <summary>
/// Return an FSSpec for the disk file containing the named font.
/// </summary>
/// <param name="fontName">Mac OS name of the font (e.g., Times New Roman Bold).</param>
/// <param name="faceIndex">Index of the face. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</param>
/// <returns>FSSpec to the file. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</returns>
public static IntPtr GetFileFromMacName(string fontName, out int faceIndex)
{
IntPtr fsspec;
Error err = FT_GetFile_From_Mac_Name(fontName, out fsspec, out faceIndex);
if (err != Error.Ok)
throw new FreeTypeException(err);
return fsspec;
}
/// <summary>
/// Return an FSSpec for the disk file containing the named font.
/// </summary>
/// <param name="fontName">Mac OS name of the font in ATS framework.</param>
/// <param name="faceIndex">Index of the face. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</param>
/// <returns>FSSpec to the file. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</returns>
public static IntPtr GetFileFromMacAtsName(string fontName, out int faceIndex)
{
IntPtr fsspec;
Error err = FT_GetFile_From_Mac_ATS_Name(fontName, out fsspec, out faceIndex);
if (err != Error.Ok)
throw new FreeTypeException(err);
return fsspec;
}
/// <summary>
/// Return a pathname of the disk file and face index for given font name which is handled by ATS framework.
/// </summary>
/// <param name="fontName">Mac OS name of the font in ATS framework.</param>
/// <param name="path">
/// Buffer to store pathname of the file. For passing to <see cref="Library.NewFace"/>. The client must
/// allocate this buffer before calling this function.
/// </param>
/// <returns>Index of the face. For passing to <see cref="Library.NewFace"/>.</returns>
public static unsafe int GetFilePathFromMacAtsName(string fontName, byte[] path)
{
int faceIndex;
fixed (void* ptr = path)
{
Error err = FT_GetFilePath_From_Mac_ATS_Name(fontName, (IntPtr)ptr, path.Length, out faceIndex);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
return faceIndex;
}
#endregion
#endif
}
}

View File

@@ -0,0 +1,546 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
#if !SHARPFONT_PORTABLE
using System.Drawing;
using System.Drawing.Imaging;
#endif
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A structure used to describe a bitmap or pixmap to the raster. Note that we now manage pixmaps of various
/// depths through the <see cref="PixelMode"/> field.
/// </summary>
/// <remarks>
/// For now, the only pixel modes supported by FreeType are mono and grays. However, drivers might be added in the
/// future to support more colorful options.
/// </remarks>
public sealed class FTBitmap : IDisposable
{
#region Fields
private IntPtr reference;
private BitmapRec rec;
private Library library;
private bool disposed;
//If the bitmap was generated with FT_Bitmap_New.
private bool user;
//HACK these variables exist to reduce the cost of reflection at runtime.
//Meant to be a temporary fix to https://github.com/Robmaister/SharpFont/issues/62
//until libgdiplus gets patched.
#if !SHARPFONT_PORTABLE
private bool hasCheckedForMono;
private bool isRunningOnMono;
private System.Reflection.FieldInfo monoPaletteFlagsField;
#endif
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FTBitmap"/> class.
/// </summary>
/// <param name="library">The parent <see cref="Library"/>.</param>
public FTBitmap(Library library)
{
IntPtr bitmapRef = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BitmapRec)));
FT.FT_Bitmap_New(bitmapRef);
Reference = bitmapRef;
this.library = library;
this.user = true;
}
internal FTBitmap(IntPtr reference, Library library)
{
Reference = reference;
this.library = library;
}
internal FTBitmap(IntPtr reference, BitmapRec bmpInt, Library library)
{
this.reference = reference;
this.rec = bmpInt;
this.library = library;
}
/// <summary>
/// Finalizes an instance of the <see cref="FTBitmap"/> class.
/// </summary>
~FTBitmap()
{
Dispose(false);
}
#endregion
#region Properties
/// <summary>
/// Gets a value indicating whether the <see cref="FTBitmap"/> has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return disposed;
}
}
/// <summary>
/// Gets the number of bitmap rows.
/// </summary>
public int Rows
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.rows;
}
}
/// <summary>
/// Gets the number of pixels in bitmap row.
/// </summary>
public int Width
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.width;
}
}
/// <summary><para>
/// Gets the pitch's absolute value is the number of bytes taken by one bitmap row, including padding. However,
/// the pitch is positive when the bitmap has a down flow, and negative when it has an up flow. In all
/// cases, the pitch is an offset to add to a bitmap pointer in order to go down one row.
/// </para><para>
/// Note that padding means the alignment of a bitmap to a byte border, and FreeType functions normally align
/// to the smallest possible integer value.
/// </para><para>
/// For the B/W rasterizer, pitch is always an even number.
/// </para><para>
/// To change the pitch of a bitmap (say, to make it a multiple of 4), use <see cref="FTBitmap.Convert"/>.
/// Alternatively, you might use callback functions to directly render to the application's surface; see the
/// file example2.cpp in the tutorial for a demonstration.
/// </para></summary>
public int Pitch
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.pitch;
}
}
/// <summary>
/// Gets a typeless pointer to the bitmap buffer. This value should be aligned on 32-bit boundaries in most
/// cases.
/// </summary>
public IntPtr Buffer
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.buffer;
}
}
/// <summary>
/// Gets the number of gray levels used in the bitmap. This field is only used with
/// <see cref="SharpFont.PixelMode.Gray"/>.
/// </summary>
public short GrayLevels
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.num_grays;
}
}
/// <summary>
/// Gets the pixel mode, i.e., how pixel bits are stored.
/// </summary>
public PixelMode PixelMode
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.pixel_mode;
}
}
/// <summary>
/// Gets how the palette is stored. This field is intended for paletted pixel modes.
/// </summary>
[Obsolete("Not used currently.")]
public byte PaletteMode
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.palette_mode;
}
}
/// <summary>
/// Gets a typeless pointer to the bitmap palette; this field is intended for paletted pixel modes.
/// </summary>
[Obsolete("Not used currently.")]
public IntPtr Palette
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return rec.palette;
}
}
/// <summary>
/// Gets the <see cref="FTBitmap"/>'s buffer as a byte array.
/// </summary>
public byte[] BufferData
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
//TODO deal with negative pitch
byte[] data = new byte[rec.rows * rec.pitch];
Marshal.Copy(rec.buffer, data, 0, data.Length);
return data;
}
}
internal IntPtr Reference
{
get
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
return reference;
}
set
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
reference = value;
rec = PInvokeHelper.PtrToStructure<BitmapRec>(reference);
}
}
#endregion
#region Methods
/// <summary>
/// Copy a bitmap into another one.
/// </summary>
/// <param name="library">A handle to a library object.</param>
/// <returns>A handle to the target bitmap.</returns>
public FTBitmap Copy(Library library)
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
if (library == null)
throw new ArgumentNullException("library");
FTBitmap newBitmap = new FTBitmap(library);
IntPtr bmpRef = newBitmap.reference;
Error err = FT.FT_Bitmap_Copy(library.Reference, Reference, bmpRef);
newBitmap.Reference = bmpRef;
if (err != Error.Ok)
throw new FreeTypeException(err);
return newBitmap;
}
/// <summary>
/// Embolden a bitmap. The new bitmap will be about xStrength pixels wider and yStrength pixels higher. The
/// left and bottom borders are kept unchanged.
/// </summary>
/// <remarks><para>
/// The current implementation restricts xStrength to be less than or equal to 8 if bitmap is of pixel_mode
/// <see cref="SharpFont.PixelMode.Mono"/>.
/// </para><para>
/// If you want to embolden the bitmap owned by a <see cref="GlyphSlot"/>, you should call
/// <see cref="GlyphSlot.OwnBitmap"/> on the slot first.
/// </para></remarks>
/// <param name="library">A handle to a library object.</param>
/// <param name="xStrength">
/// How strong the glyph is emboldened horizontally. Expressed in 26.6 pixel format.
/// </param>
/// <param name="yStrength">
/// How strong the glyph is emboldened vertically. Expressed in 26.6 pixel format.
/// </param>
public void Embolden(Library library, Fixed26Dot6 xStrength, Fixed26Dot6 yStrength)
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
if (library == null)
throw new ArgumentNullException("library");
Error err = FT.FT_Bitmap_Embolden(library.Reference, Reference, (IntPtr)xStrength.Value, (IntPtr)yStrength.Value);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary>
/// Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, or 8bpp to a bitmap object with depth 8bpp, making the
/// number of used bytes per line (a.k.a. the pitch) a multiple of alignment.
/// </summary>
/// <remarks><para>
/// It is possible to call <see cref="Convert"/> multiple times without calling
/// <see cref="Dispose()"/> (the memory is simply reallocated).
/// </para><para>
/// Use <see cref="Dispose()"/> to finally remove the bitmap object.
/// </para><para>
/// The library argument is taken to have access to FreeType's memory handling functions.
/// </para></remarks>
/// <param name="library">A handle to a library object.</param>
/// <param name="alignment">
/// The pitch of the bitmap is a multiple of this parameter. Common values are 1, 2, or 4.
/// </param>
/// <returns>The target bitmap.</returns>
public FTBitmap Convert(Library library, int alignment)
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
if (library == null)
throw new ArgumentNullException("library");
FTBitmap newBitmap = new FTBitmap(library);
IntPtr bmpRef = newBitmap.reference;
Error err = FT.FT_Bitmap_Convert(library.Reference, Reference, bmpRef, alignment);
newBitmap.Reference = bmpRef;
if (err != Error.Ok)
throw new FreeTypeException(err);
return newBitmap;
}
#if !SHARPFONT_PORTABLE
/// <summary>
/// Copies the contents of the <see cref="FTBitmap"/> to a GDI+ <see cref="Bitmap"/>.
/// </summary>
/// <returns>A GDI+ <see cref="Bitmap"/> containing this bitmap's data.</returns>
public Bitmap ToGdipBitmap()
{
return ToGdipBitmap(Color.Black);
}
/// <summary>
/// Copies the contents of the <see cref="FTBitmap"/> to a GDI+ <see cref="Bitmap"/>.
/// </summary>
/// <param name="color">The color of the text.</param>
/// <returns>A GDI+ <see cref="Bitmap"/> containing this bitmap's data with a transparent background.</returns>
public Bitmap ToGdipBitmap(Color color)
{
if (disposed)
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
if (rec.width == 0 || rec.rows == 0)
throw new InvalidOperationException("Invalid image size - one or both dimensions are 0.");
//TODO deal with negative pitch
switch (rec.pixel_mode)
{
case PixelMode.Mono:
{
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format1bppIndexed);
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
for (int i = 0; i < rec.rows; i++)
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
bmp.UnlockBits(locked);
ColorPalette palette = bmp.Palette;
palette.Entries[0] = Color.FromArgb(0, color);
palette.Entries[1] = Color.FromArgb(255, color);
bmp.Palette = palette;
return bmp;
}
case PixelMode.Gray4:
{
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format4bppIndexed);
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format4bppIndexed);
for (int i = 0; i < rec.rows; i++)
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
bmp.UnlockBits(locked);
ColorPalette palette = bmp.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
float a = (i * 17) / 255f;
palette.Entries[i] = Color.FromArgb(i * 17, (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
}
bmp.Palette = palette;
return bmp;
}
case PixelMode.Gray:
{
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format8bppIndexed);
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
for (int i = 0; i < rec.rows; i++)
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
bmp.UnlockBits(locked);
ColorPalette palette = bmp.Palette;
for (int i = 0; i < palette.Entries.Length; i++)
{
float a = i / 255f;
palette.Entries[i] = Color.FromArgb(i, (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
}
//HACK There's a bug in Mono's libgdiplus requiring the "PaletteHasAlpha" flag to be set for transparency to work properly
//See https://github.com/Robmaister/SharpFont/issues/62
if (!hasCheckedForMono)
{
hasCheckedForMono = true;
isRunningOnMono = Type.GetType("Mono.Runtime") != null;
if (isRunningOnMono)
{
monoPaletteFlagsField = typeof(ColorPalette).GetField("flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
}
}
if (isRunningOnMono)
monoPaletteFlagsField.SetValue(palette, palette.Flags | 1);
bmp.Palette = palette;
return bmp;
}
case PixelMode.Lcd:
{
//TODO apply color
int bmpWidth = rec.width / 3;
Bitmap bmp = new Bitmap(bmpWidth, rec.rows, PixelFormat.Format24bppRgb);
var locked = bmp.LockBits(new Rectangle(0, 0, bmpWidth, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
for (int i = 0; i < rec.rows; i++)
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
bmp.UnlockBits(locked);
return bmp;
}
/*case PixelMode.VerticalLcd:
{
int bmpHeight = rec.rows / 3;
Bitmap bmp = new Bitmap(rec.width, bmpHeight, PixelFormat.Format24bppRgb);
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, bmpHeight), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
for (int i = 0; i < bmpHeight; i++)
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, rec.width);
bmp.UnlockBits(locked);
return bmp;
}*/
default:
throw new InvalidOperationException("System.Drawing.Bitmap does not support this pixel mode.");
}
}
#endif
#region IDisposable
/// <summary>
/// Disposes an instance of the <see cref="FTBitmap"/> class.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposed)
{
disposed = true;
if (user)
{
FT.FT_Bitmap_Done(library.Reference, reference);
Marshal.FreeHGlobal(reference);
}
reference = IntPtr.Zero;
library = null;
}
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,195 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// An <see cref="FTList"/> iterator function which is called during a list parse by <see cref="FTList.Iterate"/>.
/// </summary>
/// <param name="node">The current iteration list node.</param>
/// <param name="user">
/// A typeless pointer passed to <see cref="ListIterator"/>. Can be used to point to the iteration's state.
/// </param>
/// <returns>Error code.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate Error ListIterator(NativeReference<ListNode> node, IntPtr user);
/// <summary>
/// An <see cref="FTList"/> iterator function which is called during a list finalization by
/// <see cref="FTList.Finalize"/> to destroy all elements in a given list.
/// </summary>
/// <param name="memory">The current system object.</param>
/// <param name="data">The current object to destroy.</param>
/// <param name="user">
/// A typeless pointer passed to <see cref="FTList.Iterate"/>. It can be used to point to the iteration's state.
/// </param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ListDestructor(NativeReference<Memory> memory, IntPtr data, IntPtr user);
/// <summary>
/// A structure used to hold a simple doubly-linked list. These are used in many parts of FreeType.
/// </summary>
public sealed class FTList
{
#region Fields
private IntPtr reference;
private ListRec rec;
#endregion
#region Constructors
internal FTList(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the head (first element) of doubly-linked list.
/// </summary>
public ListNode Head
{
get
{
return new ListNode(rec.head);
}
}
/// <summary>
/// Gets the tail (last element) of doubly-linked list.
/// </summary>
public ListNode Tail
{
get
{
return new ListNode(rec.tail);
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<ListRec>(reference);
}
}
#endregion
#region Methods
/// <summary>
/// Find the list node for a given listed object.
/// </summary>
/// <param name="data">The address of the listed object.</param>
/// <returns>List node. NULL if it wasn't found.</returns>
public ListNode Find(IntPtr data)
{
return new ListNode(FT.FT_List_Find(Reference, data));
}
/// <summary>
/// Append an element to the end of a list.
/// </summary>
/// <param name="node">The node to append.</param>
public void Add(ListNode node)
{
FT.FT_List_Add(Reference, node.Reference);
}
/// <summary>
/// Insert an element at the head of a list.
/// </summary>
/// <param name="node">The node to insert.</param>
public void Insert(ListNode node)
{
FT.FT_List_Insert(Reference, node.Reference);
}
/// <summary>
/// Remove a node from a list. This function doesn't check whether the node is in the list!
/// </summary>
/// <param name="node">The node to remove.</param>
public void Remove(ListNode node)
{
FT.FT_List_Remove(Reference, node.Reference);
}
/// <summary>
/// Move a node to the head/top of a list. Used to maintain LRU lists.
/// </summary>
/// <param name="node">The node to move.</param>
public void Up(ListNode node)
{
FT.FT_List_Up(Reference, node.Reference);
}
/// <summary>
/// Parse a list and calls a given iterator function on each element. Note that parsing is stopped as soon as
/// one of the iterator calls returns a non-zero value.
/// </summary>
/// <param name="iterator">An iterator function, called on each node of the list.</param>
/// <param name="user">A user-supplied field which is passed as the second argument to the iterator.</param>
public void Iterate(ListIterator iterator, IntPtr user)
{
Error err = FT.FT_List_Iterate(Reference, iterator, user);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary>
/// Destroy all elements in the list as well as the list itself.
/// </summary>
/// <remarks>
/// This function expects that all nodes added by <see cref="Add"/> or <see cref="Insert"/> have been
/// dynamically allocated.
/// </remarks>
/// <param name="destroy">A list destructor that will be applied to each element of the list.</param>
/// <param name="memory">The current memory object which handles deallocation.</param>
/// <param name="user">A user-supplied field which is passed as the last argument to the destructor.</param>
public void Finalize(ListDestructor destroy, Memory memory, IntPtr user)
{
FT.FT_List_Finalize(Reference, destroy, memory.Reference, user);
}
#endregion
}
}

View File

@@ -0,0 +1,250 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A simple structure used to store a 2x2 matrix. Coefficients are in 16.16 fixed float format. The computation
/// performed is:
/// <code>
/// x' = x*xx + y*xy
/// y' = x*yx + y*yy
/// </code>
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FTMatrix : IEquatable<FTMatrix>
{
#region Fields
private IntPtr xx, xy;
private IntPtr yx, yy;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FTMatrix"/> struct.
/// </summary>
/// <param name="xx">Matrix coefficient XX.</param>
/// <param name="xy">Matrix coefficient XY.</param>
/// <param name="yx">Matrix coefficient YX.</param>
/// <param name="yy">Matrix coefficient YY.</param>
public FTMatrix(int xx, int xy, int yx, int yy)
: this()
{
this.xx = (IntPtr)xx;
this.xy = (IntPtr)xy;
this.yx = (IntPtr)yx;
this.yy = (IntPtr)yy;
}
/// <summary>
/// Initializes a new instance of the <see cref="FTMatrix"/> struct.
/// </summary>
/// <param name="row0">Matrix coefficients XX, XY.</param>
/// <param name="row1">Matrix coefficients YX, YY.</param>
public FTMatrix(FTVector row0, FTVector row1)
: this(row0.X.Value, row0.Y.Value, row1.X.Value, row1.Y.Value)
{
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the matrix coefficient.
/// </summary>
public Fixed16Dot16 XX
{
get
{
return Fixed16Dot16.FromRawValue((int)xx);
}
set
{
xx = (IntPtr)value.Value;
}
}
/// <summary>
/// Gets or sets the matrix coefficient.
/// </summary>
public Fixed16Dot16 XY
{
get
{
return Fixed16Dot16.FromRawValue((int)xy);
}
set
{
xy = (IntPtr)value.Value;
}
}
/// <summary>
/// Gets or sets the matrix coefficient.
/// </summary>
public Fixed16Dot16 YX
{
get
{
return Fixed16Dot16.FromRawValue((int)yx);
}
set
{
yx = (IntPtr)value.Value;
}
}
/// <summary>
/// Gets or sets the matrix coefficient.
/// </summary>
public Fixed16Dot16 YY
{
get
{
return Fixed16Dot16.FromRawValue((int)yy);
}
set
{
yy = (IntPtr)value.Value;
}
}
#endregion
#region Operators
/// <summary>
/// Compares two instances of <see cref="FTMatrix"/> for equality.
/// </summary>
/// <param name="left">A <see cref="FTMatrix"/>.</param>
/// <param name="right">Another <see cref="FTMatrix"/>.</param>
/// <returns>A value indicating equality.</returns>
public static bool operator ==(FTMatrix left, FTMatrix right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="FTMatrix"/> for inequality.
/// </summary>
/// <param name="left">A <see cref="FTMatrix"/>.</param>
/// <param name="right">Another <see cref="FTMatrix"/>.</param>
/// <returns>A value indicating inequality.</returns>
public static bool operator !=(FTMatrix left, FTMatrix right)
{
return !left.Equals(right);
}
#endregion
#region Methods
/// <summary>
/// Perform the matrix operation b = a*b.
/// </summary>
/// <remarks>
/// The result is undefined if either a or b is zero.
/// </remarks>
/// <param name="a">A pointer to matrix a.</param>
/// <param name="b">A pointer to matrix b.</param>
public static void Multiply(FTMatrix a, FTMatrix b)
{
FT.FT_Matrix_Multiply(ref a, ref b);
}
/// <summary>
/// Perform the matrix operation b = a*b.
/// </summary>
/// <remarks>
/// The result is undefined if either a or b is zero.
/// </remarks>
/// <param name="b">A pointer to matrix b.</param>
public void Multiply(FTMatrix b)
{
FT.FT_Matrix_Multiply(ref this, ref b);
}
/// <summary>
/// Invert a 2x2 matrix. Return an error if it can't be inverted.
/// </summary>
public void Invert()
{
Error err = FT.FT_Matrix_Invert(ref this);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary>
/// Compares this instance of <see cref="FTMatrix"/> to another for equality.
/// </summary>
/// <param name="other">A <see cref="FTMatrix"/>.</param>
/// <returns>A value indicating equality.</returns>
public bool Equals(FTMatrix other)
{
return
xx == other.xx &&
xy == other.xy &&
yx == other.yx &&
yy == other.yy;
}
/// <summary>
/// Compares this instance of <see cref="FTMatrix"/> to an object for equality.
/// </summary>
/// <param name="obj">An object.</param>
/// <returns>A value indicating equality.</returns>
public override bool Equals(object obj)
{
if (obj is FTMatrix)
return this.Equals((FTMatrix)obj);
else
return false;
}
/// <summary>
/// Gets a unique hash code for this instance.
/// </summary>
/// <returns>A hash code.</returns>
public override int GetHashCode()
{
return xx.GetHashCode() ^ xy.GetHashCode() ^ yx.GetHashCode() ^ yy.GetHashCode();
}
#endregion
}
}

View File

@@ -0,0 +1,269 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// FreeType root size class structure. A size object models a face object at a given size.
/// </summary>
public sealed class FTSize : IDisposable
{
#region Fields
private bool userAlloc;
private bool disposed;
private bool duplicate;
private IntPtr reference;
private SizeRec rec;
private Face parentFace;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FTSize"/> class.
/// </summary>
/// <param name="parent">The parent face.</param>
public FTSize(Face parent)
{
IntPtr reference;
Error err = FT.FT_New_Size(parent.Reference, out reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
Reference = reference;
userAlloc = true;
}
internal FTSize(IntPtr reference, bool userAlloc, Face parentFace)
{
Reference = reference;
this.userAlloc = userAlloc;
if (parentFace != null)
{
this.parentFace = parentFace;
parentFace.AddChildSize(this);
}
else
{
duplicate = true;
}
}
/// <summary>
/// Finalizes an instance of the FTSize class.
/// </summary>
~FTSize()
{
Dispose(false);
}
#endregion
#region Events
/// <summary>
/// Occurs when the size is disposed.
/// </summary>
public event EventHandler Disposed;
#endregion
#region Properties
/// <summary>
/// Gets a value indicating whether the object has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return disposed;
}
}
/// <summary>
/// Gets a handle to the parent face object.
/// </summary>
public Face Face
{
get
{
if (disposed)
throw new ObjectDisposedException("Face", "Cannot access a disposed object.");
return parentFace;
}
}
/// <summary>
/// Gets or sets a typeless pointer, which is unused by the FreeType library or any of its drivers. It can be used by
/// client applications to link their own data to each size object.
/// </summary>
[Obsolete("Use the Tag property and Disposed event instead.")]
public Generic Generic
{
get
{
if (disposed)
throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
return new Generic(rec.generic);
}
set
{
if (disposed)
throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
value.WriteToUnmanagedMemory(PInvokeHelper.AbsoluteOffsetOf<SizeRec>(Reference, "generic"));
Reference = reference; //update rec.
}
}
/// <summary>
/// Gets metrics for this size object. This field is read-only.
/// </summary>
public SizeMetrics Metrics
{
get
{
if (disposed)
throw new ObjectDisposedException("Metrics", "Cannot access a disposed object.");
return new SizeMetrics(rec.metrics);
}
}
/// <summary>
/// Gets or sets an object used to identify this instance of <see cref="FTSize"/>. This object will not be
/// modified or accessed internally.
/// </summary>
/// <remarks>
/// This is a replacement for FT_Generic in FreeType. If you are retrieving the same object multiple times
/// from functions, this object will not appear in new copies.
/// </remarks>
public object Tag { get; set; }
internal IntPtr Reference
{
get
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
return reference;
}
set
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
reference = value;
this.rec = PInvokeHelper.PtrToStructure<SizeRec>(reference);
}
}
#endregion
#region Public Methods
/// <summary><para>
/// Even though it is possible to create several size objects for a given face (see
/// <see cref="SharpFont.Face.NewSize"/> for details), functions like <see cref="SharpFont.Face.LoadGlyph"/> or
/// <see cref="SharpFont.Face.LoadChar"/> only use the one which has been activated last to determine the
/// current character pixel size.
/// </para><para>
/// This function can be used to activate a previously created size object.
/// </para></summary>
/// <remarks>
/// If face is the size's parent face object, this function changes the value of face->size to the input
/// size handle.
/// </remarks>
public void Activate()
{
if (disposed)
throw new ObjectDisposedException("Activate", "Cannot access a disposed object.");
Error err = FT.FT_Activate_Size(Reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary>
/// Diposes the FTSize.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
#region Private Methods
private void Dispose(bool disposing)
{
if (!disposed)
{
disposed = true;
//only dispose the user allocated sizes that are not duplicates.
if (userAlloc && !duplicate)
{
FT.FT_Done_Size(reference);
}
// removes itself from the parent Face, with a check to prevent this from happening when Face is
// being disposed (Face disposes all it's children with a foreach loop, this causes an
// InvalidOperationException for modifying a collection during enumeration)
if (parentFace != null && !parentFace.IsDisposed)
parentFace.RemoveChildSize(this);
reference = IntPtr.Zero;
rec = new SizeRec();
EventHandler handler = Disposed;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
#endregion
}
}

View File

@@ -0,0 +1,315 @@
#region MIT License
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A function used to seek and read data from a given input stream.
/// </summary>
/// <remarks>
/// This function might be called to perform a seek or skip operation with a count of 0. A non-zero return value
/// then indicates an error.
/// </remarks>
/// <param name="stream">A handle to the source stream.</param>
/// <param name="offset">The offset of read in stream (always from start).</param>
/// <param name="buffer">The address of the read buffer.</param>
/// <param name="count">The number of bytes to read from the stream.</param>
/// <returns>The number of bytes effectively read by the stream.</returns>
[CLSCompliant(false)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint StreamIOFunc(NativeReference<FTStream> stream, uint offset, IntPtr buffer, uint count);
/// <summary>
/// A function used to close a given input stream.
/// </summary>
/// <param name="stream">A handle to the target stream.</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void StreamCloseFunc(NativeReference<FTStream> stream);
/// <summary>
/// A handle to an input stream.
/// </summary>
public sealed class FTStream : NativeObject
{
#region Fields
private StreamRec rec;
#endregion
#region Constructors
internal FTStream(IntPtr reference): base(reference)
{
}
#endregion
#region Properties
/// <summary>
/// Gets base. For memory-based streams, this is the address of the first stream byte in memory. This field
/// should always be set to NULL for disk-based streams.
/// </summary>
public IntPtr Base
{
get
{
return rec.@base;
}
}
/// <summary>
/// Gets the stream size in bytes.
/// </summary>
[CLSCompliant(false)]
public uint Size
{
get
{
return (uint)rec.size;
}
}
/// <summary>
/// Gets the current position within the stream.
/// </summary>
[CLSCompliant(false)]
public uint Position
{
get
{
return (uint)rec.pos;
}
}
/// <summary>
/// Gets the descriptor. This field is a union that can hold an integer or a pointer. It is used by stream
/// implementations to store file descriptors or FILE* pointers.
/// </summary>
public StreamDesc Descriptor
{
get
{
return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "descriptor"));
}
}
/// <summary>
/// Gets the path name. This field is completely ignored by FreeType. However, it is often useful during
/// debugging to use it to store the stream's filename (where available).
/// </summary>
public StreamDesc PathName
{
get
{
return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "pathname"));
}
}
/// <summary>
/// Gets the stream's input function.
/// </summary>
[CLSCompliant(false)]
public StreamIOFunc Read
{
get
{
return rec.read;
}
}
/// <summary>
/// Gets the stream's close function.
/// </summary>
public StreamCloseFunc Close
{
get
{
return rec.close;
}
}
/// <summary>
/// Gets the memory manager to use to preload frames. This is set internally by FreeType and shouldn't be
/// touched by stream implementations.
/// </summary>
public Memory Memory
{
get
{
return new Memory(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "memory"));
}
}
/// <summary>
/// Gets the cursor. This field is set and used internally by FreeType when parsing frames.
/// </summary>
public IntPtr Cursor
{
get
{
return rec.cursor;
}
}
/// <summary>
/// Gets the limit. This field is set and used internally by FreeType when parsing frames.
/// </summary>
public IntPtr Limit
{
get
{
return rec.limit;
}
}
internal override IntPtr Reference
{
get
{
return base.Reference;
}
set
{
base.Reference = value;
rec = PInvokeHelper.PtrToStructure<StreamRec>(value);
}
}
#endregion
#region Methods
#region GZIP Streams
/// <summary>
/// Open a new stream to parse gzip-compressed font files. This is mainly used to support the compressed
/// *.pcf.gz fonts that come with XFree86.
/// </summary>
/// <remarks><para>
/// The source stream must be opened before calling this function.
/// </para><para>
/// Calling the internal function FT_Stream_Close on the new stream will not call FT_Stream_Close on the
/// source stream. None of the stream objects will be released to the heap.
/// </para><para>
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
/// needed within the stream.
/// </para><para>
/// In certain builds of the library, gzip compression recognition is automatically handled when calling
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
/// capable of handling the raw compressed file, the library will try to open a gzipped stream from it and
/// re-open the face with it.
/// </para><para>
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
/// compiled with zlib support.
/// </para></remarks>
/// <param name="source">The source stream.</param>
public void OpenGzip(FTStream source)
{
Error err = FT.FT_Stream_OpenGzip(Reference, source.Reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#endregion
#region LZW Streams
/// <summary>
/// Open a new stream to parse LZW-compressed font files. This is mainly used to support the compressed
/// *.pcf.Z fonts that come with XFree86.
/// </summary>
/// <remarks><para>
/// The source stream must be opened before calling this function.
/// </para><para>
/// Calling the internal function FT_Stream_Close on the new stream will not call FT_Stream_Close on the
/// source stream. None of the stream objects will be released to the heap.
/// </para><para>
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
/// needed within the stream.
/// </para><para>
/// In certain builds of the library, LZW compression recognition is automatically handled when calling
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
/// capable of handling the raw compressed file, the library will try to open a LZW stream from it and re-open
/// the face with it.
/// </para><para>
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
/// compiled with LZW support.
/// </para></remarks>
/// <param name="source">The source stream.</param>
public void OpenLzw(FTStream source)
{
Error err = FT.FT_Stream_OpenLZW(Reference, source.Reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#endregion
#region BZIP2 Streams
/// <summary>
/// Open a new stream to parse bzip2-compressed font files. This is mainly used to support the compressed
/// *.pcf.bz2 fonts that come with XFree86.
/// </summary>
/// <remarks><para>
/// The source stream must be opened before calling this function.
/// </para><para>
/// Calling the internal function FT_Stream_Close on the new stream will not call FT_Stream_Close on the
/// source stream. None of the stream objects will be released to the heap.
/// </para><para>
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
/// needed within the stream.
/// </para><para>
/// In certain builds of the library, bzip2 compression recognition is automatically handled when calling
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
/// capable of handling the raw compressed file, the library will try to open a bzip2 stream from it and
/// re-open the face with it.
/// </para><para>
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
/// compiled with bzip2 support.
/// </para></remarks>
/// <param name="source">The source stream.</param>
public void StreamOpenBzip2(FTStream source)
{
Error err = FT.FT_Stream_OpenBzip2(Reference, source.Reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,46 @@
#region MIT License
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// A simple structure used to store a 2D vector unit vector. Uses <see cref="Fixed2Dot14"/> types.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FTUnitVector
{
/// <summary>
/// Horizontal coordinate.
/// </summary>
public Fixed2Dot14 X;
/// <summary>
/// Vertical coordinate.
/// </summary>
public Fixed2Dot14 Y;
}
}

View File

@@ -0,0 +1,240 @@
#region MIT License
/*Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A simple structure used to store a 2D vector.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FTVector : IEquatable<FTVector>
{
#region Fields
private IntPtr x;
private IntPtr y;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FTVector"/> struct.
/// </summary>
/// <param name="x">The horizontal coordinate.</param>
/// <param name="y">The vertical coordinate.</param>
public FTVector(Fixed16Dot16 x, Fixed16Dot16 y)
: this()
{
this.x = (IntPtr)x.Value;
this.y = (IntPtr)y.Value;
}
internal FTVector(IntPtr reference)
: this()
{
this.x = Marshal.ReadIntPtr(reference);
this.y = Marshal.ReadIntPtr(reference, IntPtr.Size);
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the horizontal coordinate.
/// </summary>
public Fixed16Dot16 X
{
get
{
return Fixed16Dot16.FromRawValue((int)x);
}
set
{
x = (IntPtr)value.Value;
}
}
/// <summary>
/// Gets or sets the vertical coordinate.
/// </summary>
public Fixed16Dot16 Y
{
get
{
return Fixed16Dot16.FromRawValue((int)y);
}
set
{
y = (IntPtr)value.Value;
}
}
#endregion
#region Operators
/// <summary>
/// Compares two instances of <see cref="FTVector"/> for equality.
/// </summary>
/// <param name="left">A <see cref="FTVector"/>.</param>
/// <param name="right">Another <see cref="FTVector"/>.</param>
/// <returns>A value indicating equality.</returns>
public static bool operator ==(FTVector left, FTVector right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="FTVector"/> for inequality.
/// </summary>
/// <param name="left">A <see cref="FTVector"/>.</param>
/// <param name="right">Another <see cref="FTVector"/>.</param>
/// <returns>A value indicating inequality.</returns>
public static bool operator !=(FTVector left, FTVector right)
{
return !left.Equals(right);
}
#endregion
#region Methods
/// <summary><para>
/// Return the unit vector corresponding to a given angle. After the call, the value of vec.x will be
/// sin(angle), and the value of vec.y will be cos(angle).
/// </para><para>
/// This function is useful to retrieve both the sinus and cosinus of a given angle quickly.
/// </para></summary>
/// <param name="angle">The address of angle.</param>
/// <returns>The address of target vector.</returns>
public static FTVector Unit(Fixed16Dot16 angle)
{
FTVector vec;
FT.FT_Vector_Unit(out vec, (IntPtr)angle.Value);
return vec;
}
/// <summary>
/// Compute vector coordinates from a length and angle.
/// </summary>
/// <param name="length">The vector length.</param>
/// <param name="angle">The vector angle.</param>
/// <returns>The address of source vector.</returns>
public static FTVector FromPolar(Fixed16Dot16 length, Fixed16Dot16 angle)
{
FTVector vec;
FT.FT_Vector_From_Polar(out vec, (IntPtr)length.Value, (IntPtr)angle.Value);
return vec;
}
/// <summary>
/// Transform a single vector through a 2x2 matrix.
/// </summary>
/// <remarks>
/// The result is undefined if either vector or matrix is invalid.
/// </remarks>
/// <param name="matrix">A pointer to the source 2x2 matrix.</param>
public void Transform(FTMatrix matrix)
{
FT.FT_Vector_Transform(ref this, ref matrix);
}
/// <summary>
/// Rotate a vector by a given angle.
/// </summary>
/// <param name="angle">The address of angle.</param>
public void Rotate(Fixed16Dot16 angle)
{
FT.FT_Vector_Rotate(ref this, (IntPtr)angle.Value);
}
/// <summary>
/// Return the length of a given vector.
/// </summary>
/// <returns>The vector length, expressed in the same units that the original vector coordinates.</returns>
public Fixed16Dot16 Length()
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Vector_Length(ref this));
}
/// <summary>
/// Compute both the length and angle of a given vector.
/// </summary>
/// <param name="length">The vector length.</param>
/// <param name="angle">The vector angle.</param>
public void Polarize(out Fixed16Dot16 length, out Fixed16Dot16 angle)
{
IntPtr tmpLength, tmpAngle;
FT.FT_Vector_Polarize(ref this, out tmpLength, out tmpAngle);
length = Fixed16Dot16.FromRawValue((int)tmpLength);
angle = Fixed16Dot16.FromRawValue((int)tmpAngle);
}
/// <summary>
/// Compares this instance of <see cref="FTVector"/> to another for equality.
/// </summary>
/// <param name="other">A <see cref="FTVector"/>.</param>
/// <returns>A value indicating equality.</returns>
public bool Equals(FTVector other)
{
return x == other.x && y == other.y;
}
/// <summary>
/// Compares this instance of <see cref="FTVector"/> to an object for equality.
/// </summary>
/// <param name="obj">An object.</param>
/// <returns>A value indicating equality.</returns>
public override bool Equals(object obj)
{
if (obj is FTVector)
return this.Equals((FTVector)obj);
else
return false;
}
/// <summary>
/// Gets a unique hash code for this instance.
/// </summary>
/// <returns>A hash code.</returns>
public override int GetHashCode()
{
return x.GetHashCode() ^ y.GetHashCode();
}
#endregion
}
}

View File

@@ -0,0 +1,164 @@
#region MIT License
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// A simple structure used to store a 2D vector.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FTVector26Dot6 : IEquatable<FTVector26Dot6>
{
#region Fields
private IntPtr x;
private IntPtr y;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="FTVector26Dot6"/> struct.
/// </summary>
/// <param name="x">The horizontal coordinate.</param>
/// <param name="y">The vertical coordinate.</param>
public FTVector26Dot6(Fixed26Dot6 x, Fixed26Dot6 y)
: this()
{
this.x = (IntPtr)x.Value;
this.y = (IntPtr)y.Value;
}
internal FTVector26Dot6(IntPtr reference)
: this()
{
this.x = Marshal.ReadIntPtr(reference);
this.y = Marshal.ReadIntPtr(reference, IntPtr.Size);
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the horizontal coordinate.
/// </summary>
public Fixed26Dot6 X
{
get
{
return Fixed26Dot6.FromRawValue((int)x);
}
set
{
x = (IntPtr)value.Value;
}
}
/// <summary>
/// Gets or sets the vertical coordinate.
/// </summary>
public Fixed26Dot6 Y
{
get
{
return Fixed26Dot6.FromRawValue((int)y);
}
set
{
y = (IntPtr)value.Value;
}
}
#endregion
#region Operators
/// <summary>
/// Compares two instances of <see cref="FTVector26Dot6"/> for equality.
/// </summary>
/// <param name="left">A <see cref="FTVector26Dot6"/>.</param>
/// <param name="right">Another <see cref="FTVector26Dot6"/>.</param>
/// <returns>A value indicating equality.</returns>
public static bool operator ==(FTVector26Dot6 left, FTVector26Dot6 right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="FTVector26Dot6"/> for inequality.
/// </summary>
/// <param name="left">A <see cref="FTVector26Dot6"/>.</param>
/// <param name="right">Another <see cref="FTVector26Dot6"/>.</param>
/// <returns>A value indicating inequality.</returns>
public static bool operator !=(FTVector26Dot6 left, FTVector26Dot6 right)
{
return !left.Equals(right);
}
#endregion
#region Methods
/// <summary>
/// Compares this instance of <see cref="FTVector26Dot6"/> to another for equality.
/// </summary>
/// <param name="other">A <see cref="FTVector26Dot6"/>.</param>
/// <returns>A value indicating equality.</returns>
public bool Equals(FTVector26Dot6 other)
{
return x == other.x && y == other.y;
}
/// <summary>
/// Compares this instance of <see cref="FTVector26Dot6"/> to an object for equality.
/// </summary>
/// <param name="obj">An object.</param>
/// <returns>A value indicating equality.</returns>
public override bool Equals(object obj)
{
if (obj is FTVector26Dot6)
return this.Equals((FTVector26Dot6)obj);
else
return false;
}
/// <summary>
/// Gets a unique hash code for this instance.
/// </summary>
/// <returns>A hash code.</returns>
public override int GetHashCode()
{
return x.GetHashCode() ^ y.GetHashCode();
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,145 @@
#region MIT License
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// A list of bit flags used in the face_flags field of the <see cref="Face"/> structure. They inform client
/// applications of properties of the corresponding face.
/// </summary>
[Flags]
public enum FaceFlags : long
{
/// <summary>
/// No style flags.
/// </summary>
None = 0x0000,
/// <summary>
/// Indicates that the face contains outline glyphs. This doesn't prevent bitmap strikes, i.e., a face can have
/// both this and and <see cref="FaceFlags.FixedSizes"/> set.
/// </summary>
Scalable = 0x0001,
/// <summary>
/// Indicates that the face contains bitmap strikes. See also <see cref="Face.FixedSizesCount"/> and
/// <see cref="Face.AvailableSizes"/>.
/// </summary>
FixedSizes = 0x0002,
/// <summary>
/// Indicates that the face contains fixed-width characters (like Courier, Lucido, MonoType, etc.).
/// </summary>
FixedWidth = 0x0004,
/// <summary>
/// Indicates that the face uses the sfnt storage scheme. For now, this means TrueType and OpenType.
/// </summary>
Sfnt = 0x0008,
/// <summary>
/// Indicates that the face contains horizontal glyph metrics. This should be set for all common formats.
/// </summary>
Horizontal = 0x0010,
/// <summary>
/// Indicates that the face contains vertical glyph metrics. This is only available in some formats, not all of
/// them.
/// </summary>
Vertical = 0x0020,
/// <summary>
/// Indicates that the face contains kerning information. If set, the kerning distance can be retrieved through
/// the function <see cref="Face.GetKerning"/>. Otherwise the function always return the vector (0,0). Note
/// that FreeType doesn't handle kerning data from the GPOS table (as present in some OpenType fonts).
/// </summary>
Kerning = 0x0040,
/// <summary>
/// THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT.
/// </summary>
[Obsolete("THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT.")]
FastGlyphs = 0x0080,
/// <summary>
/// Indicates that the font contains multiple masters and is capable of interpolating between them. See the
/// multiple-masters specific API for details.
/// </summary>
MultipleMasters = 0x0100,
/// <summary>
/// Indicates that the font contains glyph names that can be retrieved through
/// <see cref="Face.GetGlyphName(uint, int)"/>. Note that some TrueType fonts contain broken glyph name
/// tables. Use the function <see cref="Face.HasPSGlyphNames"/> when needed.
/// </summary>
GlyphNames = 0x0200,
/// <summary>
/// Used internally by FreeType to indicate that a face's stream was provided by the client application and
/// should not be destroyed when <see cref="Face.Dispose()"/> is called. Don't read or test this flag.
/// </summary>
ExternalStream = 0x0400,
/// <summary>
/// Set if the font driver has a hinting machine of its own. For example, with TrueType fonts, it makes sense
/// to use data from the SFNT gasp table only if the native TrueType hinting engine (with the bytecode
/// interpreter) is available and active.
/// </summary>
Hinter = 0x0800,
/// <summary><para>
/// Set if the font is CID-keyed. In that case, the font is not accessed by glyph indices but by CID values.
/// For subsetted CID-keyed fonts this has the consequence that not all index values are a valid argument to
/// <see cref="Face.LoadGlyph"/>. Only the CID values for which corresponding glyphs in the subsetted font
/// exist make <see cref="Face.LoadGlyph"/> return successfully; in all other cases you get an
/// <see cref="Error.InvalidArgument"/> error.
/// </para><para>
/// Note that CID-keyed fonts which are in an SFNT wrapper don't have this flag set since the glyphs are
/// accessed in the normal way (using contiguous indices); the CID-ness isn't visible to the application.
/// </para></summary>
CidKeyed = 0x1000,
/// <summary><para>
/// Set if the font is tricky, this is, it always needs the font format's native hinting engine to get a
/// reasonable result. A typical example is the Chinese font mingli.ttf which uses TrueType bytecode
/// instructions to move and scale all of its subglyphs.
/// </para><para>
/// It is not possible to autohint such fonts using <see cref="LoadFlags.ForceAutohint"/>; it will also ignore
/// <see cref="LoadFlags.NoHinting"/>. You have to set both <see cref="LoadFlags.NoHinting"/> and
/// <see cref="LoadFlags.ForceAutohint"/> to really disable hinting; however, you probably never want this
/// except for demonstration purposes.
/// </para><para>
/// Currently, there are about a dozen TrueType fonts in the list of tricky fonts; they are hard-coded in file
/// ttobjs.c.
/// </para></summary>
Tricky = 0x2000,
/// <summary>
/// Set if the font has color glyph tables. To access color glyphs use <see cref="LoadFlags.Color"/>.
/// </summary>
Color = 0x4000,
}
}

View File

@@ -0,0 +1,752 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// Represents a fixed-point decimal value with 16 bits of decimal precision.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Fixed16Dot16 : IEquatable<Fixed16Dot16>, IComparable<Fixed16Dot16>
{
#region Fields
/// <summary>
/// The angle pi expressed in FT_Angle units.
/// </summary>
public static readonly Fixed16Dot16 AnglePI = new Fixed16Dot16(180);
/// <summary>
/// The angle 2*pi expressed in FT_Angle units.
/// </summary>
public static readonly Fixed16Dot16 Angle2PI = new Fixed16Dot16(360);
/// <summary>
/// The angle pi/2 expressed in FT_Angle units.
/// </summary>
public static readonly Fixed16Dot16 AnglePI2 = new Fixed16Dot16(90);
/// <summary>
/// The angle pi/4 expressed in FT_Angle units.
/// </summary>
public static readonly Fixed16Dot16 AnglePI4 = new Fixed16Dot16(45);
/// <summary>
/// The raw 16.16 integer.
/// </summary>
private int value;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
/// </summary>
/// <param name="value">An integer value.</param>
public Fixed16Dot16(int value)
{
this.value = value << 16;
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed16Dot16(float value)
{
this.value = (int)(value * 65536);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed16Dot16(double value)
{
this.value = (int)(value * 65536);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed16Dot16(decimal value)
{
this.value = (int)(value * 65536);
}
#endregion
#region Properties
/// <summary>
/// Gets the raw 16.16 integer.
/// </summary>
public int Value
{
get
{
return value;
}
}
#endregion
#region Methods
#region Static
/// <summary>
/// Creates a <see cref="Fixed16Dot16"/> from an int containing a 16.16 value.
/// </summary>
/// <param name="value">A 16.16 value.</param>
/// <returns>An instance of <see cref="Fixed16Dot16"/>.</returns>
public static Fixed16Dot16 FromRawValue(int value)
{
Fixed16Dot16 f = new Fixed16Dot16();
f.value = value;
return f;
}
/// <summary>
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Int32"/>
/// </summary>
/// <param name="value">A <see cref="System.Int32"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static Fixed16Dot16 FromInt32(int value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Creates a new <see cref="Fixed16Dot16"/> from <see cref="System.Single"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 16.16 value.</returns>
public static Fixed16Dot16 FromSingle(float value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 16.16 value.</returns>
public static Fixed16Dot16 FromDouble(double value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 16.16 value.</returns>
public static Fixed16Dot16 FromDecimal(decimal value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Adds two 16.16 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed16Dot16 Add(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Fixed16Dot16.FromRawValue(left.value + right.value);
}
/// <summary>
/// Subtacts one 16.16 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed16Dot16 Subtract(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Fixed16Dot16.FromRawValue(left.value - right.value);
}
/// <summary>
/// Multiplies two 16.16 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed16Dot16 Multiply(Fixed16Dot16 left, Fixed16Dot16 right)
{
long mul = (long)left.value * (long)right.value;
Fixed16Dot16 ans = new Fixed16Dot16();
ans.value = (int)(mul >> 16);
return ans;
}
/// <summary>
/// A very simple function used to perform the computation (a*b)/0x10000 with maximal accuracy. Most of the
/// time this is used to multiply a given value by a 16.16 fixed float factor.
/// </summary>
/// <remarks><para>
/// NOTE: This is a native FreeType function.
/// </para><para>
/// This function has been optimized for the case where the absolute value of a is less than 2048, and b is
/// a 16.16 scaling factor. As this happens mainly when scaling from notional units to fractional pixels in
/// FreeType, it resulted in noticeable speed improvements between versions 2.x and 1.x.
/// </para><para>
/// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make
/// a great difference.
/// </para></remarks>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
/// <returns>The result of (a*b)/0x10000.</returns>
public static Fixed16Dot16 MultiplyFix(int a, Fixed16Dot16 b)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_MulFix((IntPtr)a, (IntPtr)b.Value));
}
/// <summary>
/// Divides one 16.16 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed16Dot16 Divide(Fixed16Dot16 left, Fixed16Dot16 right)
{
long div = ((long)left.Value << 16) / right.value;
Fixed16Dot16 ans = new Fixed16Dot16();
ans.value = (int)div;
return ans;
}
/// <summary>
/// A very simple function used to perform the computation (a*0x10000)/b with maximal accuracy. Most of the
/// time, this is used to divide a given value by a 16.16 fixed float factor.
/// </summary>
/// <remarks><para>
/// NOTE: This is a native FreeType function.
/// </para><para>
/// The optimization for <see cref="DivideFix"/> is simple: If (a &lt;&lt; 16) fits in 32 bits, then the division
/// is computed directly. Otherwise, we use a specialized version of <see cref="MultiplyDivide"/>.
/// </para></remarks>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
/// <returns>The result of (a*0x10000)/b.</returns>
public static Fixed16Dot16 DivideFix(int a, Fixed16Dot16 b)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_DivFix((IntPtr)a, (IntPtr)b.Value));
}
/// <summary><para>
/// A very simple function used to perform the computation (a*b)/c with maximal accuracy (it uses a 64-bit
/// intermediate integer whenever necessary).
/// </para><para>
/// This function isn't necessarily as fast as some processor specific operations, but is at least completely
/// portable.
/// </para></summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <param name="a">The first multiplier.</param>
/// <param name="b">The second multiplier.</param>
/// <param name="c">The divisor.</param>
/// <returns>
/// The result of (a*b)/c. This function never traps when trying to divide by zero; it simply returns
/// MaxInt or MinInt depending on the signs of a and b.
/// </returns>
public static Fixed16Dot16 MultiplyDivide(Fixed16Dot16 a, Fixed16Dot16 b, Fixed16Dot16 c)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_MulDiv((IntPtr)a.Value, (IntPtr)b.Value, (IntPtr)c.Value));
}
/// <summary>
/// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <param name="x">The horizontal vector coordinate.</param>
/// <param name="y">The vertical vector coordinate.</param>
/// <returns>The arc-tangent value (i.e. angle).</returns>
public static Fixed16Dot16 Atan2(Fixed16Dot16 x, Fixed16Dot16 y)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Atan2((IntPtr)x.Value, (IntPtr)y.Value));
}
/// <summary>
/// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <param name="angle1">First angle.</param>
/// <param name="angle2">Second angle.</param>
/// <returns>Constrained value of value2-value1.</returns>
public static Fixed16Dot16 AngleDiff(Fixed16Dot16 angle1, Fixed16Dot16 angle2)
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Angle_Diff((IntPtr)angle1.Value, (IntPtr)angle2.Value));
}
#endregion
#region Operators
/// <summary>
/// Casts a <see cref="System.Int16"/> to a <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="value">A <see cref="System.Int16"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static implicit operator Fixed16Dot16(short value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Casts a <see cref="System.Int32"/> to a <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="value">A <see cref="System.Int32"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static explicit operator Fixed16Dot16(int value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="value">A <see cref="System.Single"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static explicit operator Fixed16Dot16(float value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="value">A <see cref="System.Double"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static explicit operator Fixed16Dot16(double value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
public static explicit operator Fixed16Dot16(decimal value)
{
return new Fixed16Dot16(value);
}
/// <summary>
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Int32"/>.
/// </summary>
/// <remarks>
/// This operation can result in a loss of data.
/// </remarks>
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
/// <returns>The equivalent <see cref="System.Int32"/> value.</returns>
public static explicit operator int(Fixed16Dot16 value)
{
return value.ToInt32();
}
/// <summary>
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Single"/>.
/// </summary>
/// <remarks>
/// This operation can result in a loss of data.
/// </remarks>
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static explicit operator float(Fixed16Dot16 value)
{
return value.ToSingle();
}
/// <summary>
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
public static implicit operator double(Fixed16Dot16 value)
{
return value.ToDouble();
}
/// <summary>
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static implicit operator decimal(Fixed16Dot16 value)
{
return value.ToDecimal();
}
/// <summary>
/// Adds two 16.16 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed16Dot16 operator +(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Add(left, right);
}
/// <summary>
/// Subtacts one 16.16 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed16Dot16 operator -(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Subtract(left, right);
}
/// <summary>
/// Multiplies two 16.16 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed16Dot16 operator *(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Multiply(left, right);
}
/// <summary>
/// Divides one 16.16 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed16Dot16 operator /(Fixed16Dot16 left, Fixed16Dot16 right)
{
return Divide(left, right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed16Dot16"/> for equality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public static bool operator ==(Fixed16Dot16 left, Fixed16Dot16 right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed16Dot16"/> for inequality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are not equal.</returns>
public static bool operator !=(Fixed16Dot16 left, Fixed16Dot16 right)
{
return !(left == right);
}
/// <summary>
/// Checks if the left operand is less than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than right.</returns>
public static bool operator <(Fixed16Dot16 left, Fixed16Dot16 right)
{
return left.CompareTo(right) < 0;
}
/// <summary>
/// Checks if the left operand is less than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than or equal to right.</returns>
public static bool operator <=(Fixed16Dot16 left, Fixed16Dot16 right)
{
return left.CompareTo(right) <= 0;
}
/// <summary>
/// Checks if the left operand is greater than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than right.</returns>
public static bool operator >(Fixed16Dot16 left, Fixed16Dot16 right)
{
return left.CompareTo(right) > 0;
}
/// <summary>
/// Checks if the left operand is greater than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
public static bool operator >=(Fixed16Dot16 left, Fixed16Dot16 right)
{
return left.CompareTo(right) >= 0;
}
#endregion
#region Instance
/// <summary>
/// Removes the decimal part of the value.
/// </summary>
/// <returns>The truncated number.</returns>
public int Floor()
{
return value >> 16;
}
/// <summary>
/// A very simple function used to compute the floor function of a 16.16 fixed number.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <returns>The result of a &amp; -0x10000.</returns>
public Fixed16Dot16 FloorFix()
{
//TODO does the P/Invoke overhead make this slower than re-implementing in C#? Test it
return FromRawValue((int)FT.FT_FloorFix((IntPtr)this.Value));
}
/// <summary>
/// Rounds to the nearest whole number.
/// </summary>
/// <returns>The nearest whole number.</returns>
public int Round()
{
//add 2^15, rounds the integer part up if the decimal value is >= 0.5
return (value + 32768) >> 16;
}
/// <summary>
/// A very simple function used to round a 16.16 fixed number.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <returns>The result of (a + 0x8000) &amp; -0x10000.</returns>
public Fixed16Dot16 RoundFix()
{
return FromRawValue((int)FT.FT_RoundFix((IntPtr)this.Value));
}
/// <summary>
/// Rounds up to the next whole number.
/// </summary>
/// <returns>The next whole number.</returns>
public int Ceiling()
{
//add 2^16 - 1, rounds the integer part up if there's any decimal value
return (value + 65535) >> 16;
}
/// <summary>
/// A very simple function used to compute the ceiling function of a 16.16 fixed number.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <returns>The result of (a + 0x10000 - 1) &amp; -0x10000.</returns>
public Fixed16Dot16 CeilingFix()
{
return FromRawValue((int)FT.FT_CeilFix((IntPtr)this.Value));
}
/// <summary>
/// Return the sinus of a given angle in fixed point format.
/// </summary>
/// <remarks><para>
/// NOTE: This is a native FreeType function.
/// </para><para>
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
/// </para></remarks>
/// <returns>The sinus value.</returns>
public Fixed16Dot16 Sin()
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)this.Value));
}
/// <summary>
/// Return the cosinus of a given angle in fixed point format.
/// </summary>
/// <remarks><para>
/// NOTE: This is a native FreeType function.
/// </para><para>
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
/// </para></remarks>
/// <returns>The cosinus value.</returns>
public Fixed16Dot16 Cos()
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)this.Value));
}
/// <summary>
/// Return the tangent of a given angle in fixed point format.
/// </summary>
/// <remarks>This is a native FreeType function.</remarks>
/// <returns>The tangent value.</returns>
public Fixed16Dot16 Tan()
{
return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)this.Value));
}
/// <summary>
/// Converts the value to a <see cref="System.Int32"/>. The value is floored.
/// </summary>
/// <returns>An integer value.</returns>
public int ToInt32()
{
return Floor();
}
/// <summary>
/// Converts the value to a <see cref="System.Single"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public float ToSingle()
{
return value / 65536f;
}
/// <summary>
/// Converts the value to a <see cref="System.Double"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public double ToDouble()
{
return value / 65536d;
}
/// <summary>
/// Converts the value to a <see cref="System.Decimal"/>.
/// </summary>
/// <returns>A decimal value.</returns>
public decimal ToDecimal()
{
return value / 65536m;
}
/// <summary>
/// Compares this instance to another <see cref="Fixed16Dot16"/> for equality.
/// </summary>
/// <param name="other">A <see cref="Fixed16Dot16"/>.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public bool Equals(Fixed16Dot16 other)
{
return value == other.value;
}
/// <summary>
/// Compares this instnace with another <see cref="Fixed16Dot16"/> and returns an integer that indicates
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
/// other <see cref="Fixed16Dot16"/>.
/// </summary>
/// <param name="other">A <see cref="Fixed16Dot16"/>.</param>
/// <returns>A value indicating the relative order of the instances.</returns>
public int CompareTo(Fixed16Dot16 other)
{
return value.CompareTo(other.value);
}
#endregion
#region Overrides
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(IFormatProvider provider)
{
return ToDecimal().ToString(provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format)
{
return ToDecimal().ToString(format);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format, IFormatProvider provider)
{
return ToDecimal().ToString(format, provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return ToDecimal().ToString();
}
/// <summary>
/// Calculates a hash code for the current object.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode()
{
return value.GetHashCode();
}
/// <summary>
/// Determines whether the specified object isequal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>A value indicating equality between the two objects.</returns>
public override bool Equals(object obj)
{
if (obj is Fixed16Dot16)
return this.Equals((Fixed16Dot16)obj);
else if (obj is int)
return value == ((Fixed16Dot16)obj).value;
else
return false;
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,579 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// Represents a fixed-point decimal value with 6 bits of decimal precision.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Fixed26Dot6 : IEquatable<Fixed26Dot6>, IComparable<Fixed26Dot6>
{
#region Fields
/// <summary>
/// The raw 26.6 integer.
/// </summary>
private int value;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
/// </summary>
/// <param name="value">An integer value.</param>
public Fixed26Dot6(int value)
{
this.value = value << 6;
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed26Dot6(float value)
{
this.value = (int)(value * 64);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed26Dot6(double value)
{
this.value = (int)(value * 64);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed26Dot6(decimal value)
{
this.value = (int)(value * 64);
}
#endregion
#region Properties
/// <summary>
/// Gets the raw 26.6 integer.
/// </summary>
public int Value
{
get
{
return value;
}
}
#endregion
#region Methods
#region Static
/// <summary>
/// Creates a <see cref="Fixed26Dot6"/> from an int containing a 26.6 value.
/// </summary>
/// <param name="value">A 26.6 value.</param>
/// <returns>An instance of <see cref="Fixed26Dot6"/>.</returns>
public static Fixed26Dot6 FromRawValue(int value)
{
Fixed26Dot6 f = new Fixed26Dot6();
f.value = value;
return f;
}
/// <summary>
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Int32"/>
/// </summary>
/// <param name="value">A <see cref="System.Int32"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static Fixed26Dot6 FromInt32(int value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Creates a new <see cref="Fixed26Dot6"/> from <see cref="System.Single"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 26.6 value.</returns>
public static Fixed26Dot6 FromSingle(float value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 26.6 value.</returns>
public static Fixed26Dot6 FromDouble(double value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 26.6 value.</returns>
public static Fixed26Dot6 FromDecimal(decimal value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Adds two 26.6 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed26Dot6 Add(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Fixed26Dot6.FromRawValue(left.value + right.value);
}
/// <summary>
/// Subtacts one 26.6 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed26Dot6 Subtract(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Fixed26Dot6.FromRawValue(left.value - right.value);
}
/// <summary>
/// Multiplies two 26.6 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed26Dot6 Multiply(Fixed26Dot6 left, Fixed26Dot6 right)
{
long mul = (long)left.value * (long)right.value;
Fixed26Dot6 ans = new Fixed26Dot6();
ans.value = (int)(mul >> 6);
return ans;
}
/// <summary>
/// Divides one 26.6 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed26Dot6 Divide(Fixed26Dot6 left, Fixed26Dot6 right)
{
long div = ((long)left.Value << 6) / right.value;
Fixed26Dot6 ans = new Fixed26Dot6();
ans.value = (int)div;
return ans;
}
#endregion
#region Operators
/// <summary>
/// Casts a <see cref="System.Int16"/> to a <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="value">A <see cref="System.Int16"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static implicit operator Fixed26Dot6(short value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Casts a <see cref="System.Int32"/> to a <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="value">A <see cref="System.Int32"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static implicit operator Fixed26Dot6(int value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="value">A <see cref="System.Single"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static implicit operator Fixed26Dot6(float value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="value">A <see cref="System.Double"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static implicit operator Fixed26Dot6(double value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
public static implicit operator Fixed26Dot6(decimal value)
{
return new Fixed26Dot6(value);
}
/// <summary>
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Int32"/>.
/// </summary>
/// <remarks>
/// This operation can result in a loss of data.
/// </remarks>
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
/// <returns>The equivalent <see cref="System.Int32"/> value.</returns>
public static explicit operator int(Fixed26Dot6 value)
{
return value.ToInt32();
}
/// <summary>
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Single"/>.
/// </summary>
/// <remarks>
/// This operation can result in a loss of data.
/// </remarks>
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static explicit operator float(Fixed26Dot6 value)
{
return value.ToSingle();
}
/// <summary>
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
public static implicit operator double(Fixed26Dot6 value)
{
return value.ToDouble();
}
/// <summary>
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static implicit operator decimal(Fixed26Dot6 value)
{
return value.ToDecimal();
}
/// <summary>
/// Adds two 26.6 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed26Dot6 operator +(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Add(left, right);
}
/// <summary>
/// Subtacts one 26.6 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed26Dot6 operator -(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Subtract(left, right);
}
/// <summary>
/// Multiplies two 26.6 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed26Dot6 operator *(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Multiply(left, right);
}
/// <summary>
/// Divides one 26.6 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed26Dot6 operator /(Fixed26Dot6 left, Fixed26Dot6 right)
{
return Divide(left, right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed26Dot6"/> for equality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public static bool operator ==(Fixed26Dot6 left, Fixed26Dot6 right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed26Dot6"/> for inequality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are not equal.</returns>
public static bool operator !=(Fixed26Dot6 left, Fixed26Dot6 right)
{
return !(left == right);
}
/// <summary>
/// Checks if the left operand is less than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than right.</returns>
public static bool operator <(Fixed26Dot6 left, Fixed26Dot6 right)
{
return left.CompareTo(right) < 0;
}
/// <summary>
/// Checks if the left operand is less than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than or equal to right.</returns>
public static bool operator <=(Fixed26Dot6 left, Fixed26Dot6 right)
{
return left.CompareTo(right) <= 0;
}
/// <summary>
/// Checks if the left operand is greater than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than right.</returns>
public static bool operator >(Fixed26Dot6 left, Fixed26Dot6 right)
{
return left.CompareTo(right) > 0;
}
/// <summary>
/// Checks if the left operand is greater than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
public static bool operator >=(Fixed26Dot6 left, Fixed26Dot6 right)
{
return left.CompareTo(right) >= 0;
}
#endregion
#region Instance
/// <summary>
/// Removes the decimal part of the value.
/// </summary>
/// <returns>The truncated number.</returns>
public int Floor()
{
return value >> 6;
}
/// <summary>
/// Rounds to the nearest whole number.
/// </summary>
/// <returns>The nearest whole number.</returns>
public int Round()
{
//add 2^5, rounds the integer part up if the decimal value is >= 0.5
return (value + 32) >> 6;
}
/// <summary>
/// Rounds up to the next whole number.
/// </summary>
/// <returns>The next whole number.</returns>
public int Ceiling()
{
//add 2^6 - 1, rounds the integer part up if there's any decimal value
return (value + 63) >> 6;
}
/// <summary>
/// Converts the value to a <see cref="System.Int32"/>. The value is floored.
/// </summary>
/// <returns>An integer value.</returns>
public int ToInt32()
{
return Floor();
}
/// <summary>
/// Converts the value to a <see cref="System.Single"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public float ToSingle()
{
return value / 64f;
}
/// <summary>
/// Converts the value to a <see cref="System.Double"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public double ToDouble()
{
return value / 64d;
}
/// <summary>
/// Converts the value to a <see cref="System.Decimal"/>.
/// </summary>
/// <returns>A decimal value.</returns>
public decimal ToDecimal()
{
return value / 64m;
}
/// <summary>
/// Compares this instance to another <see cref="Fixed26Dot6"/> for equality.
/// </summary>
/// <param name="other">A <see cref="Fixed26Dot6"/>.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public bool Equals(Fixed26Dot6 other)
{
return value == other.value;
}
/// <summary>
/// Compares this instnace with another <see cref="Fixed26Dot6"/> and returns an integer that indicates
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
/// other <see cref="Fixed26Dot6"/>.
/// </summary>
/// <param name="other">A <see cref="Fixed26Dot6"/>.</param>
/// <returns>A value indicating the relative order of the instances.</returns>
public int CompareTo(Fixed26Dot6 other)
{
return value.CompareTo(other.value);
}
#endregion
#region Overrides
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(IFormatProvider provider)
{
return ToDecimal().ToString(provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format)
{
return ToDecimal().ToString(format);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format, IFormatProvider provider)
{
return ToDecimal().ToString(format, provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return ToDecimal().ToString();
}
/// <summary>
/// Calculates a hash code for the current object.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode()
{
return value.GetHashCode();
}
/// <summary>
/// Determines whether the specified object isequal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>A value indicating equality between the two objects.</returns>
public override bool Equals(object obj)
{
if (obj is Fixed26Dot6)
return this.Equals((Fixed26Dot6)obj);
else if (obj is int)
return value == ((Fixed26Dot6)obj).value;
else
return false;
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,546 @@
#region MIT License
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont
{
/// <summary>
/// Represents a fixed-point decimal value with 14 bits of decimal precision.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Fixed2Dot14 : IEquatable<Fixed2Dot14>, IComparable<Fixed2Dot14>
{
#region Fields
/// <summary>
/// The raw 2.14 short.
/// </summary>
private short value;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
/// </summary>
/// <param name="value">An integer value.</param>
public Fixed2Dot14(short value)
{
this.value = (short)(value << 14);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed2Dot14(float value)
{
this.value = (short)(value * 16384);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed2Dot14(double value)
{
this.value = (short)(value * 16384);
}
/// <summary>
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
/// </summary>
/// <param name="value">A floating point value.</param>
public Fixed2Dot14(decimal value)
{
this.value = (short)(value * 16384);
}
#endregion
#region Properties
/// <summary>
/// Gets the raw 2.14 integer.
/// </summary>
public int Value
{
get
{
return value;
}
}
#endregion
#region Methods
#region Static
/// <summary>
/// Creates a <see cref="Fixed2Dot14"/> from an int containing a 2.14 value.
/// </summary>
/// <param name="value">A 2.14 value.</param>
/// <returns>An instance of <see cref="Fixed2Dot14"/>.</returns>
public static Fixed2Dot14 FromRawValue(short value)
{
Fixed2Dot14 f = new Fixed2Dot14();
f.value = value;
return f;
}
/// <summary>
/// Creates a new <see cref="Fixed2Dot14"/> from a <see cref="System.Int16"/>
/// </summary>
/// <param name="value">A <see cref="System.Int16"/> value.</param>
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
public static Fixed2Dot14 FromInt16(short value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Single"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 2.14 value.</returns>
public static Fixed2Dot14 FromSingle(float value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 2.14 value.</returns>
public static Fixed2Dot14 FromDouble(double value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A floating-point value.</param>
/// <returns>A fixed 2.14 value.</returns>
public static Fixed2Dot14 FromDecimal(decimal value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Adds two 2.14 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed2Dot14 Add(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Fixed2Dot14.FromRawValue((short)(left.value + right.value));
}
/// <summary>
/// Subtacts one 2.14 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed2Dot14 Subtract(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Fixed2Dot14.FromRawValue((short)(left.value - right.value));
}
/// <summary>
/// Multiplies two 2.14 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed2Dot14 Multiply(Fixed2Dot14 left, Fixed2Dot14 right)
{
int mul = (int)left.value * (int)right.value;
Fixed2Dot14 ans;
ans.value = (short)(mul >> 14);
return ans;
}
/// <summary>
/// Divides one 2.14 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed2Dot14 Divide(Fixed2Dot14 left, Fixed2Dot14 right)
{
int div = ((int)left.Value << 6) / right.value;
Fixed2Dot14 ans;
ans.value = (short)div;
return ans;
}
#endregion
#region Operators
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed2Dot14"/>.
/// </summary>
/// <param name="value">A <see cref="System.Single"/> value.</param>
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
public static explicit operator Fixed2Dot14(float value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed2Dot14"/>.
/// </summary>
/// <param name="value">A <see cref="System.Double"/> value.</param>
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
public static explicit operator Fixed2Dot14(double value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed2Dot14"/>.
/// </summary>
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
public static explicit operator Fixed2Dot14(decimal value)
{
return new Fixed2Dot14(value);
}
/// <summary>
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Single"/>.
/// </summary>
/// <remarks>
/// This operation can result in a loss of data.
/// </remarks>
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static explicit operator float(Fixed2Dot14 value)
{
return value.ToSingle();
}
/// <summary>
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Double"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
public static implicit operator double(Fixed2Dot14 value)
{
return value.ToDouble();
}
/// <summary>
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Decimal"/>.
/// </summary>
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
public static implicit operator decimal(Fixed2Dot14 value)
{
return value.ToDecimal();
}
/// <summary>
/// Adds two 2.14 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the addition.</returns>
public static Fixed2Dot14 operator +(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Add(left, right);
}
/// <summary>
/// Subtacts one 2.14 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the subtraction.</returns>
public static Fixed2Dot14 operator -(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Subtract(left, right);
}
/// <summary>
/// Multiplies two 2.14 values together.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the multiplication.</returns>
public static Fixed2Dot14 operator *(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Multiply(left, right);
}
/// <summary>
/// Divides one 2.14 values from another.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>The result of the division.</returns>
public static Fixed2Dot14 operator /(Fixed2Dot14 left, Fixed2Dot14 right)
{
return Divide(left, right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed2Dot14"/> for equality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public static bool operator ==(Fixed2Dot14 left, Fixed2Dot14 right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances of <see cref="Fixed2Dot14"/> for inequality.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether the two instances are not equal.</returns>
public static bool operator !=(Fixed2Dot14 left, Fixed2Dot14 right)
{
return !(left == right);
}
/// <summary>
/// Checks if the left operand is less than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than right.</returns>
public static bool operator <(Fixed2Dot14 left, Fixed2Dot14 right)
{
return left.CompareTo(right) < 0;
}
/// <summary>
/// Checks if the left operand is less than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is less than or equal to right.</returns>
public static bool operator <=(Fixed2Dot14 left, Fixed2Dot14 right)
{
return left.CompareTo(right) <= 0;
}
/// <summary>
/// Checks if the left operand is greater than the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than right.</returns>
public static bool operator >(Fixed2Dot14 left, Fixed2Dot14 right)
{
return left.CompareTo(right) > 0;
}
/// <summary>
/// Checks if the left operand is greater than or equal to the right operand.
/// </summary>
/// <param name="left">The left operand.</param>
/// <param name="right">The right operand.</param>
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
public static bool operator >=(Fixed2Dot14 left, Fixed2Dot14 right)
{
return left.CompareTo(right) >= 0;
}
#endregion
#region Instance
/// <summary>
/// Removes the decimal part of the value.
/// </summary>
/// <returns>The truncated number.</returns>
public short Floor()
{
return (short)(value >> 14);
}
/// <summary>
/// Rounds to the nearest whole number.
/// </summary>
/// <returns>The nearest whole number.</returns>
public short Round()
{
//add 2^13, rounds the integer part up if the decimal value is >= 0.5
return (short)((value + 8192) >> 14);
}
/// <summary>
/// Rounds up to the next whole number.
/// </summary>
/// <returns>The next whole number.</returns>
public short Ceiling()
{
//add 2^14 - 1, rounds the integer part up if there's any decimal value
return (short)((value + 16383) >> 14);
}
/// <summary>
/// Converts the value to a <see cref="System.Int16"/>. The value is floored.
/// </summary>
/// <returns>An integer value.</returns>
public short ToInt16()
{
return Floor();
}
/// <summary>
/// Converts the value to a <see cref="System.Single"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public float ToSingle()
{
return value / 16384f;
}
/// <summary>
/// Converts the value to a <see cref="System.Double"/>.
/// </summary>
/// <returns>A floating-point value.</returns>
public double ToDouble()
{
return value / 16384d;
}
/// <summary>
/// Converts the value to a <see cref="System.Decimal"/>.
/// </summary>
/// <returns>A decimal value.</returns>
public decimal ToDecimal()
{
return value / 16384m;
}
/// <summary>
/// Compares this instance to another <see cref="Fixed2Dot14"/> for equality.
/// </summary>
/// <param name="other">A <see cref="Fixed2Dot14"/>.</param>
/// <returns>A value indicating whether the two instances are equal.</returns>
public bool Equals(Fixed2Dot14 other)
{
return value == other.value;
}
/// <summary>
/// Compares this instnace with another <see cref="Fixed2Dot14"/> and returns an integer that indicates
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
/// other <see cref="Fixed2Dot14"/>.
/// </summary>
/// <param name="other">A <see cref="Fixed2Dot14"/>.</param>
/// <returns>A value indicating the relative order of the instances.</returns>
public int CompareTo(Fixed2Dot14 other)
{
return value.CompareTo(other.value);
}
#endregion
#region Overrides
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(IFormatProvider provider)
{
return ToDecimal().ToString(provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format)
{
return ToDecimal().ToString(format);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(string format, IFormatProvider provider)
{
return ToDecimal().ToString(format, provider);
}
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return ToDecimal().ToString();
}
/// <summary>
/// Calculates a hash code for the current object.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode()
{
return value.GetHashCode();
}
/// <summary>
/// Determines whether the specified object isequal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>A value indicating equality between the two objects.</returns>
public override bool Equals(object obj)
{
if (obj is Fixed2Dot14)
return this.Equals((Fixed2Dot14)obj);
else if (obj is int)
return value == ((Fixed2Dot14)obj).value;
else
return false;
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,594 @@
#region MIT License
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Linq;
using SharpFont.Fnt.Internal;
namespace SharpFont.Fnt
{
/// <summary>
/// Describes the general appearance of the font.
/// </summary>
public enum Family
{
/// <summary>
/// Don't care or don't know which family.
/// </summary>
DontCare = 0,
/// <summary>
/// The font has a Roman appearance.
/// </summary>
Roman = 1,
/// <summary>
/// The font has a Swiss appearance.
/// </summary>
Swiss = 2,
/// <summary>
/// The font has a Modern appearance.
/// </summary>
Modern = 3,
/// <summary>
/// The font has a script-like appearance.
/// </summary>
Script = 4,
/// <summary>
/// The font is decorative.
/// </summary>
Decorative = 5
}
/// <summary>
/// Provides flags for font proportions and color.
/// </summary>
[Flags]
[CLSCompliant(false)]
public enum Flags : ushort
{
/// <summary>
/// Font is fixed.
/// </summary>
Fixed = 1 << 0,
/// <summary>
/// Font is proportional.
/// </summary>
Proportional = 1 << 1,
/// <summary>
/// Font is ABC fixed.
/// </summary>
AbcFixed = 1 << 2,
/// <summary>
/// Font is ABC proportional.
/// </summary>
AbcProportional = 1 << 3,
/// <summary>
/// Font is 2-bit color.
/// </summary>
Color1 = 1 << 4,
/// <summary>
/// Font is 4-bit color.
/// </summary>
Color16 = 1 << 5,
/// <summary>
/// Font is 8-bit color.
/// </summary>
Color256 = 1 << 6,
/// <summary>
/// Font is RGB color.
/// </summary>
RgbColor = 1 << 7
}
/// <summary>
/// Windows FNT Header info.
/// </summary>
public class Header
{
#region Fields
private IntPtr reference;
private HeaderRec rec;
#endregion
#region Constructors
internal Header(IntPtr reference)
{
Reference = reference;
}
#endregion
#region Properties
/// <summary>
/// Gets the version format of the file (e.g. 0x0200).
/// </summary>
[CLSCompliant(false)]
public ushort Version
{
get
{
return rec.version;
}
}
/// <summary>
/// Gets the size of the file in bytes.
/// </summary>
[CLSCompliant(false)]
public uint FileSize
{
get
{
return (uint)rec.file_size;
}
}
/// <summary>
/// Gets the copyright text.
/// Limited to 60 bytes.
/// </summary>
public byte[] Copyright
{
get
{
return rec.copyright;
}
}
/// <summary>
/// Gets the filetype (vector or bitmap). This is exclusively for GDI use.
/// </summary>
[CLSCompliant(false)]
public ushort FileType
{
get
{
return rec.file_type;
}
}
/// <summary>
/// Gets the nominal point size determined by the designer at which the font looks
/// best.
/// </summary>
[CLSCompliant(false)]
public ushort NominalPointSize
{
get
{
return rec.nominal_point_size;
}
}
/// <summary>
/// Gets the nominal vertical resolution in dots per inch.
/// </summary>
[CLSCompliant(false)]
public ushort VerticalResolution
{
get
{
return rec.vertical_resolution;
}
}
/// <summary>
/// Gets the nominal horizontal resolution in dots per inch.
/// </summary>
[CLSCompliant(false)]
public ushort HorizontalResolution
{
get
{
return rec.horizontal_resolution;
}
}
/// <summary>
/// Gets the height of the font's ascent from the baseline.
/// </summary>
[CLSCompliant(false)]
public ushort Ascent
{
get
{
return rec.ascent;
}
}
/// <summary>
/// Gets the amount of leading inside the bounds of <see cref="PixelHeight"/>.
/// </summary>
[CLSCompliant(false)]
public ushort InternalLeading
{
get
{
return rec.internal_leading;
}
}
/// <summary>
/// Gets the amount of leading the designer recommends to be added between
/// rows.
/// </summary>
[CLSCompliant(false)]
public ushort ExternalLeading
{
get
{
return rec.external_leading;
}
}
/// <summary>
/// Gets whether the font is italic.
/// </summary>
public bool Italic
{
get
{
return (0x01 & rec.italic) == 0x01;
}
}
/// <summary>
/// Ges whether the font includes underlining.
/// </summary>
public bool Underline
{
get
{
return (0x01 & rec.underline) == 0x01;
}
}
/// <summary>
/// Ges whether the font includes strikeout.
/// </summary>
public bool Strikeout
{
get
{
return (0x01 & rec.strike_out) == 0x01;
}
}
/// <summary>
/// Gets the weight of characters on a scale of 1 to 1000, with
/// 400 being regular weight.
/// </summary>
[CLSCompliant(false)]
public ushort Weight
{
get
{
return rec.weight;
}
}
/// <summary>
/// Gets the character set specified by the font.
/// </summary>
public byte Charset
{
get
{
return rec.charset;
}
}
/// <summary>
/// Gets the width of the vector grid (vector fonts). For raster fonts,
/// a zero value indicates that characters have variables widths,
/// otherwise, the value is the width of the bitmap for all characters.
/// </summary>
[CLSCompliant(false)]
public ushort PixelWidth
{
get
{
return rec.pixel_width;
}
}
/// <summary>
/// Gets the height of the vector grid (vector fonts) or the height
/// of the bitmap for all characters (raster fonts).
/// </summary>
[CLSCompliant(false)]
public ushort PixelHeight
{
get
{
return rec.pixel_height;
}
}
/// <summary>
/// Gets whether the font is variable pitch.
/// </summary>
public byte PitchAndFamily
{
get
{
return rec.pitch_and_family;
}
}
/// <summary>
/// Gets the width of characters in the font, based on the width of 'X'.
/// </summary>
[CLSCompliant(false)]
public ushort AverageWidth
{
get
{
return rec.avg_width;
}
}
/// <summary>
/// Gets the maximum width of all characters in the font.
/// </summary>
[CLSCompliant(false)]
public ushort MaximumWidth
{
get
{
return rec.max_width;
}
}
/// <summary>
/// Gets the first character code specified in the font.
/// </summary>
public byte FirstChar
{
get
{
return rec.first_char;
}
}
/// <summary>
/// Gets the last character code specified in the font.
/// </summary>
public byte LastChar
{
get
{
return rec.last_char;
}
}
/// <summary>
/// Gets the character to substitute when a character is needed that
/// isn't defined in the font.
/// </summary>
public byte DefaultChar
{
get
{
return rec.default_char;
}
}
/// <summary>
/// Gets the character that defines word breaks, for purposes of word
/// wrapping and word spacing justification. This value is relative to
/// the <see cref="FirstChar"/>, so the character code is this value
/// minus <see cref="FirstChar"/>.
/// </summary>
public byte BreakChar
{
get
{
return rec.break_char;
}
}
/// <summary>
/// Gets the number of bytes in each row of the bitmap (raster fonts).
/// </summary>
[CLSCompliant(false)]
public ushort BytesPerRow
{
get
{
return rec.bytes_per_row;
}
}
/// <summary>
/// Gets the offset in the file, in bytes, to the string that gives the device name.
/// The value is 0 for generic fonts.
/// </summary>
[CLSCompliant(false)]
public uint DeviceOffset
{
get
{
return (uint)rec.device_offset;
}
}
/// <summary>
/// Gets the offset in the file, in bytes, to the string that gives the face name
/// (null-terminated).
/// </summary>
[CLSCompliant(false)]
public uint FaceNameOffset
{
get
{
return (uint)rec.face_name_offset;
}
}
/// <summary>
/// Gets the absolute machine address of the bitmap,
/// which is set by GDI at load time.
/// </summary>
[CLSCompliant(false)]
public uint BitsPointer
{
get
{
return (uint)rec.bits_pointer;
}
}
/// <summary>
/// Gets the offset in the file, in bytes, to the beginning of the character data
/// (raster or vector).
/// </summary>
[CLSCompliant(false)]
public uint BitsOffset
{
get
{
return (uint)rec.bits_offset;
}
}
/// <summary>
/// Reservied.
/// </summary>
public byte Reserved
{
get
{
return rec.reserved;
}
}
/// <summary>
/// Gets <see cref="Flags"/> that describe font proportion and color.
/// </summary>
[CLSCompliant(false)]
public Flags Flags
{
get
{
return (Flags)rec.flags;
}
}
/// <summary>
/// ASpace has not been used since before Windows 3.0.
/// Set it to 0 for compatibility.
/// </summary>
[CLSCompliant(false)]
public ushort ASpace
{
get
{
return rec.A_space;
}
}
/// <summary>
/// BSpace has not been used since before Windows 3.0.
/// Set it to 0 for compatibility.
/// </summary>
[CLSCompliant(false)]
public ushort BSpace
{
get
{
return rec.B_space;
}
}
/// <summary>
/// CSpace has not been used since before Windows 3.0.
/// Set it to 0 for compatibility.
/// </summary>
[CLSCompliant(false)]
public ushort CSpace
{
get
{
return rec.C_space;
}
}
/// <summary>
/// Gets the offset of the color table.
/// </summary>
[CLSCompliant(false)]
public ushort ColorTableOffset
{
get
{
return rec.color_table_offset;
}
}
/// <summary>
/// This field is reserved.
/// </summary>
[CLSCompliant(false)]
public uint[] Reserved1
{
get
{
return rec.reserved1.Select(x => (uint) x).ToArray();
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<HeaderRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,77 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Fnt.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct HeaderRec
{
internal ushort version;
internal FT_ULong file_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
internal byte[] copyright;
internal ushort file_type;
internal ushort nominal_point_size;
internal ushort vertical_resolution;
internal ushort horizontal_resolution;
internal ushort ascent;
internal ushort internal_leading;
internal ushort external_leading;
internal byte italic;
internal byte underline;
internal byte strike_out;
internal ushort weight;
internal byte charset;
internal ushort pixel_width;
internal ushort pixel_height;
internal byte pitch_and_family;
internal ushort avg_width;
internal ushort max_width;
internal byte first_char;
internal byte last_char;
internal byte default_char;
internal byte break_char;
internal ushort bytes_per_row;
internal FT_ULong device_offset;
internal FT_ULong face_name_offset;
internal FT_ULong bits_pointer;
internal FT_ULong bits_offset;
internal byte reserved;
internal FT_ULong flags;
internal ushort A_space;
internal ushort B_space;
internal ushort C_space;
internal ushort color_table_offset;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
internal FT_ULong[] reserved1;
}
}

View File

@@ -0,0 +1,148 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont.Fnt
{
/// <summary>
/// A list of valid values for the charset byte in <see cref="Header"/>. Exact mapping tables for the various
/// cpXXXX encodings (except for cp1361) can be found at <see href="ftp://ftp.unicode.org" /> in the
/// MAPPINGS/VENDORS/MICSFT/WINDOWS subdirectory. cp1361 is roughly a superset of
/// MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT.
/// </summary>
public enum WinFntId : byte
{
/// <summary>
/// ANSI encoding. A superset of ISO 8859-1.
/// </summary>
CP1252 = 0,
/// <summary>
/// This is used for font enumeration and font creation as a don't care value. Valid font files don't contain
/// this value. When querying for information about the character set of the font that is currently selected
/// into a specified device context, this return value (of the related Windows API) simply denotes failure.
/// </summary>
Default = 1,
/// <summary>
/// There is no known mapping table available.
/// </summary>
Symbol = 2,
/// <summary>
/// Mac Roman encoding.
/// </summary>
Mac = 77,
/// <summary>
/// A superset of Japanese Shift-JIS (with minor deviations).
/// </summary>
CP932 = 128,
/// <summary>
/// A superset of Korean Hangul KS C 5601-1987 (with different ordering and minor deviations).
/// </summary>
CP949 = 129,
/// <summary>
/// Korean (Johab).
/// </summary>
CP1361 = 130,
/// <summary>
/// A superset of simplified Chinese GB 2312-1980 (with different ordering and minor deviations).
/// </summary>
CP936 = 134,
/// <summary>
/// A superset of traditional Chinese Big 5 ETen (with different ordering and minor deviations).
/// </summary>
CP950 = 136,
/// <summary>
/// A superset of Greek ISO 8859-7 (with minor modifications).
/// </summary>
CP1253 = 161,
/// <summary>
/// A superset of Turkish ISO 8859-9.
/// </summary>
CP1254 = 162,
/// <summary>
/// For Vietnamese. This encoding doesn't cover all necessary characters.
/// </summary>
CP1258 = 163,
/// <summary>
/// A superset of Hebrew ISO 8859-8 (with some modifications).
/// </summary>
CP1255 = 177,
/// <summary>
/// A superset of Arabic ISO 8859-6 (with different ordering).
/// </summary>
CP1256 = 178,
/// <summary>
/// A superset of Baltic ISO 8859-13 (with some deviations).
/// </summary>
CP1257 = 186,
/// <summary>
/// A superset of Russian ISO 8859-5 (with different ordering).
/// </summary>
CP1251 = 204,
/// <summary>
/// A superset of Thai TIS 620 and ISO 8859-11.
/// </summary>
CP874 = 222,
/// <summary>
/// A superset of East European ISO 8859-2 (with slightly different ordering).
/// </summary>
CP1250 = 238,
/// <summary><para>
/// From Michael Pöttgen &lt;michael@poettgen.de&gt;:
/// The Windows Font Mapping article says that <see cref="WinFntId.Oem"/> is used for the charset of vector
/// fonts, like modern.fon, roman.fon, and script.fon on Windows.
/// </para><para>
/// The CreateFont documentation says: The <see cref="WinFntId.Oem"/> value specifies a character set that is
/// operating-system dependent.
/// </para><para>
/// The IFIMETRICS documentation from the Windows Driver Development Kit says: This font supports an
/// OEM-specific character set. The OEM character set is system dependent.
/// </para><para>
/// In general OEM, as opposed to ANSI (i.e., cp1252), denotes the second default codepage that most
/// international versions of Windows have. It is one of the OEM codepages from
/// <see href="http://www.microsoft.com/globaldev/reference/cphome.mspx"/>, and is used for the DOS boxes, to
/// support legacy applications. A German Windows version for example usually uses ANSI codepage 1252 and OEM
/// codepage 850.
/// </para></summary>
Oem = 255
}
}

View File

@@ -0,0 +1,153 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// An exception that gets thrown when FreeType returns an error code.
/// </summary>
public class FreeTypeException : Exception
{
private Error error;
/// <summary>
/// Initializes a new instance of the <see cref="FreeTypeException"/> class.
/// </summary>
/// <param name="error">The error returned by FreeType.</param>
public FreeTypeException(Error error)
: base("FreeType error: " + GetErrorMessage(error))
{
this.error = error;
}
/// <summary>
/// Gets the FreeType error code that caused the exception.
/// </summary>
public Error Error
{
get
{
return this.error;
}
}
private static string GetErrorMessage(Error err)
{
switch (err)
{
case Error.Ok: return "No error.";
case Error.CannotOpenResource: return "Cannot open resource.";
case Error.UnknownFileFormat: return "Unknown file format.";
case Error.InvalidFileFormat: return "Broken file.";
case Error.InvalidVersion: return "Invalid FreeType version.";
case Error.LowerModuleVersion: return "Module version is too low.";
case Error.InvalidArgument: return "Invalid argument.";
case Error.UnimplementedFeature: return "Unimplemented feature.";
case Error.InvalidTable: return "Broken table.";
case Error.InvalidOffset: return "Broken offset within table.";
case Error.ArrayTooLarge: return "Array allocation size too large.";
case Error.InvalidGlyphIndex: return "Invalid glyph index.";
case Error.InvalidCharacterCode: return "Invalid character code.";
case Error.InvalidGlyphFormat: return "Unsupported glyph image format.";
case Error.CannotRenderGlyph: return "Cannot render this glyph format.";
case Error.InvalidOutline: return "Invalid outline.";
case Error.InvalidComposite: return "Invalid composite glyph.";
case Error.TooManyHints: return "Too many hints.";
case Error.InvalidPixelSize: return "Invalid pixel size.";
case Error.InvalidHandle: return "Invalid object handle.";
case Error.InvalidLibraryHandle: return "Invalid library handle.";
case Error.InvalidDriverHandle: return "Invalid module handle.";
case Error.InvalidFaceHandle: return "Invalid face handle.";
case Error.InvalidSizeHandle: return "Invalid size handle.";
case Error.InvalidSlotHandle: return "Invalid glyph slot handle.";
case Error.InvalidCharMapHandle: return "Invalid charmap handle.";
case Error.InvalidCacheHandle: return "Invalid cache manager handle.";
case Error.InvalidStreamHandle: return "Invalid stream handle.";
case Error.TooManyDrivers: return "Too many modules.";
case Error.TooManyExtensions: return "Too many extensions.";
case Error.OutOfMemory: return "Out of memory.";
case Error.UnlistedObject: return "Unlisted object.";
case Error.CannotOpenStream: return "Cannot open stream.";
case Error.InvalidStreamSeek: return "Invalid stream seek.";
case Error.InvalidStreamSkip: return "Invalid stream skip.";
case Error.InvalidStreamRead: return "Invalid stream read.";
case Error.InvalidStreamOperation: return "Invalid stream operation.";
case Error.InvalidFrameOperation: return "Invalid frame operation.";
case Error.NestedFrameAccess: return "Nested frame access.";
case Error.InvalidFrameRead: return "Invalid frame read.";
case Error.RasterUninitialized: return "Raster uninitialized.";
case Error.RasterCorrupted: return "Raster corrupted.";
case Error.RasterOverflow: return "Raster overflow.";
case Error.RasterNegativeHeight: return "Negative height while rastering.";
case Error.TooManyCaches: return "Too many registered caches.";
case Error.InvalidOpCode: return "Invalid opcode.";
case Error.TooFewArguments: return "Too few arguments.";
case Error.StackOverflow: return "Stack overflow.";
case Error.CodeOverflow: return "Code overflow.";
case Error.BadArgument: return "Bad argument.";
case Error.DivideByZero: return "Division by zero.";
case Error.InvalidReference: return "Invalid reference.";
case Error.DebugOpCode: return "Found debug opcode.";
case Error.EndfInExecStream: return "Found ENDF opcode in execution stream.";
case Error.NestedDefs: return "Nested DEFS.";
case Error.InvalidCodeRange: return "Invalid code range.";
case Error.ExecutionTooLong: return "Execution context too long.";
case Error.TooManyFunctionDefs: return "Too many function definitions.";
case Error.TooManyInstructionDefs: return "Too many instruction definitions.";
case Error.TableMissing: return "SFNT font table missing.";
case Error.HorizHeaderMissing: return "Horizontal header (hhea) table missing.";
case Error.LocationsMissing: return "Locations (loca) table missing.";
case Error.NameTableMissing: return "Name table missing.";
case Error.CMapTableMissing: return "Character map (cmap) table missing.";
case Error.HmtxTableMissing: return "Horizontal metrics (hmtx) table missing.";
case Error.PostTableMissing: return "PostScript (post) table missing.";
case Error.InvalidHorizMetrics: return "Invalid horizontal metrics.";
case Error.InvalidCharMapFormat: return "Invalid character map (cmap) format.";
case Error.InvalidPPem: return "Invalid ppem value.";
case Error.InvalidVertMetrics: return "Invalid vertical metrics.";
case Error.CouldNotFindContext: return "Could not find context.";
case Error.InvalidPostTableFormat: return "Invalid PostScript (post) table format.";
case Error.InvalidPostTable: return "Invalid PostScript (post) table.";
case Error.SyntaxError: return "Opcode syntax error.";
case Error.StackUnderflow: return "Argument stack underflow.";
case Error.Ignore: return "Ignore this error.";
case Error.NoUnicodeGlyphName: return "No Unicode glyph name found.";
case Error.MissingStartfontField: return "`STARTFONT' field missing.";
case Error.MissingFontField: return "`FONT' field missing.";
case Error.MissingSizeField: return "`SIZE' field missing.";
case Error.MissingFontboudingboxField: return "`FONTBOUNDINGBOX' field missing.";
case Error.MissingCharsField: return "`CHARS' field missing.";
case Error.MissingStartcharField: return "`STARTCHAR' field missing.";
case Error.MissingEncodingField: return "`ENCODING' field missing.";
case Error.MissingBbxField: return "`BBX' field missing.";
case Error.BbxTooBig: return "`BBX' too big.";
case Error.CorruptedFontHeader: return "Font header corrupted or missing fields.";
case Error.CorruptedFontGlyphs: return "Font glyphs corrupted or missing fields.";
default: return "Encountered an unknown error. Most likely this is a new error that hasn't been included in SharpFont yet. Error:" + (int)err;
}
}
}
}

View File

@@ -0,0 +1,70 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// A list of values and/or bit-flags returned by the FT_Get_Gasp function.
/// </summary>
/// <remarks><para>
/// The bit-flags <see cref="Gasp.DoGridfit"/> and <see cref="Gasp.DoGray"/> are to be used for standard font
/// rasterization only. Independently of that, <see cref="Gasp.SymmetricSmoothing"/> and
/// <see cref="Gasp.SymmetricGridfit"/> are to be used if ClearType is enabled (and <see cref="Gasp.DoGridfit"/>
/// and <see cref="Gasp.DoGray"/> are consequently ignored).
/// </para><para>
/// ClearType is Microsoft's implementation of LCD rendering, partly protected by patents.
/// </para></remarks>
[Flags]
public enum Gasp
{
/// <summary>
/// This special value means that there is no GASP table in this face. It is up to the client to decide what to
/// do.
/// </summary>
NoTable = -1,
/// <summary>
/// Grid-fitting and hinting should be performed at the specified ppem. This really means TrueType bytecode
/// interpretation. If this bit is not set, no hinting gets applied.
/// </summary>
DoGridfit = 0x01,
/// <summary>
/// Anti-aliased rendering should be performed at the specified ppem. If not set, do monochrome rendering.
/// </summary>
DoGray = 0x02,
/// <summary>
/// If set, smoothing along multiple axes must be used with ClearType.
/// </summary>
SymmetricSmoothing = 0x08,
/// <summary>
/// Grid-fitting must be used with ClearType's symmetric smoothing.
/// </summary>
SymmetricGridfit = 0x10
}
}

View File

@@ -0,0 +1,156 @@
#region MIT License
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// Describe a function used to destroy the client data of any FreeType object. See the description of the
/// <see cref="Generic"/> type for details of usage.
/// </summary>
/// <param name="object">
/// The address of the FreeType object which is under finalization. Its client data is accessed through its
/// generic field.
/// </param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void GenericFinalizer(IntPtr @object);
/// <summary><para>
/// Client applications often need to associate their own data to a variety of FreeType core objects. For example,
/// a text layout API might want to associate a glyph cache to a given size object.
/// </para><para>
/// Most FreeType object contains a generic field, of type <see cref="Generic"/>, which usage is left to client
/// applications and font servers.
/// </para><para>
/// It can be used to store a pointer to client-specific data, as well as the address of a finalizer function,
/// which will be called by FreeType when the object is destroyed (for example, the previous client example would
/// put the address of the glyph cache destructor in the finalizer field).
/// </para></summary>
[Obsolete("Use the Tag property and Disposed event.")]
public class Generic
{
#region Fields
private GenericRec rec;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Generic"/> class.
/// </summary>
/// <param name="data">
/// A typeless pointer to some client data. The data it cointains must stay fixed until finalizer is called.
/// </param>
/// <param name="finalizer">A delegate that gets called when the contained object gets finalized.</param>
public Generic(IntPtr data, GenericFinalizer finalizer)
{
rec.data = data;
//rec.finalizer = finalizer;
}
internal Generic(GenericRec genInternal)
{
rec = genInternal;
}
internal Generic(IntPtr reference)
{
rec = PInvokeHelper.PtrToStructure<GenericRec>(reference);
}
internal Generic(IntPtr reference, int offset)
: this(new IntPtr(reference.ToInt64() + offset))
{
}
#endregion
#region Properties
/// <summary>
/// Gets the size of a <see cref="Generic"/>, in bytes.
/// </summary>
public static int SizeInBytes
{
get
{
return Marshal.SizeOf(typeof(GenericRec));
}
}
/// <summary>
/// Gets or sets a typeless pointer to any client-specified data. This field is completely ignored by the
/// FreeType library.
/// </summary>
public IntPtr Data
{
get
{
return rec.data;
}
set
{
rec.data = value;
}
}
/// <summary>
/// Gets or sets a pointer to a <see cref="GenericFinalizer"/> function, which will be called when the object
/// is destroyed. If this field is set to NULL, no code will be called.
/// </summary>
/*public GenericFinalizer Finalizer
{
get
{
return rec.finalizer;
}
set
{
rec.finalizer = value;
}
}*/
#endregion
#region Methods
//TODO make this private and build it into the setters if the reference isn't IntPtr.Zero.
internal void WriteToUnmanagedMemory(IntPtr location)
{
Marshal.WriteIntPtr(location, rec.data);
//Marshal.WriteIntPtr(location, IntPtr.Size, Marshal.GetFunctionPointerForDelegate(rec.finalizer));
Marshal.WriteIntPtr(location, IntPtr.Size, rec.finalizer);
}
#endregion
}
}

View File

@@ -0,0 +1,444 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// The root glyph structure contains a given glyph image plus its advance width in 16.16 fixed float format.
/// </summary>
public sealed class Glyph : IDisposable
{
#region Fields
private bool disposed;
private IntPtr reference;
private GlyphRec rec;
private Library parentLibrary;
#endregion
#region Constructors
internal Glyph(IntPtr reference, Library parentLibrary)
{
Reference = reference;
this.parentLibrary = parentLibrary;
parentLibrary.AddChildGlyph(this);
}
/// <summary>
/// Finalizes an instance of the Glyph class.
/// </summary>
~Glyph()
{
Dispose(false);
}
#endregion
#region Properties
/// <summary>
/// Gets a value indicating whether the object has been disposed.
/// </summary>
public bool IsDisposed
{
get
{
return disposed;
}
}
/// <summary>
/// Gets a handle to the FreeType library object.
/// </summary>
public Library Library
{
get
{
if (disposed)
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
return parentLibrary;
}
}
/// <summary>
/// Gets the format of the glyph's image.
/// </summary>
[CLSCompliant(false)]
public GlyphFormat Format
{
get
{
if (disposed)
throw new ObjectDisposedException("Format", "Cannot access a disposed object.");
return rec.format;
}
}
/// <summary>
/// Gets a 16.16 vector that gives the glyph's advance width.
/// </summary>
public FTVector Advance
{
get
{
if (disposed)
throw new ObjectDisposedException("Advance", "Cannot access a disposed object.");
return rec.advance;
}
}
internal IntPtr Reference
{
get
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
return reference;
}
set
{
if (disposed)
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
reference = value;
rec = PInvokeHelper.PtrToStructure<GlyphRec>(reference);
}
}
#endregion
#region Operators
/// <summary>
/// Downcasts a <see cref="Glyph"/> to a <see cref="BitmapGlyph"/>
/// </summary>
/// <param name="g">A <see cref="Glyph"/>.</param>
/// <returns>A <see cref="BitmapGlyph"/>.</returns>
/// <exception cref="InvalidCastException">
/// If the <see cref="Glyph"/>'s format is not <see cref="GlyphFormat.Bitmap"/>.
/// </exception>
public static explicit operator BitmapGlyph(Glyph g)
{
if (g.Format == GlyphFormat.Bitmap)
return new BitmapGlyph(g);
else
throw new InvalidCastException("The glyph's format is not GlyphFormat.Bitmap.");
}
/// <summary>
/// Downcasts a <see cref="Glyph"/> to a <see cref="OutlineGlyph"/>
/// </summary>
/// <param name="g">A <see cref="Glyph"/>.</param>
/// <returns>A <see cref="OutlineGlyph"/>.</returns>
/// <exception cref="InvalidCastException">
/// If the <see cref="Glyph"/>'s format is not <see cref="GlyphFormat.Outline"/>.
/// </exception>
public static explicit operator OutlineGlyph(Glyph g)
{
if (g.Format == GlyphFormat.Outline)
return new OutlineGlyph(g);
else
throw new InvalidCastException("The glyph's format is not GlyphFormat.Outline.");
}
#endregion
#region Methods
/// <summary>
/// CLS-compliant equivalent of an explicit cast to <see cref="BitmapGlyph"/>.
/// </summary>
/// <returns>A <see cref="BitmapGlyph"/>.</returns>
public BitmapGlyph ToBitmapGlyph()
{
return (BitmapGlyph)this;
}
/// <summary>
/// CLS-compliant equivalent of an explicit cast to <see cref="OutlineGlyph"/>.
/// </summary>
/// <returns>A <see cref="OutlineGlyph"/>.</returns>
public OutlineGlyph ToOutlineGlyph()
{
return (OutlineGlyph)this;
}
/// <summary>
/// A function used to copy a glyph image. Note that the created <see cref="Glyph"/> object must be released
/// with <see cref="Glyph.Dispose()"/>.
/// </summary>
/// <returns>A handle to the target glyph object. 0 in case of error.</returns>
public Glyph Copy()
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
IntPtr glyphRef;
Error err = FT.FT_Glyph_Copy(Reference, out glyphRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
return new Glyph(glyphRef, Library);
}
/// <summary>
/// Transform a glyph image if its format is scalable.
/// </summary>
/// <param name="matrix">A pointer to a 2x2 matrix to apply.</param>
/// <param name="delta">
/// A pointer to a 2d vector to apply. Coordinates are expressed in 1/64th of a pixel.
/// </param>
public void Transform(FTMatrix matrix, FTVector delta)
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
Error err = FT.FT_Glyph_Transform(Reference, ref matrix, ref delta);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary><para>
/// Return a glyph's control box. The control box encloses all the outline's points, including Bézier control
/// points. Though it coincides with the exact bounding box for most glyphs, it can be slightly larger in some
/// situations (like when rotating an outline which contains Bézier outside arcs).
/// </para><para>
/// Computing the control box is very fast, while getting the bounding box can take much more time as it needs
/// to walk over all segments and arcs in the outline. To get the latter, you can use the ftbbox component
/// which is dedicated to this single task.
/// </para></summary>
/// <remarks><para>
/// Coordinates are relative to the glyph origin, using the y upwards convention.
/// </para><para>
/// If the glyph has been loaded with <see cref="LoadFlags.NoScale"/>, bbox_mode must be set to
/// <see cref="GlyphBBoxMode.Unscaled"/> to get unscaled font units in 26.6 pixel format. The value
/// <see cref="GlyphBBoxMode.Subpixels"/> is another name for this constant.
/// </para><para>
/// If the font is tricky and the glyph has been loaded with <see cref="LoadFlags.NoScale"/>, the resulting
/// CBox is meaningless. To get reasonable values for the CBox it is necessary to load the glyph at a large
/// ppem value (so that the hinting instructions can properly shift and scale the subglyphs), then extracting
/// the CBox which can be eventually converted back to font units.
/// </para><para>
/// Note that the maximum coordinates are exclusive, which means that one can compute the width and height of
/// the glyph image (be it in integer or 26.6 pixels) as:
/// </para><para>
/// <code>
/// width = bbox.xMax - bbox.xMin;
/// height = bbox.yMax - bbox.yMin;
/// </code>
/// </para><para>
/// Note also that for 26.6 coordinates, if bbox_mode is set to <see cref="GlyphBBoxMode.Gridfit"/>, the
/// coordinates will also be grid-fitted, which corresponds to:
/// </para><para>
/// <code>
/// bbox.xMin = FLOOR(bbox.xMin);
/// bbox.yMin = FLOOR(bbox.yMin);
/// bbox.xMax = CEILING(bbox.xMax);
/// bbox.yMax = CEILING(bbox.yMax);
/// </code>
/// </para><para>
/// To get the bbox in pixel coordinates, set bbox_mode to <see cref="GlyphBBoxMode.Truncate"/>.
/// </para><para>
/// To get the bbox in grid-fitted pixel coordinates, set bbox_mode to <see cref="GlyphBBoxMode.Pixels"/>.
/// </para></remarks>
/// <param name="mode">The mode which indicates how to interpret the returned bounding box values.</param>
/// <returns>
/// The glyph coordinate bounding box. Coordinates are expressed in 1/64th of pixels if it is grid-fitted.
/// </returns>
[CLSCompliant(false)]
public BBox GetCBox(GlyphBBoxMode mode)
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
BBox box;
FT.FT_Glyph_Get_CBox(Reference, mode, out box);
return box;
}
/// <summary>
/// Convert a given glyph object to a bitmap glyph object.
/// </summary>
/// <remarks><para>
/// This function does nothing if the glyph format isn't scalable.
/// </para><para>
/// The glyph image is translated with the origin vector before rendering.
/// </para><para>
/// The first parameter is a pointer to an <see cref="Glyph"/> handle, that will be replaced by this function
/// (with newly allocated data). Typically, you would use (omitting error handling):
/// </para><para>
/// --sample code ommitted--
/// </para></remarks>
/// <param name="renderMode">An enumeration that describes how the data is rendered.</param>
/// <param name="origin">
/// A pointer to a vector used to translate the glyph image before rendering. Can be 0 (if no translation). The
/// origin is expressed in 26.6 pixels.
/// </param>
/// <param name="destroy">
/// A boolean that indicates that the original glyph image should be destroyed by this function. It is never
/// destroyed in case of error.
/// </param>
public void ToBitmap(RenderMode renderMode, FTVector26Dot6 origin, bool destroy)
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
IntPtr glyphRef = Reference;
Error err = FT.FT_Glyph_To_Bitmap(ref glyphRef, renderMode, ref origin, destroy);
Reference = glyphRef;
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#region Glyph Stroker
/// <summary>
/// Stroke a given outline glyph object with a given stroker.
/// </summary>
/// <remarks>
/// The source glyph is untouched in case of error.
/// </remarks>
/// <param name="stroker">A stroker handle.</param>
/// <param name="destroy">A Boolean. If 1, the source glyph object is destroyed on success.</param>
/// <returns>New glyph handle.</returns>
public Glyph Stroke(Stroker stroker, bool destroy)
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
if (stroker == null)
throw new ArgumentNullException("stroker");
IntPtr sourceRef = Reference;
Error err = FT.FT_Glyph_Stroke(ref sourceRef, stroker.Reference, destroy);
if (destroy && err == Error.Ok)
{
//if FT_Glyph_Stroke destroys the glyph, keep the C# side synchronized.
disposed = true;
reference = IntPtr.Zero;
}
if (err != Error.Ok)
throw new FreeTypeException(err);
//check if the pointer didn't change.
if (sourceRef == Reference)
return this;
else
return new Glyph(sourceRef, Library);
}
/// <summary>
/// Stroke a given outline glyph object with a given stroker, but only return either its inside or outside
/// border.
/// </summary>
/// <remarks>
/// The source glyph is untouched in case of error.
/// </remarks>
/// <param name="stroker">A stroker handle.</param>
/// <param name="inside">A Boolean. If 1, return the inside border, otherwise the outside border.</param>
/// <param name="destroy">A Boolean. If 1, the source glyph object is destroyed on success.</param>
/// <returns>New glyph handle.</returns>
public Glyph StrokeBorder(Stroker stroker, bool inside, bool destroy)
{
if (disposed)
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
if (stroker == null)
throw new ArgumentNullException("stroker");
IntPtr sourceRef = Reference;
Error err = FT.FT_Glyph_StrokeBorder(ref sourceRef, stroker.Reference, inside, destroy);
if (destroy && err == Error.Ok)
{
//if FT_Glyph_Stroke destroys the glyph, keep the C# side synchronized.
disposed = true;
reference = IntPtr.Zero;
}
if (err != Error.Ok)
throw new FreeTypeException(err);
//check if the pointer didn't change.
if (sourceRef == Reference)
return this;
else
return new Glyph(sourceRef, Library);
}
#endregion
/// <summary>
/// Disposes the Glyph.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!disposed)
{
disposed = true;
FT.FT_Done_Glyph(reference);
// removes itself from the parent Library, with a check to prevent this from happening when Library is
// being disposed (Library disposes all it's children with a foreach loop, this causes an
// InvalidOperationException for modifying a collection during enumeration)
if (!parentLibrary.IsDisposed)
parentLibrary.RemoveChildGlyph(this);
reference = IntPtr.Zero;
}
}
#endregion
}
}

View File

@@ -0,0 +1,50 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// The mode how the values of <see cref="Glyph.GetCBox"/> are returned.
/// </summary>
[CLSCompliant(false)]
public enum GlyphBBoxMode : uint
{
/// <summary>Return unscaled font units.</summary>
Unscaled = 0,
/// <summary>Return unfitted 26.6 coordinates.</summary>
Subpixels = 0,
/// <summary>Return grid-fitted 26.6 coordinates.</summary>
Gridfit = 1,
/// <summary>Return coordinates in integer pixels.</summary>
Truncate = 2,
/// <summary>Return grid-fitted pixel coordinates.</summary>
Pixels = 3
}
}

View File

@@ -0,0 +1,67 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
namespace SharpFont
{
/// <summary>
/// An enumeration type used to describe the format of a given glyph image. Note that this version of FreeType only
/// supports two image formats, even though future font drivers will be able to register their own format.
/// </summary>
[CLSCompliant(false)]
public enum GlyphFormat : uint
{
/// <summary>
/// The value 0 is reserved.
/// </summary>
None = 0,
/// <summary>
/// The glyph image is a composite of several other images. This format is only used with
/// <see cref="LoadFlags.NoRecurse"/>, and is used to report compound glyphs (like accented characters).
/// </summary>
Composite = ('c' << 24 | 'o' << 16 | 'm' << 8 | 'p'),
/// <summary>
/// The glyph image is a bitmap, and can be described as an <see cref="FTBitmap"/>. You generally need to
/// access the bitmap field of the <see cref="GlyphSlot"/> structure to read it.
/// </summary>
Bitmap = ('b' << 24 | 'i' << 16 | 't' << 8 | 's'),
/// <summary>
/// The glyph image is a vectorial outline made of line segments and Bézier arcs; it can be described as an
/// <see cref="Outline"/>; you generally want to access the outline field of the <see cref="GlyphSlot"/>
/// structure to read it.
/// </summary>
Outline = ('o' << 24 | 'u' << 16 | 't' << 8 | 'l'),
/// <summary>
/// The glyph image is a vectorial path with no inside and outside contours. Some Type 1 fonts, like those in
/// the Hershey family, contain glyphs in this format. These are described as <see cref="Outline"/>, but
/// FreeType isn't currently capable of rendering them correctly.
/// </summary>
Plotter = ('p' << 24 | 'l' << 16 | 'o' << 8 | 't')
}
}

View File

@@ -0,0 +1,180 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// A structure used to model the metrics of a single glyph. The values are expressed in 26.6 fractional pixel
/// format; if the flag <see cref="LoadFlags.NoScale"/> has been used while loading the glyph, values are expressed
/// in font units instead.
/// </summary>
/// <remarks>
/// If not disabled with <see cref="LoadFlags.NoHinting"/>, the values represent dimensions of the hinted glyph (in
/// case hinting is applicable).
/// </remarks>
public sealed class GlyphMetrics
{
#region Fields
private IntPtr reference;
private GlyphMetricsRec rec;
#endregion
#region Constructors
internal GlyphMetrics(IntPtr reference)
{
Reference = reference;
}
internal GlyphMetrics(GlyphMetricsRec glyphMetInt)
{
this.rec = glyphMetInt;
}
#endregion
#region Properties
/// <summary>
/// Gets the glyph's width. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 Width
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.width);
}
}
/// <summary>
/// Gets the glyph's height. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 Height
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.height);
}
}
/// <summary>
/// Gets the left side bearing for horizontal layout. If getting metrics from a face loaded with
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 HorizontalBearingX
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.horiBearingX);
}
}
/// <summary>
/// Gets the top side bearing for horizontal layout. If getting metrics from a face loaded with
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 HorizontalBearingY
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.horiBearingY);
}
}
/// <summary>
/// Gets the advance width for horizontal layout. If getting metrics from a face loaded with
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 HorizontalAdvance
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.horiAdvance);
}
}
/// <summary>
/// Gets the left side bearing for vertical layout. If getting metrics from a face loaded with
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 VerticalBearingX
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.vertBearingX);
}
}
/// <summary>
/// Gets the top side bearing for vertical layout. Larger positive values mean further below the vertical glyph
/// origin. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 VerticalBearingY
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.vertBearingY);
}
}
/// <summary>
/// Gets the advance height for vertical layout. Positive values mean the glyph has a positive advance
/// downward. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
/// </summary>
public Fixed26Dot6 VerticalAdvance
{
get
{
return Fixed26Dot6.FromRawValue((int)rec.vertAdvance);
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<GlyphMetricsRec>(reference);
}
}
#endregion
}
}

View File

@@ -0,0 +1,475 @@
#region MIT License
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// FreeType root glyph slot class structure. A glyph slot is a container where individual glyphs can be loaded, be
/// they in outline or bitmap format.
/// </summary>
/// <remarks><para>
/// If <see cref="SharpFont.Face.LoadGlyph"/> is called with default flags (see <see cref="LoadFlags.Default"/>)
/// the glyph image is loaded in the glyph slot in its native format (e.g., an outline glyph for TrueType and Type
/// 1 formats).
/// </para><para>
/// This image can later be converted into a bitmap by calling <see cref="RenderGlyph"/>. This function finds the
/// current renderer for the native image's format, then invokes it.
/// </para><para>
/// The renderer is in charge of transforming the native image through the slot's face transformation fields, then
/// converting it into a bitmap that is returned in slot->bitmap.
/// </para><para>
/// Note that slot->bitmap_left and slot->bitmap_top are also used to specify the position of the bitmap
/// relative to the current pen position (e.g., coordinates (0,0) on the baseline). Of course, slot->format is
/// also changed to <see cref="GlyphFormat.Bitmap"/>.
/// </para></remarks>
/// <example>
/// <code>
/// FT_Pos origin_x = 0;
/// FT_Pos prev_rsb_delta = 0;
///
///
/// for all glyphs do
/// &lt;compute kern between current and previous glyph and add it to
/// `origin_x'&gt;
///
/// &lt;load glyph with `FT_Load_Glyph'&gt;
///
/// if ( prev_rsb_delta - face-&gt;glyph-&gt;lsb_delta &gt;= 32 )
/// origin_x -= 64;
/// else if ( prev_rsb_delta - face->glyph-&gt;lsb_delta &lt; -32 )
/// origin_x += 64;
///
/// prev_rsb_delta = face-&gt;glyph->rsb_delta;
///
/// &lt;save glyph image, or render glyph, or ...&gt;
///
/// origin_x += face-&gt;glyph-&gt;advance.x;
/// endfor
/// </code>
/// </example>
public sealed class GlyphSlot
{
#region Fields
private IntPtr reference;
private GlyphSlotRec rec;
private Face parentFace;
private Library parentLibrary;
#endregion
#region Constructors
internal GlyphSlot(IntPtr reference, Face parentFace, Library parentLibrary)
{
Reference = reference;
this.parentFace = parentFace;
this.parentLibrary = parentLibrary;
}
#endregion
#region Properties
/// <summary>
/// Gets a handle to the FreeType library instance this slot belongs to.
/// </summary>
public Library Library
{
get
{
return parentLibrary;
}
}
/// <summary>
/// Gets a handle to the parent face object.
/// </summary>
public Face Face
{
get
{
return parentFace;
}
}
/// <summary>
/// Gets the next <see cref="GlyphSlot"/>. In some cases (like some font tools), several glyph slots per face
/// object can be a good thing. As this is rare, the glyph slots are listed through a direct, single-linked
/// list using its next field.
/// </summary>
public GlyphSlot Next
{
get
{
return new GlyphSlot(rec.next, parentFace, parentLibrary);
}
}
/// <summary>
/// Gets a typeless pointer which is unused by the FreeType library or any of its drivers. It can be used by
/// client applications to link their own data to each glyph slot object.
/// </summary>
[Obsolete("Use the Tag property, Dispose callback not handled currently.")]
public Generic Generic
{
get
{
return new Generic(rec.generic);
}
}
/// <summary><para>
/// Gets the metrics of the last loaded glyph in the slot. The returned values depend on the last load flags
/// (see the <see cref="SharpFont.Face.LoadGlyph"/> API function) and can be expressed either in 26.6
/// fractional pixels or font units.
/// </para><para>
/// Note that even when the glyph image is transformed, the metrics are not.
/// </para></summary>
public GlyphMetrics Metrics
{
get
{
return new GlyphMetrics(rec.metrics);
}
}
/// <summary>
/// Gets the advance width of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless
/// <see cref="LoadFlags.LinearDesign"/> is set when loading the glyph. This field can be important to perform
/// correct WYSIWYG layout. Only relevant for outline glyphs.
/// </summary>
public Fixed16Dot16 LinearHorizontalAdvance
{
get
{
return Fixed16Dot16.FromRawValue((int)rec.linearHoriAdvance);
}
}
/// <summary>
/// Gets the advance height of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless
/// <see cref="LoadFlags.LinearDesign"/> is set when loading the glyph. This field can be important to perform
/// correct WYSIWYG layout. Only relevant for outline glyphs.
/// </summary>
public Fixed16Dot16 LinearVerticalAdvance
{
get
{
return Fixed16Dot16.FromRawValue((int)rec.linearVertAdvance);
}
}
/// <summary>
/// Gets the advance. This shorthand is, depending on <see cref="LoadFlags.IgnoreTransform"/>, the transformed
/// advance width for the glyph (in 26.6 fractional pixel format). As specified with
/// <see cref="LoadFlags.VerticalLayout"/>, it uses either the horiAdvance or the vertAdvance value of
/// metrics field.
/// </summary>
public FTVector26Dot6 Advance
{
get
{
return rec.advance;
}
}
/// <summary>
/// Gets the glyph format. This field indicates the format of the image contained in the glyph slot. Typically
/// <see cref="GlyphFormat.Bitmap"/>, <see cref="GlyphFormat.Outline"/>, or
/// <see cref="GlyphFormat.Composite"/>, but others are possible.
/// </summary>
[CLSCompliant(false)]
public GlyphFormat Format
{
get
{
return rec.format;
}
}
/// <summary>
/// Gets the bitmap. This field is used as a bitmap descriptor when the slot format is
/// <see cref="GlyphFormat.Bitmap"/>. Note that the address and content of the bitmap buffer can change between
/// calls of <see cref="SharpFont.Face.LoadGlyph"/> and a few other functions.
/// </summary>
public FTBitmap Bitmap
{
get
{
return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf<GlyphSlotRec>(Reference, "bitmap"), rec.bitmap, parentLibrary);
}
}
/// <summary>
/// Gets the bitmap's left bearing expressed in integer pixels. Of course, this is only valid if the format is
/// <see cref="GlyphFormat.Bitmap"/>.
/// </summary>
public int BitmapLeft
{
get
{
return rec.bitmap_left;
}
}
/// <summary>
/// Gets the bitmap's top bearing expressed in integer pixels. Remember that this is the distance from the
/// baseline to the top-most glyph scanline, upwards y coordinates being positive.
/// </summary>
public int BitmapTop
{
get
{
return rec.bitmap_top;
}
}
/// <summary>
/// Gets the outline descriptor for the current glyph image if its format is <see cref="GlyphFormat.Outline"/>.
/// Once a glyph is loaded, outline can be transformed, distorted, embolded, etc. However, it must not be
/// freed.
/// </summary>
public Outline Outline
{
get
{
return new Outline(PInvokeHelper.AbsoluteOffsetOf<GlyphSlotRec>(Reference, "outline"), rec.outline);
}
}
/// <summary>
/// Gets the number of subglyphs in a composite glyph. This field is only valid for the composite glyph format
/// that should normally only be loaded with the <see cref="LoadFlags.NoRecurse"/> flag. For now this is
/// internal to FreeType.
/// </summary>
[CLSCompliant(false)]
public uint SubglyphsCount
{
get
{
return rec.num_subglyphs;
}
}
/// <summary>
/// Gets an array of subglyph descriptors for composite glyphs. There are num_subglyphs elements in there.
/// Currently internal to FreeType.
/// </summary>
public SubGlyph[] Subglyphs
{
get
{
int count = (int)SubglyphsCount;
if (count == 0)
return null;
SubGlyph[] subglyphs = new SubGlyph[count];
IntPtr array = rec.subglyphs;
for (int i = 0; i < count; i++)
{
subglyphs[i] = new SubGlyph((IntPtr)(array.ToInt64() + IntPtr.Size * i));
}
return subglyphs;
}
}
/// <summary>
/// Gets the control data. Certain font drivers can also return the control data for a given glyph image (e.g.
/// TrueType bytecode, Type 1 charstrings, etc.). This field is a pointer to such data.
/// </summary>
public IntPtr ControlData
{
get
{
return rec.control_data;
}
}
/// <summary>
/// Gets the length in bytes of the control data.
/// </summary>
public int ControlLength
{
get
{
return (int)rec.control_len;
}
}
/// <summary>
/// Gets the difference between hinted and unhinted left side bearing while autohinting is active. Zero
/// otherwise.
/// </summary>
public int DeltaLsb
{
get
{
return (int)rec.lsb_delta;
}
}
/// <summary>
/// Gets the difference between hinted and unhinted right side bearing while autohinting is active. Zero
/// otherwise.
/// </summary>
public int DeltaRsb
{
get
{
return (int)rec.rsb_delta;
}
}
/// <summary>
/// Gets or sets an object used to identify this instance of <see cref="GlyphSlot"/>. This object will not be
/// modified or accessed internally.
/// </summary>
/// <remarks>
/// This is a replacement for FT_Generic in FreeType. If you are retrieving the same object multiple times
/// from functions, this object will not appear in new copies.
/// </remarks>
public object Tag { get; set; }
/// <summary>
/// Gets other data. Really wicked formats can use this pointer to present their own glyph image to client
/// applications. Note that the application needs to know about the image format.
/// </summary>
public IntPtr Other
{
get
{
return rec.other;
}
}
internal IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
rec = PInvokeHelper.PtrToStructure<GlyphSlotRec>(reference);
}
}
#endregion
#region Public Methods
#region Base Interface
/// <summary>
/// Convert a given glyph image to a bitmap. It does so by inspecting the glyph image format, finding the
/// relevant renderer, and invoking it.
/// </summary>
/// <param name="mode">This is the render mode used to render the glyph image into a bitmap.</param>
public void RenderGlyph(RenderMode mode)
{
Error err = FT.FT_Render_Glyph(Reference, mode);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
/// <summary>
/// Retrieve a description of a given subglyph. Only use it if <see cref="GlyphSlot.Format"/> is
/// <see cref="GlyphFormat.Composite"/>; an error is returned otherwise.
/// </summary>
/// <remarks>
/// The values of *p_arg1, *p_arg2, and *p_transform must be interpreted depending on the flags returned
/// in *p_flags. See the TrueType specification for details.
/// </remarks>
/// <param name="subIndex">
/// The index of the subglyph. Must be less than <see cref="GlyphSlot.SubglyphsCount"/>.
/// </param>
/// <param name="index">The glyph index of the subglyph.</param>
/// <param name="flags">The subglyph flags, see <see cref="SubGlyphFlags"/>.</param>
/// <param name="arg1">The subglyph's first argument (if any).</param>
/// <param name="arg2">The subglyph's second argument (if any).</param>
/// <param name="transform">The subglyph transformation (if any).</param>
[CLSCompliant(false)]
public void GetSubGlyphInfo(uint subIndex, out int index, out SubGlyphFlags flags, out int arg1, out int arg2, out FTMatrix transform)
{
Error err = FT.FT_Get_SubGlyph_Info(Reference, subIndex, out index, out flags, out arg1, out arg2, out transform);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#endregion
#region Glyph Management
/// <summary>
/// A function used to extract a glyph image from a slot. Note that the created <see cref="Glyph"/> object must
/// be released with <see cref="Glyph.Dispose()"/>.
/// </summary>
/// <returns>A handle to the glyph object.</returns>
public Glyph GetGlyph()
{
IntPtr glyphRef;
Error err = FT.FT_Get_Glyph(Reference, out glyphRef);
if (err != Error.Ok)
throw new FreeTypeException(err);
return new Glyph(glyphRef, Library);
}
#endregion
#region Bitmap Handling
/// <summary>
/// Make sure that a glyph slot owns slot->bitmap.
/// </summary>
/// <remarks>
/// This function is to be used in combination with <see cref="FTBitmap.Embolden"/>.
/// </remarks>
public void OwnBitmap()
{
Error err = FT.FT_GlyphSlot_Own_Bitmap(Reference);
if (err != Error.Ok)
throw new FreeTypeException(err);
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,96 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// The data exchange structure for the glyph-to-script-map property.
/// </summary>
public class GlyphToScriptMapProperty
{
private GlyphToScriptMapPropertyRec rec;
private Face face;
/// <summary>
/// Initializes a new instance of the <see cref="GlyphToScriptMapProperty"/> class.
/// </summary>
/// <param name="face">The face to apply the property to.</param>
public GlyphToScriptMapProperty(Face face)
{
Face = face;
}
internal GlyphToScriptMapProperty(GlyphToScriptMapPropertyRec rec, Face face)
{
this.rec = rec;
this.face = face;
}
/// <summary>
/// Gets or sets the associated face.
/// </summary>
public Face Face
{
get
{
return face;
}
set
{
face = value;
rec.face = face.Reference;
}
}
/// <summary>
/// Gets or sets the associated map.
/// </summary>
public IntPtr Map
{
get
{
return rec.map;
}
set
{
rec.map = value;
}
}
internal GlyphToScriptMapPropertyRec Rec
{
get
{
return rec;
}
}
}
}

View File

@@ -0,0 +1,97 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using SharpFont.Internal;
namespace SharpFont
{
/// <summary>
/// The data exchange structure for the increase-x-height property.
/// </summary>
public class IncreaseXHeightProperty
{
private IncreaseXHeightPropertyRec rec;
private Face face;
/// <summary>
/// Initializes a new instance of the <see cref="IncreaseXHeightProperty"/> class.
/// </summary>
/// <param name="face">The face to increase the X height of.</param>
public IncreaseXHeightProperty(Face face)
{
this.rec.face = face.Reference;
this.face = face;
}
internal IncreaseXHeightProperty(IncreaseXHeightPropertyRec rec, Face face)
{
this.rec = rec;
this.face = face;
}
/// <summary>
/// Gets or sets the associated face.
/// </summary>
public Face Face
{
get
{
return face;
}
set
{
face = value;
rec.face = face.Reference;
}
}
/// <summary>
/// Gets or sets the limit property.
/// </summary>
[CLSCompliant(false)]
public uint Limit
{
get
{
return rec.limit;
}
set
{
rec.limit = value;
}
}
internal IncreaseXHeightPropertyRec Rec
{
get
{
return rec;
}
}
}
}

View File

@@ -0,0 +1,38 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct BitmapGlyphRec
{
internal GlyphRec root;
internal int left;
internal int top;
internal BitmapRec bitmap;
}
}

View File

@@ -0,0 +1,48 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a Bitmap.
/// </summary>
/// <remarks>
/// Refer to <see cref="FTBitmap"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct BitmapRec
{
internal int rows;
internal int width;
internal int pitch;
internal IntPtr buffer;
internal short num_grays;
internal PixelMode pixel_mode;
internal byte palette_mode;
internal IntPtr palette;
}
}

View File

@@ -0,0 +1,52 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a BitmapSize.
/// </summary>
/// <remarks>
/// Refer to <see cref="BitmapSize"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct BitmapSizeRec
{
internal short height;
internal short width;
internal FT_Long size;
internal FT_Long x_ppem;
internal FT_Long y_ppem;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(BitmapSizeRec)); } }
}
}

View File

@@ -0,0 +1,46 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using SharpFont.TrueType;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a CharMap.
/// </summary>
/// <remarks>
/// Refer to <see cref="CharMap"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct CharMapRec
{
internal IntPtr face;
internal Encoding encoding;
internal PlatformId platform_id;
internal ushort encoding_id;
}
}

View File

@@ -0,0 +1,90 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a Face.
/// </summary>
/// <remarks>
/// Refer to <see cref="Face"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct FaceRec
{
internal FT_Long num_faces;
internal FT_Long face_index;
internal FT_Long face_flags;
internal FT_Long style_flags;
internal FT_Long num_glyphs;
internal IntPtr family_name;
internal IntPtr style_name;
internal int num_fixed_sizes;
internal IntPtr available_sizes;
internal int num_charmaps;
internal IntPtr charmaps;
internal GenericRec generic;
internal BBox bbox;
internal ushort units_per_EM;
internal short ascender;
internal short descender;
internal short height;
internal short max_advance_width;
internal short max_advance_height;
internal short underline_position;
internal short underline_thickness;
internal IntPtr glyph;
internal IntPtr size;
internal IntPtr charmap;
private IntPtr driver;
private IntPtr memory;
private IntPtr stream;
private IntPtr sizes_list;
private GenericRec autohint;
private IntPtr extensions;
private IntPtr @internal;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(FaceRec)); } }
}
}

View File

@@ -0,0 +1,36 @@
#region MIT License
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct GenericRec
{
internal IntPtr data;
internal IntPtr finalizer;
}
}

View File

@@ -0,0 +1,53 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a GlyphMetrics.
/// </summary>
/// <remarks>
/// Refer to <see cref="GlyphMetrics"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct GlyphMetricsRec
{
internal FT_Long width;
internal FT_Long height;
internal FT_Long horiBearingX;
internal FT_Long horiBearingY;
internal FT_Long horiAdvance;
internal FT_Long vertBearingX;
internal FT_Long vertBearingY;
internal FT_Long vertAdvance;
}
}

View File

@@ -0,0 +1,38 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct GlyphRec
{
internal IntPtr library;
private IntPtr clazz;
internal GlyphFormat format;
internal FTVector advance;
}
}

View File

@@ -0,0 +1,74 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
/// <summary>
/// Internally represents a GlyphSlot.
/// </summary>
/// <remarks>
/// Refer to <see cref="GlyphSlot"/> for FreeType documentation.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct GlyphSlotRec
{
internal IntPtr library;
internal IntPtr face;
internal IntPtr next;
internal uint reserved;
internal GenericRec generic;
internal GlyphMetricsRec metrics;
internal FT_Long linearHoriAdvance;
internal FT_Long linearVertAdvance;
internal FTVector26Dot6 advance;
internal GlyphFormat format;
internal BitmapRec bitmap;
internal int bitmap_left;
internal int bitmap_top;
internal OutlineRec outline;
internal uint num_subglyphs;
internal IntPtr subglyphs;
internal IntPtr control_data;
internal FT_Long control_len;
internal FT_Long lsb_delta;
internal FT_Long rsb_delta;
internal IntPtr other;
private IntPtr @internal;
}
}

View File

@@ -0,0 +1,36 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct GlyphToScriptMapPropertyRec
{
internal IntPtr face;
internal IntPtr map;
}
}

View File

@@ -0,0 +1,36 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct IncreaseXHeightPropertyRec
{
internal IntPtr face;
internal uint limit;
}
}

View File

@@ -0,0 +1,39 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ListNodeRec
{
internal IntPtr prev;
internal IntPtr next;
internal IntPtr data;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(ListNodeRec)); } }
}
}

View File

@@ -0,0 +1,36 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ListRec
{
internal IntPtr head;
internal IntPtr tail;
}
}

View File

@@ -0,0 +1,40 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct MemoryRec
{
internal IntPtr user;
internal AllocFunc alloc;
internal FreeFunc free;
internal ReallocFunc realloc;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(MemoryRec)); } }
}
}

View File

@@ -0,0 +1,50 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ModuleClassRec
{
internal uint module_flags;
internal FT_Long module_size;
[MarshalAs(UnmanagedType.LPStr)]
internal string module_name;
internal FT_Long module_version;
internal FT_Long module_requires;
internal IntPtr module_interface;
internal ModuleConstructor module_init;
internal ModuleDestructor module_done;
internal ModuleRequester get_interface;
}
}

View File

@@ -0,0 +1,33 @@
using System;
namespace SharpFont
{
/// <summary>
/// Provide a consistent means for using pointers as references.
/// </summary>
public abstract class NativeObject
{
private IntPtr reference;
/// <summary>
/// Construct a new NativeObject and assign the reference.
/// </summary>
/// <param name="reference"></param>
protected NativeObject(IntPtr reference)
{
this.reference = reference;
}
internal virtual IntPtr Reference
{
get
{
return reference;
}
set
{
reference = value;
}
}
}
}

View File

@@ -0,0 +1,58 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
/// <summary>
/// Struct NativeReference
/// </summary>
/// <typeparam name="T"></typeparam>
[StructLayout(LayoutKind.Sequential)]
public struct NativeReference<T> where T : NativeObject
{
private readonly IntPtr memoryPtr;
/// <summary>
/// Initializes a new instance of the <see cref="NativeReference{T}"/> struct.
/// </summary>
/// <param name="memoryPtr">The memory PTR.</param>
public NativeReference(IntPtr memoryPtr)
{
this.memoryPtr = memoryPtr;
}
/// <summary>
/// Performs an implicit conversion from <see cref="Memory"/> to <see cref="NativeReference{T}"/>.
/// </summary>
/// <param name="memory">The memory.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator NativeReference<T>(T memory)
{
return new NativeReference<T>(memory.Reference);
}
}
}

View File

@@ -0,0 +1,48 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct OpenArgsRec
{
internal OpenFlags flags;
internal IntPtr memory_base;
internal FT_Long memory_size;
[MarshalAs(UnmanagedType.LPStr)]
internal string pathname;
internal IntPtr stream;
internal IntPtr driver;
internal int num_params;
internal IntPtr @params;
}
}

View File

@@ -0,0 +1,43 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct OutlineFuncsRec
{
internal IntPtr moveTo;
internal IntPtr lineTo;
internal IntPtr conicTo;
internal IntPtr cubicTo;
internal int shift;
internal FT_Long delta;
}
}

View File

@@ -0,0 +1,36 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct OutlineGlyphRec
{
internal GlyphRec root;
internal OutlineRec outline;
}
}

View File

@@ -0,0 +1,42 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct OutlineRec
{
internal short n_contours;
internal short n_points;
internal IntPtr points;
internal IntPtr tags;
internal IntPtr contours;
internal OutlineFlags flags;
}
}

View File

@@ -0,0 +1,41 @@
#region MIT License
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
using FT_Long = System.IntPtr;
using FT_ULong = System.UIntPtr;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct ParameterRec
{
internal FT_ULong tag;
internal IntPtr data;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(ParameterRec)); } }
}
}

View File

@@ -0,0 +1,40 @@
#region MIT License
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct RasterFuncsRec
{
internal GlyphFormat glyph_format;
internal RasterNewFunc raster_new;
internal RasterResetFunc raster_reset;
internal RasterSetModeFunc raster_set_mode;
internal RasterRenderFunc raster_render;
internal RasterDoneFunc raster_done;
}
}

View File

@@ -0,0 +1,50 @@
#region MIT License
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
using System;
using System.Runtime.InteropServices;
namespace SharpFont.Internal
{
[StructLayout(LayoutKind.Sequential)]
internal struct RasterParamsRec
{
internal IntPtr target;
internal IntPtr source;
internal RasterFlags flags;
internal RasterSpanFunc gray_spans;
internal RasterSpanFunc black_spans;
[Obsolete("Unused")]
internal RasterBitTestFunc bit_test;
[Obsolete("Unused")]
internal RasterBitSetFunc bit_set;
internal IntPtr user;
internal BBox clip_box;
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(RasterParamsRec)); } }
}
}

Some files were not shown because too many files have changed in this diff Show More