diff --git a/SharpFont/.gitignore b/SharpFont/.gitignore new file mode 100644 index 000000000..18d28f582 --- /dev/null +++ b/SharpFont/.gitignore @@ -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 diff --git a/SharpFont/.gitmodules b/SharpFont/.gitmodules new file mode 100644 index 000000000..89d13d9b2 --- /dev/null +++ b/SharpFont/.gitmodules @@ -0,0 +1,4 @@ +[submodule "Dependencies"] + path = Dependencies + url = https://github.com/Robmaister/SharpFont.Dependencies.git + ignore = dirty diff --git a/SharpFont/Dependencies/freetype2/2.5.4-alldeps/README.md b/SharpFont/Dependencies/freetype2/2.5.4-alldeps/README.md new file mode 100644 index 000000000..205b22174 --- /dev/null +++ b/SharpFont/Dependencies/freetype2/2.5.4-alldeps/README.md @@ -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. diff --git a/SharpFont/Dependencies/freetype2/2.5.4-alldeps/patches/fttypes-h-win32.patch b/SharpFont/Dependencies/freetype2/2.5.4-alldeps/patches/fttypes-h-win32.patch new file mode 100644 index 000000000..20bfc2590 --- /dev/null +++ b/SharpFont/Dependencies/freetype2/2.5.4-alldeps/patches/fttypes-h-win32.patch @@ -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 @@ + /* */ + /* A typedef for signed long. */ + /* */ ++#ifdef _WIN32 ++ typedef signed __int64 FT_Long; ++#else + typedef signed long FT_Long; ++#endif + +- + /*************************************************************************/ + /* */ + /* */ +@@ -250,9 +253,12 @@ + /* */ + /* A typedef for unsigned long. */ + /* */ ++#ifdef _WIN32 ++ typedef unsigned __int64 FT_ULong; ++#else + typedef unsigned long FT_ULong; ++#endif + +- + /*************************************************************************/ + /* */ + /* */ +@@ -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 + +- + /*************************************************************************/ + /* */ + /* */ +@@ -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 + +- + /*************************************************************************/ + /* */ + /* */ diff --git a/SharpFont/Dependencies/freetype2/2.5.5-alldeps/README.md b/SharpFont/Dependencies/freetype2/2.5.5-alldeps/README.md new file mode 100644 index 000000000..88b40a02b --- /dev/null +++ b/SharpFont/Dependencies/freetype2/2.5.5-alldeps/README.md @@ -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. \ No newline at end of file diff --git a/SharpFont/Dependencies/freetype2/FTL.TXT b/SharpFont/Dependencies/freetype2/FTL.TXT new file mode 100644 index 000000000..bbaba33f4 --- /dev/null +++ b/SharpFont/Dependencies/freetype2/FTL.TXT @@ -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 © The FreeType + Project (www.freetype.org). All rights reserved. + """ + + Please replace 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 --- diff --git a/SharpFont/Dependencies/freetype2/README.md b/SharpFont/Dependencies/freetype2/README.md new file mode 100644 index 000000000..44673889a --- /dev/null +++ b/SharpFont/Dependencies/freetype2/README.md @@ -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 diff --git a/SharpFont/Dependencies/freetype2/win64.patch b/SharpFont/Dependencies/freetype2/win64.patch new file mode 100644 index 000000000..a7da056a2 --- /dev/null +++ b/SharpFont/Dependencies/freetype2/win64.patch @@ -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 + /* */ + /* 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 + /* */ + /* 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 + + + /*************************************************************************/ diff --git a/SharpFont/LICENSE b/SharpFont/LICENSE new file mode 100644 index 000000000..9ee67879e --- /dev/null +++ b/SharpFont/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2012-2016 Robert Rouhani + +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. \ No newline at end of file diff --git a/SharpFont/Makefile b/SharpFont/Makefile new file mode 100644 index 000000000..55320feea --- /dev/null +++ b/SharpFont/Makefile @@ -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 diff --git a/SharpFont/README.md b/SharpFont/README.md new file mode 100644 index 000000000..8054930b6 --- /dev/null +++ b/SharpFont/README.md @@ -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 + +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 diff --git a/SharpFont/Source/.editorconfig b/SharpFont/Source/.editorconfig new file mode 100644 index 000000000..54d45caba --- /dev/null +++ b/SharpFont/Source/.editorconfig @@ -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 diff --git a/SharpFont/Source/Settings.StyleCop b/SharpFont/Source/Settings.StyleCop new file mode 100644 index 000000000..2c2aa1c55 --- /dev/null +++ b/SharpFont/Source/Settings.StyleCop @@ -0,0 +1,97 @@ + + + + + + Rec\.cs$ + Marhsaler\.cs$ + + + + + + + + + + False + + + + + + + + + + False + + + + + + + + + + False + + + + + False + + + + + + + + + + False + + + + + + + + + + False + + + + + False + + + + + True + True + + + + + + + False + + + + + + + + + + False + + + + + + + \ No newline at end of file diff --git a/SharpFont/Source/SharpFont.dll.config b/SharpFont/Source/SharpFont.dll.config new file mode 100644 index 000000000..c216adda3 --- /dev/null +++ b/SharpFont/Source/SharpFont.dll.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/SharpFont/Source/SharpFont.sln b/SharpFont/Source/SharpFont.sln new file mode 100644 index 000000000..7d3f623da --- /dev/null +++ b/SharpFont/Source/SharpFont.sln @@ -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 diff --git a/SharpFont/Source/SharpFont.snk b/SharpFont/Source/SharpFont.snk new file mode 100644 index 000000000..552a3332a Binary files /dev/null and b/SharpFont/Source/SharpFont.snk differ diff --git a/SharpFont/Source/SharpFont/SharpFont.csproj b/SharpFont/Source/SharpFont/SharpFont.csproj new file mode 100644 index 000000000..7aef6745f --- /dev/null +++ b/SharpFont/Source/SharpFont/SharpFont.csproj @@ -0,0 +1,65 @@ + + + + Release + AnyCPU + 8.0.30703 + 2.0 + {C293DB32-FA42-486D-B128-5A12522FAE4E} + Library + Properties + SharpFont + SharpFont + v4.5 + 512 + + + true + full + false + ..\..\Binaries\SharpFont\Debug\ + TRACE;DEBUG + prompt + 4 + bin\Debug\SharpFont.xml + true + AnyCPU + + + pdbonly + true + ..\..\Binaries\SharpFont\Release\ + TRACE + prompt + 4 + bin\Release\SharpFont.xml + true + AnyCPU + + + true + + + ..\SharpFont.snk + + + + + + + + PreserveNewest + + + + + + + + diff --git a/SharpFont/Source/SharpFontShared/AutoHinterScript.cs b/SharpFont/Source/SharpFontShared/AutoHinterScript.cs new file mode 100644 index 000000000..71bc7448f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/AutoHinterScript.cs @@ -0,0 +1,138 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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. + /// + public enum AutoHinterScript + { + /// + /// Don't auto-hint this glyph. + /// + None = 0, + + /// + /// 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. + /// + /// + /// By default, characters from the following Unicode ranges are assigned to this submodule. + /// + /// 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 + /// + Latin = 1, + + /// + /// Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old Vietnamese, and some other scripts. + /// + /// + /// By default, characters from the following Unicode ranges are assigned to this submodule. + /// + /// 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 + /// + Cjk = 2, + + /// + /// Apply the indic auto-hinter, covering all major scripts from the Indian sub-continent and some other + /// related scripts like Thai, Lao, or Tibetan. + /// + /// + /// By default, characters from the following Unicode ranges are assigned to this submodule. + /// + /// 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 + /// + /// Note that currently Indic support is rudimentary only, missing blue zone support. + /// + Indic = 3 + } +} diff --git a/SharpFont/Source/SharpFontShared/BBox.cs b/SharpFont/Source/SharpFontShared/BBox.cs new file mode 100644 index 000000000..50df52ccc --- /dev/null +++ b/SharpFont/Source/SharpFontShared/BBox.cs @@ -0,0 +1,190 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// A structure used to hold an outline's bounding box, i.e., the + /// coordinates of its extrema in the horizontal and vertical directions. + /// + [StructLayout(LayoutKind.Sequential)] + public struct BBox : IEquatable + { + #region Fields + + private FT_Long xMin, yMin; + private FT_Long xMax, yMax; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// The left bound. + /// The bottom bound. + /// The right bound. + /// The upper bound. + 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 + + /// + /// Gets the horizontal minimum (left-most). + /// + public int Left + { + get + { + return (int)xMin; + } + } + + /// + /// Gets the vertical minimum (bottom-most). + /// + public int Bottom + { + get + { + return (int)yMin; + } + } + + /// + /// Gets the horizontal maximum (right-most). + /// + public int Right + { + get + { + return (int)xMax; + } + } + + /// + /// Gets the vertical maximum (top-most). + /// + public int Top + { + get + { + return (int)yMax; + } + } + + #endregion + + #region Operators + + /// + /// Compares two instances of for equality. + /// + /// A . + /// Another . + /// A value indicating equality. + public static bool operator ==(BBox left, BBox right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// A . + /// Another . + /// A value indicating inequality. + public static bool operator !=(BBox left, BBox right) + { + return !left.Equals(right); + } + + #endregion + + #region Methods + + /// + /// Compares this instance of to another for equality. + /// + /// A . + /// A value indicating equality. + public bool Equals(BBox other) + { + return + xMin == other.xMin && + yMin == other.yMin && + xMax == other.xMax && + yMax == other.yMax; + } + + /// + /// Compares this instance of to an object for equality. + /// + /// An object. + /// A value indicating equality. + public override bool Equals(object obj) + { + if (obj is BBox) + return this.Equals((BBox)obj); + + return false; + } + + /// + /// Gets a unique hash code for this instance. + /// + /// A hash code. + public override int GetHashCode() + { + //TODO better hash algo + return xMin.GetHashCode() ^ yMin.GetHashCode() ^ xMax.GetHashCode() ^ yMax.GetHashCode(); + } + + /// + /// Gets a string that represents this instance. + /// + /// A string representation of this instance. + public override string ToString() + { + return "Min: (" + (int)xMin + ", " + (int)yMin + "), Max: (" + (int)xMax + ", " + (int)yMax + ")"; + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Bdf/Internal/PropertyRec.cs b/SharpFont/Source/SharpFontShared/Bdf/Internal/PropertyRec.cs new file mode 100644 index 000000000..e62293bd0 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Bdf/Internal/PropertyRec.cs @@ -0,0 +1,45 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Bdf/Property.cs b/SharpFont/Source/SharpFontShared/Bdf/Property.cs new file mode 100644 index 000000000..35f3f3b84 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Bdf/Property.cs @@ -0,0 +1,121 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// This structure models a given BDF/PCF property. + /// + public class Property + { + #region Fields + + private IntPtr reference; + private PropertyRec rec; + + #endregion + + #region Constructors + + internal Property(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the property type. + /// + public PropertyType Type + { + get + { + return rec.type; + } + } + + /// + /// Gets the atom string, if type is . + /// + 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); + } + } + + /// + /// Gets a signed integer, if type is . + /// + public int Integer + { + get + { + return rec.integer; + } + } + + /// + /// Gets an unsigned integer, if type is . + /// + [CLSCompliant(false)] + public uint Cardinal + { + get + { + return rec.cardinal; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Bdf/PropertyType.cs b/SharpFont/Source/SharpFontShared/Bdf/PropertyType.cs new file mode 100644 index 000000000..be90669d5 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Bdf/PropertyType.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of BDF property types. + /// + public enum PropertyType + { + /// Value 0 is used to indicate a missing property. + None = 0, + + /// Property is a string atom. + Atom = 1, + + /// Property is a 32-bit signed integer. + Integer = 2, + + /// Property is a 32-bit unsigned integer. + Cardinal = 3 + } +} diff --git a/SharpFont/Source/SharpFontShared/BitmapGlyph.cs b/SharpFont/Source/SharpFontShared/BitmapGlyph.cs new file mode 100644 index 000000000..98c399ceb --- /dev/null +++ b/SharpFont/Source/SharpFontShared/BitmapGlyph.cs @@ -0,0 +1,207 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// A structure used for bitmap glyph images. This really is a ‘sub-class’ of . + /// + /// + /// You can typecast an to if you have ‘ == + /// ’. This lets you access the bitmap's contents easily. + /// + /// The corresponding pixel buffer is always owned by and is thus created and destroyed + /// with it. + /// + 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. + } + + /// + /// Finalizes an instance of the class. + /// + ~BitmapGlyph() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return original.IsDisposed; + } + } + + /// + /// Gets the root fields. + /// + public Glyph Root + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Root", "Cannot access a disposed object."); + + return original; + } + } + + /// + /// Gets the left-side bearing, i.e., the horizontal distance from the current pen position to the left border + /// of the glyph bitmap. + /// + public int Left + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Left", "Cannot access a disposed object."); + + return rec.left; + } + } + + /// + /// 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! + /// + public int Top + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Top", "Cannot access a disposed object."); + + return rec.top; + } + } + + /// + /// Gets a descriptor for the bitmap. + /// + public FTBitmap Bitmap + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object."); + + return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf(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(original.Reference); + } + } + + #endregion + + #region Operators + + /// + /// Casts a back up to a . The eqivalent of + /// . + /// + /// A . + /// A . + public static implicit operator Glyph(BitmapGlyph g) + { + return g.original; + } + + #endregion + + #region Methods + + /// + /// A CLS-compliant version of the implicit cast to . + /// + /// A . + public Glyph ToGlyph() + { + return (Glyph)this; + } + + /// + /// Disposes an instance of the class. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposing) + { + original.Dispose(); + original = null; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/BitmapSize.cs b/SharpFont/Source/SharpFontShared/BitmapSize.cs new file mode 100644 index 000000000..ff2fdbc72 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/BitmapSize.cs @@ -0,0 +1,145 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// 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 field of + /// . + /// + /// + /// 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. + /// + /// TrueType embedded bitmaps: ‘size’, ‘width’, and ‘height’ values are not + /// contained in the bitmap strike itself. They are computed from the + /// global font parameters. + /// + 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 + + /// + /// Gets the vertical distance, in pixels, between two consecutive + /// baselines. It is always positive. + /// + public short Height + { + get + { + return rec.height; + } + } + + /// + /// Gets the average width, in pixels, of all glyphs in the strike. + /// + public short Width + { + get + { + return rec.width; + } + } + + /// + /// Gets the nominal size of the strike in 26.6 fractional points. This + /// field is not very useful. + /// + public Fixed26Dot6 Size + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.size); + } + } + + /// + /// Gets the horizontal ppem (nominal width) in 26.6 fractional pixels. + /// + public Fixed26Dot6 NominalWidth + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.x_ppem); + } + } + + /// + /// Gets the vertical ppem (nominal height) in 26.6 fractional pixels. + /// + public Fixed26Dot6 NominalHeight + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.y_ppem); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/CMapCache.cs b/SharpFont/Source/SharpFontShared/Cache/CMapCache.cs new file mode 100644 index 000000000..f4dc0ef20 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/CMapCache.cs @@ -0,0 +1,100 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An opaque handle used to model a charmap cache. This cache is to hold character codes -> glyph indices + /// mappings. + /// + public class CMapCache + { + #region Fields + + private IntPtr reference; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// + /// Like all other caches, this one will be destroyed with the cache manager. + /// + /// A handle to the cache manager. + 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 + + /// + /// Translate a character code into a glyph index, using the charmap cache. + /// + /// The source face ID. + /// + /// The index of the charmap in the source face. Any negative value means to use the cache 's + /// default charmap. + /// + /// The character code (in the corresponding charmap). + /// Glyph index. 0 means ‘no glyph’. + [CLSCompliant(false)] + public uint Lookup(IntPtr faceId, int cmapIndex, uint charCode) + { + return FT.FTC_CMapCache_Lookup(Reference, faceId, cmapIndex, charCode); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/FaceRequester.cs b/SharpFont/Source/SharpFontShared/Cache/FaceRequester.cs new file mode 100644 index 000000000..5081858f7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/FaceRequester.cs @@ -0,0 +1,47 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// A callback function provided by client applications. It is used by the cache manager to translate a given + /// FTC_FaceID into a new valid object, on demand. + /// + /// + /// The third parameter ‘req_data’ is the same as the one passed by the client when + /// is called. + /// + /// The face requester should not perform funny things on the returned face object, like creating a new + /// for it, or setting a transformation through ! + /// + /// The face ID to resolve. + /// A handle to a FreeType library object. + /// Application-provided request data (see note below). + /// A new handle. + /// FreeType error code. 0 means success. + public delegate Error FaceRequester(IntPtr faceId, IntPtr library, IntPtr requestData, out IntPtr aface); +} diff --git a/SharpFont/Source/SharpFontShared/Cache/ImageCache.cs b/SharpFont/Source/SharpFontShared/Cache/ImageCache.cs new file mode 100644 index 000000000..f581b31e8 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/ImageCache.cs @@ -0,0 +1,173 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A handle to an glyph image cache object. They are designed to hold many distinct glyph images while not + /// exceeding a certain memory threshold. + /// + public class ImageCache + { + #region Fields + + private IntPtr reference; + private Manager parentManager; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The parent manager for the image cache. + 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 + + /// + /// Retrieve a given glyph image from a glyph image cache. + /// + /// + /// 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 and modify the new one. + /// + /// 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 ) will + /// always be kept in the cache until you call to ‘release’ it. + /// + /// If ‘node’ is NULL, the cache node is left unchanged, which means that the + /// 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! + /// + /// A pointer to a glyph image type descriptor. + /// The glyph index to retrieve. + /// + /// Used to return the address of of the corresponding cache node after incrementing its reference count (see + /// note below). + /// + /// The corresponding object. 0 in case of failure. + [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); + } + + /// + /// A variant of that uses a to specify the face ID and its + /// size. + /// + /// + /// 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 and modify the new one. + /// + /// 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 ) will + /// always be kept in the cache until you call to ‘release’ it. + /// + /// If ‘node’ is NULL, the cache node is left unchanged, which means that the + /// 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! + /// + /// Calls to and friends have no effect on cached glyphs; you should always use + /// the FreeType cache API instead. + /// + /// A pointer to a scaler descriptor. + /// The corresponding load flags. + /// The glyph index to retrieve. + /// + /// Used to return the address of of the corresponding cache node after incrementing its reference count (see + /// note below). + /// + /// The corresponding object. 0 in case of failure. + [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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/ImageType.cs b/SharpFont/Source/SharpFontShared/Cache/ImageType.cs new file mode 100644 index 000000000..f9c0e9016 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/ImageType.cs @@ -0,0 +1,116 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A structure used to model the type of images in a glyph cache. + /// + public class ImageType + { + #region Fields + + private IntPtr reference; + private ImageTypeRec rec; + + #endregion + + #region Constructors + + internal ImageType(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the face ID. + /// + public IntPtr FaceId + { + get + { + return rec.face_id; + } + } + + /// + /// Gets the width in pixels. + /// + public int Width + { + get + { + return rec.width; + } + } + + /// + /// Gets the height in pixels. + /// + public int Height + { + get + { + return rec.height; + } + } + + /// + /// Gets the load flags, as in + /// + [CLSCompliant(false)] + public LoadFlags Flags + { + get + { + return rec.flags; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/CMapCacheRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/CMapCacheRec.cs new file mode 100644 index 000000000..fc170624a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/CMapCacheRec.cs @@ -0,0 +1,34 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 + { + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/ImageCacheRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/ImageCacheRec.cs new file mode 100644 index 000000000..97bbd7684 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/ImageCacheRec.cs @@ -0,0 +1,34 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 + { + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/ImageTypeRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/ImageTypeRec.cs new file mode 100644 index 000000000..9da34c39c --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/ImageTypeRec.cs @@ -0,0 +1,38 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/ManagerRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/ManagerRec.cs new file mode 100644 index 000000000..aaa02a762 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/ManagerRec.cs @@ -0,0 +1,34 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 + { + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/NodeRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/NodeRec.cs new file mode 100644 index 000000000..4f26d1145 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/NodeRec.cs @@ -0,0 +1,34 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 + { + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/SBitCacheRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/SBitCacheRec.cs new file mode 100644 index 000000000..9b95b407f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/SBitCacheRec.cs @@ -0,0 +1,34 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 + { + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/SBitRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/SBitRec.cs new file mode 100644 index 000000000..b631065cd --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/SBitRec.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Internal/ScalerRec.cs b/SharpFont/Source/SharpFontShared/Cache/Internal/ScalerRec.cs new file mode 100644 index 000000000..afc4a2197 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Internal/ScalerRec.cs @@ -0,0 +1,40 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Manager.cs b/SharpFont/Source/SharpFontShared/Cache/Manager.cs new file mode 100644 index 000000000..82455004f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Manager.cs @@ -0,0 +1,274 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// This object corresponds to one instance of the cache-subsystem. It is used to cache one or more + /// objects, along with corresponding objects. + /// + /// The manager intentionally limits the total number of opened and objects + /// to control memory usage. See the ‘max_faces’ and ‘max_sizes’ parameters of + /// . + /// + /// The manager is also used to cache ‘nodes’ of various types while limiting their total memory usage. + /// + /// 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. + /// + public sealed class Manager : IDisposable + { + #region Fields + + private IntPtr reference; + private Library parentLibrary; + + private bool disposed; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the Manager class. + /// + /// The parent FreeType library handle to use. + /// + /// Maximum number of opened objects managed by this cache instance. Use 0 for defaults. + /// + /// + /// Maximum number of opened objects managed by this cache instance. Use 0 for defaults. + /// + /// + /// Maximum number of bytes to use for cached data nodes. Use 0 for defaults. Note that this value does not + /// account for managed and objects. + /// + /// + /// An application-provided callback used to translate face IDs into real objects. + /// + /// + /// A generic pointer that is passed to the requester each time it is called (see ). + /// + [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); + } + + /// + /// Finalizes an instance of the Manager class. + /// + ~Manager() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + 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 + + /// + /// Empty a given cache manager. This simply gets rid of all the currently cached and + /// objects within the manager. + /// + public void Reset() + { + if (disposed) + throw new ObjectDisposedException("Manager", "Cannot access a disposed object."); + + FT.FTC_Manager_Reset(Reference); + } + + /// + /// Retrieve the object that corresponds to a given face ID through a cache manager. + /// + /// + /// The returned object is always owned by the manager. You should never try to discard it + /// yourself. + /// + /// The object doesn't necessarily have a current size object (i.e., + /// can be 0). If you need a specific ‘font size’, use instead. + /// + /// Never change the face's transformation matrix (i.e., never call the + /// function) on a returned face! If you need to transform glyphs, do it yourself after glyph loading. + /// + /// 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. + /// + /// If a lookup fails with the cache has already been completely flushed, and + /// still no memory was available for the operation. + /// + /// The ID of the face object. + /// A handle to the face object. + 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); + } + + /// + /// Retrieve the object that corresponds to a given pointer through a + /// cache manager. + /// + /// + /// The returned object is always owned by the/ manager. You should never try to discard + /// it by yourself. + /// + /// You can access the parent object simply as if you need it. + /// Note that this object is also owned by the manager. + /// + /// 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. + /// + /// If a lookup fails with the cache has already been completely flushed, and + /// still no memory is available for the operation. + /// + /// A scaler handle. + /// A handle to the size object. + 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); + } + + /// + /// 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. + /// + /// + /// This function flushes all nodes from the cache corresponding to this ‘faceID’, with the + /// exception of nodes with a non-null reference count. + /// + /// 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. + /// + /// The FTC_FaceID to be removed. + 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 + + /// + /// Disposes the Manager. + /// + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Node.cs b/SharpFont/Source/SharpFontShared/Cache/Node.cs new file mode 100644 index 000000000..a3f03d60c --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Node.cs @@ -0,0 +1,87 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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. + /// + /// 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. + /// + /// + /// + /// + 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 + + /// + /// Decrement a cache node's internal reference count. When the count reaches 0, it is not destroyed but + /// becomes eligible for subsequent cache flushes. + /// + /// The cache manager handle. + public void Unref(Manager manager) + { + FT.FTC_Node_Unref(Reference, manager.Reference); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/SBit.cs b/SharpFont/Source/SharpFontShared/Cache/SBit.cs new file mode 100644 index 000000000..706de0491 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/SBit.cs @@ -0,0 +1,185 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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 + /// . + /// + public class SBit + { + #region Fields + + private IntPtr reference; + private SBitRec rec; + + #endregion + + #region Constructors + + internal SBit(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the bitmap width in pixels. + /// + public byte Width + { + get + { + return rec.width; + } + } + + /// + /// Gets the bitmap height in pixels. + /// + public byte Height + { + get + { + return rec.height; + } + } + + /// + /// Gets the horizontal distance from the pen position to the left bitmap border (a.k.a. ‘left side bearing’, + /// or ‘lsb’). + /// + public byte Left + { + get + { + return rec.left; + } + } + + /// + /// 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. + /// + public byte Top + { + get + { + return rec.top; + } + } + + /// + /// Gets the format of the glyph bitmap (monochrome or gray). + /// + public byte Format + { + get + { + return rec.format; + } + } + + /// + /// Gets the maximum gray level value (in the range 1 to 255). + /// + public byte MaxGrays + { + get + { + return rec.max_grays; + } + } + + /// + /// Gets the number of bytes per bitmap line. May be positive or negative. + /// + public short Pitch + { + get + { + return rec.pitch; + } + } + + /// + /// Gets the horizontal advance width in pixels. + /// + public byte AdvanceX + { + get + { + return rec.xadvance; + } + } + + /// + /// Gets the vertical advance height in pixels. + /// + public byte AdvanceY + { + get + { + return rec.yadvance; + } + } + + /// + /// Gets a pointer to the bitmap pixels. + /// + public IntPtr Buffer + { + get + { + return rec.buffer; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/SBitCache.cs b/SharpFont/Source/SharpFontShared/Cache/SBitCache.cs new file mode 100644 index 000000000..b53436a71 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/SBitCache.cs @@ -0,0 +1,173 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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 + /// . + /// + public class SBitCache + { + #region Fields + + private IntPtr reference; + private Manager parentManager; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// A handle to the source cache manager. + 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 + + /// + /// Look up a given small glyph bitmap in a given sbit cache and ‘lock’ it to prevent its flushing from the + /// cache until needed. + /// + /// + /// 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. + /// + /// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap. + /// + /// 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 to ‘release’ it. + /// + /// 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! + /// + /// A pointer to the glyph image type descriptor. + /// The glyph index. + /// + /// Used to return the address of of the corresponding cache node after incrementing its reference count (see + /// note below). + /// + /// A handle to a small bitmap descriptor. + [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); + } + + /// + /// A variant of that uses a to specify the face ID and its + /// size. + /// + /// + /// 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. + /// + /// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap. + /// + /// 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 to ‘release’ it. + /// + /// 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! + /// + /// A pointer to the scaler descriptor. + /// The corresponding load flags. + /// The glyph index. + /// + /// Used to return the address of of the corresponding cache node after incrementing its reference count (see + /// note below). + /// + /// A handle to a small bitmap descriptor. + [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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Cache/Scaler.cs b/SharpFont/Source/SharpFontShared/Cache/Scaler.cs new file mode 100644 index 000000000..17c5a795a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cache/Scaler.cs @@ -0,0 +1,146 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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 +{ + /// + /// A structure used to describe a given character size in either pixels or points to the cache manager. + /// + /// + /// This type is mainly used to retrieve objects through the cache manager. + /// + /// + public class Scaler + { + #region Fields + + private IntPtr reference; + private ScalerRec rec; + + #endregion + + #region Constructors + + internal Scaler(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the source face ID. + /// + public IntPtr FaceId + { + get + { + return rec.face_id; + } + } + + /// + /// Gets the character width. + /// + [CLSCompliant(false)] + public uint Width + { + get + { + return rec.width; + } + } + + /// + /// Gets the character height. + /// + [CLSCompliant(false)] + public uint Height + { + get + { + return rec.height; + } + } + + /// + /// 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. + /// + public bool Pixel + { + get + { + return rec.pixel == 1; + } + } + + /// + /// Gets the horizontal resolution in dpi; only used when ‘pixel’ is value 0. + /// + [CLSCompliant(false)] + public uint ResolutionX + { + get + { + return rec.x_res; + } + } + + /// + /// Gets the vertical resolution in dpi; only used when ‘pixel’ is value 0. + /// + [CLSCompliant(false)] + public uint ResolutionY + { + get + { + return rec.y_res; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Cff/HintingEngine.cs b/SharpFont/Source/SharpFontShared/Cff/HintingEngine.cs new file mode 100644 index 000000000..1370df9d0 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Cff/HintingEngine.cs @@ -0,0 +1,40 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of constants used for the hinting-engine property to select the hinting engine for CFF fonts. + /// + public enum HintingEngine + { + /// Use the old FreeType hinting engine. + FreeType = 0, + + /// Use the hinting engine contributed by Adobe. + Adobe = 1 + } +} diff --git a/SharpFont/Source/SharpFontShared/CharMap.cs b/SharpFont/Source/SharpFontShared/CharMap.cs new file mode 100644 index 000000000..6d4c78b1e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/CharMap.cs @@ -0,0 +1,170 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The base charmap structure. + /// + 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 + + /// + /// Gets a handle to the parent face object. + /// + public Face Face + { + get + { + return parentFace; + } + } + + /// + /// Gets an tag identifying the charmap. Use this with + /// . + /// + [CLSCompliant(false)] + public Encoding Encoding + { + get + { + return rec.encoding; + } + } + + /// + /// 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. + /// + [CLSCompliant(false)] + public PlatformId PlatformId + { + get + { + return rec.platform_id; + } + } + + /// + /// Gets a platform specific encoding number. This also comes from the TrueType specification and should be + /// emulated similarly. + /// + [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(reference); + } + } + + #endregion + + #region Methods + + #region Base Interface + + /// + /// Retrieve index of a given charmap. + /// + /// The index into the array of character maps within the face to which ‘charmap’ belongs. + public int GetCharmapIndex() + { + return FT.FT_Get_Charmap_Index(Reference); + } + + #endregion + + #region TrueType Tables + + /// + /// Return TrueType/sfnt specific cmap language ID. Definitions of language ID values are in + /// ‘freetype/ttnameid.h’. + /// + /// + /// The language ID of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, just return 0 as the + /// default value. + /// + [CLSCompliant(false)] + public uint GetCMapLanguageId() + { + return FT.FT_Get_CMap_Language_ID(Reference); + } + + /// + /// Return TrueType/sfnt specific cmap format. + /// + /// The format of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, return -1. + public int GetCMapFormat() + { + return FT.FT_Get_CMap_Format(Reference); + } + + #endregion + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/ClassicKernValidationFlags.cs b/SharpFont/Source/SharpFontShared/ClassicKernValidationFlags.cs new file mode 100644 index 000000000..27fe3a079 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/ClassicKernValidationFlags.cs @@ -0,0 +1,47 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants used with to indicate the classic kern + /// dialect or dialects. If the selected type doesn't fit, regards the table + /// as invalid. + /// + [Flags] + [CLSCompliant(false)] + public enum ClassicKernValidationFlags : uint + { + /// Handle the ‘kern’ table as a classic Microsoft kern table. + Microsoft = 0x4000 << 0, + + /// Handle the ‘kern’ table as a classic Apple kern table. + Apple = 0x4000 << 1, + + /// Handle the ‘kern’ as either classic Apple or Microsoft kern table. + All = Microsoft | Apple + } +} diff --git a/SharpFont/Source/SharpFontShared/Data.cs b/SharpFont/Source/SharpFontShared/Data.cs new file mode 100644 index 000000000..712b757ca --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Data.cs @@ -0,0 +1,89 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// Read-only binary data represented as a pointer and a length. + /// + public sealed class Data + { + #region Fields + + private IntPtr reference; + + #endregion + + #region Constructors + + internal Data(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the data. + /// + public IntPtr Pointer + { + get + { + return Marshal.ReadIntPtr(reference, 0); + } + } + + /// + /// Gets the length of the data in bytes. + /// + public int Length + { + get + { + return Marshal.ReadInt32(reference, IntPtr.Size); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/EmbeddingTypes.cs b/SharpFont/Source/SharpFontShared/EmbeddingTypes.cs new file mode 100644 index 000000000..35b0844be --- /dev/null +++ b/SharpFont/Source/SharpFontShared/EmbeddingTypes.cs @@ -0,0 +1,88 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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. + /// + /// + /// 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. + /// + /// + [Flags] + [CLSCompliant(false)] + public enum EmbeddingTypes : ushort + { + /// + /// Fonts with no fsType bit set may be embedded and permanently + /// installed on the remote system by an application. + /// + Installable = 0x0000, + + /// + /// 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. + /// + RestrictedLicense = 0x0002, + + /// + /// If this bit is set, the font may be embedded and temporarily loaded + /// on the remote system. Documents containing Preview & Print + /// fonts must be opened ‘read-only’; no edits can be applied to the + /// document. + /// + PreviewAndPrint = 0x0004, + + /// + /// If this bit is set, the font may be embedded but must only be + /// installed temporarily on other systems. In contrast to Preview + /// & Print fonts, documents containing editable fonts may be + /// opened for reading, editing is permitted, and changes may be saved. + /// + Editable = 0x0008, + + /// + /// If this bit is set, the font may not be subsetted prior to + /// embedding. + /// + NoSubsetting = 0x0100, + + /// + /// 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. + /// + BitmapOnly = 0x0200 + } +} diff --git a/SharpFont/Source/SharpFontShared/Encoding.cs b/SharpFont/Source/SharpFontShared/Encoding.cs new file mode 100644 index 000000000..284555973 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Encoding.cs @@ -0,0 +1,135 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An enumeration used to specify character sets supported by charmaps. + /// Used in the FT_Select_Charmap API function. + /// + /// + /// Despite the name, this enumeration lists specific character repertories + /// (i.e., charsets), and not text encoding methods (e.g., UTF-8, UTF-16, + /// etc.). + /// + /// Other encodings might be defined in the future. + /// + [CLSCompliant(false)] + public enum Encoding : uint + { + /// + /// The encoding value 0 is reserved. + /// + None = 0, + + /// + /// Corresponds to the Microsoft Symbol encoding, used to encode + /// mathematical symbols in the 32..255 character code range. + /// + /// + MicrosoftSymbol = ('s' << 24 | 'y' << 16 | 'm' << 8 | 'b'), + + /// + /// 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. + /// + /// 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. + /// + Unicode = ('u' << 24 | 'n' << 16 | 'i' << 8 | 'c'), + + /// + /// Corresponds to Japanese SJIS encoding. + /// + /// + Sjis = ('s' << 24 | 'j' << 16 | 'i' << 8 | 's'), + + /// + /// Corresponds to an encoding system for Simplified Chinese as used + /// used in mainland China. + /// + GB2312 = ('g' << 24 | 'b' << 16 | ' ' << 8 | ' '), + + /// + /// Corresponds to an encoding system for Traditional Chinese as used + /// in Taiwan and Hong Kong. + /// + Big5 = ('b' << 24 | 'i' << 16 | 'g' << 8 | '5'), + + /// + /// Corresponds to the Korean encoding system known as Wansung. + /// + /// + Wansung = ('w' << 24 | 'a' << 16 | 'n' << 8 | 's'), + + /// + /// 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. + /// + Johab = ('j' << 24 | 'o' << 16 | 'h' << 8 | 'a'), + + /// + /// Corresponds to the Adobe Standard encoding, as found in Type 1, + /// CFF, and OpenType/CFF fonts. It is limited to 256 character codes. + /// + AdobeStandard = ('A' << 24 | 'D' << 16 | 'O' << 8 | 'B'), + + /// + /// Corresponds to the Adobe Expert encoding, as found in Type 1, CFF, + /// and OpenType/CFF fonts. It is limited to 256 character codes. + /// + AdobeExpert = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'E'), + + /// + /// Corresponds to a custom encoding, as found in Type 1, CFF, and + /// OpenType/CFF fonts. It is limited to 256 character codes. + /// + AdobeCustom = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'C'), + + /// + /// Corresponds to a Latin-1 encoding as defined in a Type 1 PostScript + /// font. It is limited to 256 character codes. + /// + AdobeLatin1 = ('l' << 24 | 'a' << 16 | 't' << 8 | '1'), + + /// + /// This value is deprecated and was never used nor reported by + /// FreeType. Don't use or test for it. + /// + [Obsolete("Never used nor reported by FreeType")] + OldLatin2 = ('l' << 24 | 'a' << 16 | 't' << 8 | '2'), + + /// + /// 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. + /// + AppleRoman = ('a' << 24 | 'r' << 16 | 'm' << 8 | 'n'), + } +} diff --git a/SharpFont/Source/SharpFontShared/Error.cs b/SharpFont/Source/SharpFontShared/Error.cs new file mode 100644 index 000000000..9811e7a16 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Error.cs @@ -0,0 +1,298 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// FreeType error codes. + /// + public enum Error + { + /// No error. + Ok = 0x00, + + /// Cannot open resource. + CannotOpenResource = 0x01, + + /// Unknown file format. + UnknownFileFormat = 0x02, + + /// Broken file. + InvalidFileFormat = 0x03, + + /// Invalid FreeType version. + InvalidVersion = 0x04, + + /// Module version is too low. + LowerModuleVersion = 0x05, + + /// Invalid argument. + InvalidArgument = 0x06, + + /// Unimplemented feature. + UnimplementedFeature = 0x07, + + /// Broken table. + InvalidTable = 0x08, + + /// Broken offset within table. + InvalidOffset = 0x09, + + /// Array allocation size too large. + ArrayTooLarge = 0x0A, + + /// Invalid glyph index. + InvalidGlyphIndex = 0x10, + + /// Invalid character code. + InvalidCharacterCode = 0x11, + + /// Unsupported glyph image format. + InvalidGlyphFormat = 0x12, + + /// Cannot render this glyph format. + CannotRenderGlyph = 0x13, + + /// Invalid outline. + InvalidOutline = 0x14, + + /// Invalid composite glyph. + InvalidComposite = 0x15, + + /// Too many hints. + TooManyHints = 0x16, + + /// Invalid pixel size. + InvalidPixelSize = 0x17, + + /// Invalid object handle. + InvalidHandle = 0x20, + + /// Invalid library handle. + InvalidLibraryHandle = 0x21, + + /// Invalid module handle. + InvalidDriverHandle = 0x22, + + /// Invalid face handle. + InvalidFaceHandle = 0x23, + + /// Invalid size handle. + InvalidSizeHandle = 0x24, + + /// Invalid glyph slot handle. + InvalidSlotHandle = 0x25, + + /// Invalid charmap handle. + InvalidCharMapHandle = 0x26, + + /// Invalid cache manager handle. + InvalidCacheHandle = 0x27, + + /// Invalid stream handle. + InvalidStreamHandle = 0x28, + + /// Too many modules. + TooManyDrivers = 0x30, + + /// Too many extensions. + TooManyExtensions = 0x31, + + /// Out of memory. + OutOfMemory = 0x40, + + /// Unlisted object. + UnlistedObject = 0x41, + + /// Cannot open stream. + CannotOpenStream = 0x51, + + /// Invalid stream seek. + InvalidStreamSeek = 0x52, + + /// Invalid stream skip. + InvalidStreamSkip = 0x53, + + /// Invalid stream read. + InvalidStreamRead = 0x54, + + /// Invalid stream operation. + InvalidStreamOperation = 0x55, + + /// Invalid frame operation. + InvalidFrameOperation = 0x56, + + /// Nested frame access. + NestedFrameAccess = 0x57, + + /// Invalid frame read. + InvalidFrameRead = 0x58, + + /// Raster uninitialized. + RasterUninitialized = 0x60, + + /// Raster corrupted. + RasterCorrupted = 0x61, + + /// Raster overflow. + RasterOverflow = 0x62, + + /// Negative height while rastering. + RasterNegativeHeight = 0x63, + + /// Too many registered caches. + TooManyCaches = 0x70, + + /// Invalid opcode. + InvalidOpCode = 0x80, + + /// Too few arguments. + TooFewArguments = 0x81, + + /// Stack overflow. + StackOverflow = 0x82, + + /// Code overflow. + CodeOverflow = 0x83, + + /// Bad argument. + BadArgument = 0x84, + + /// Division by zero. + DivideByZero = 0x85, + + /// Invalid reference. + InvalidReference = 0x86, + + /// Found debug opcode. + DebugOpCode = 0x87, + + /// Found ENDF opcode in execution stream. + EndfInExecStream = 0x88, + + /// Nested DEFS. + NestedDefs = 0x89, + + /// Invalid code range. + InvalidCodeRange = 0x8A, + + /// Execution context too long. + ExecutionTooLong = 0x8B, + + /// Too many function definitions. + TooManyFunctionDefs = 0x8C, + + /// Too many instruction definitions. + TooManyInstructionDefs = 0x8D, + + /// SFNT font table missing. + TableMissing = 0x8E, + + /// Horizontal header (hhea) table missing. + HorizHeaderMissing = 0x8F, + + /// Locations (loca) table missing. + LocationsMissing = 0x90, + + /// Name table missing. + NameTableMissing = 0x91, + + /// Character map (cmap) table missing. + CMapTableMissing = 0x92, + + /// Horizontal metrics (hmtx) table missing. + HmtxTableMissing = 0x93, + + /// PostScript (post) table missing. + PostTableMissing = 0x94, + + /// Invalid horizontal metrics. + InvalidHorizMetrics = 0x95, + + /// Invalid character map (cmap) format. + InvalidCharMapFormat = 0x96, + + /// Invalid ppem value. + InvalidPPem = 0x97, + + /// Invalid vertical metrics. + InvalidVertMetrics = 0x98, + + /// Could not find context. + CouldNotFindContext = 0x99, + + /// Invalid PostScript (post) table format. + InvalidPostTableFormat = 0x9A, + + /// Invalid PostScript (post) table. + InvalidPostTable = 0x9B, + + /// Opcode syntax error. + SyntaxError = 0xA0, + + /// Argument stack underflow. + StackUnderflow = 0xA1, + + /// Ignore this error. + Ignore = 0xA2, + + /// No Unicode glyph name found. + NoUnicodeGlyphName = 0xA3, + + /// `STARTFONT' field missing. + MissingStartfontField = 0xB0, + + /// `FONT' field missing. + MissingFontField = 0xB1, + + /// `SIZE' field missing. + MissingSizeField = 0xB2, + + /// `FONTBOUNDINGBOX' field missing. + MissingFontboudingboxField = 0xB3, + + /// `CHARS' field missing. + MissingCharsField = 0xB4, + + /// `STARTCHAR' field missing. + MissingStartcharField = 0xB5, + + /// `ENCODING' field missing. + MissingEncodingField = 0xB6, + + /// `BBX' field missing. + MissingBbxField = 0xB7, + + /// `BBX' too big. + BbxTooBig = 0xB8, + + /// Font header corrupted or missing fields. + CorruptedFontHeader = 0xB9, + + /// Font glyphs corrupted or missing fields. + CorruptedFontGlyphs = 0xBA + } +} diff --git a/SharpFont/Source/SharpFontShared/FT.Internal.cs b/SharpFont/Source/SharpFontShared/FT.Internal.cs new file mode 100644 index 000000000..b73d35947 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FT.Internal.cs @@ -0,0 +1,770 @@ +#region MIT License +/*Copyright (c) 2012-2016 Robert Rouhani + +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 +{ + /// + /// This file contains all the raw FreeType2 function signatures. + /// + public static partial class FT + { + /// + /// Defines the location of the FreeType DLL. Update SharpFont.dll.config if you change this! + /// +#if SHARPFONT_PLATFORM_IOS + private const string FreetypeDll = "__Internal"; +#else + private const string FreetypeDll = "freetype6"; +#endif + + /// + /// Defines the calling convention for P/Invoking the native freetype methods. + /// + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/FT.Public.cs b/SharpFont/Source/SharpFontShared/FT.Public.cs new file mode 100644 index 000000000..676d60162 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FT.Public.cs @@ -0,0 +1,262 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// Miscellaneous FreeType2 functions that don't fit anywhere else. + /// + public static partial class FT + { + #region Computations + + /// + /// A very simple function used to perform the computation ‘(a*b)/c’ with maximal accuracy (it uses a 64-bit + /// intermediate integer whenever necessary). + /// + /// This function isn't necessarily as fast as some processor specific operations, but is at least completely + /// portable. + /// + /// The first multiplier. + /// The second multiplier. + /// The divisor. + /// + /// 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’. + /// + [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)); + } + + /// + /// 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. + /// + /// + /// 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. + /// + /// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make + /// a great difference. + /// + /// The first multiplier. + /// The second multiplier. Use a 16.16 factor here whenever possible (see note below). + /// The result of ‘(a*b)/0x10000’. + [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)); + } + + /// + /// 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. + /// + /// + /// The optimization for is simple: If (a << 16) fits in 32 bits, then the division + /// is computed directly. Otherwise, we use a specialized version of . + /// + /// The first multiplier. + /// The second multiplier. Use a 16.16 factor here whenever possible (see note below). + /// The result of ‘(a*0x10000)/b’. + [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)); + } + + /// + /// A very simple function used to round a 16.16 fixed number. + /// + /// The number to be rounded. + /// The result of ‘(a + 0x8000) & -0x10000’. + [Obsolete("Use Fixed16Dot16.RoundFix() instead.")] + public static Fixed16Dot16 RoundFix(Fixed16Dot16 a) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_RoundFix((IntPtr)a.Value)); + } + + /// + /// A very simple function used to compute the ceiling function of a 16.16 fixed number. + /// + /// The number for which the ceiling function is to be computed. + /// The result of ‘(a + 0x10000 - 1) & -0x10000’. + [Obsolete("Use Fixed16Dot16.CeilingFix() instead.")] + public static Fixed16Dot16 CeilFix(Fixed16Dot16 a) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_CeilFix((IntPtr)a.Value)); + } + + /// + /// A very simple function used to compute the floor function of a 16.16 fixed number. + /// + /// The number for which the floor function is to be computed. + /// The result of ‘a & -0x10000’. + [Obsolete("Use Fixed16Dot16.FloorFix() instead.")] + public static Fixed16Dot16 FloorFix(Fixed16Dot16 a) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_FloorFix((IntPtr)a.Value)); + } + + /// + /// Return the sinus of a given angle in fixed point format. + /// + /// + /// If you need both the sinus and cosinus for a given angle, use the function . + /// + /// The input angle. + /// The sinus value. + [Obsolete("Use Fixed16Dot16.Sin() instead.")] + public static Fixed16Dot16 Sin(Fixed16Dot16 angle) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)angle.Value)); + } + + /// + /// Return the cosinus of a given angle in fixed point format. + /// + /// + /// If you need both the sinus and cosinus for a given angle, use the function . + /// + /// The input angle. + /// The cosinus value. + [Obsolete("Use Fixed16Dot16.Cos() instead.")] + public static Fixed16Dot16 Cos(Fixed16Dot16 angle) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)angle.Value)); + } + + /// + /// Return the tangent of a given angle in fixed point format. + /// + /// The input angle. + /// The tangent value. + [Obsolete("Use Fixed16Dot16.Tan() instead.")] + public static Fixed16Dot16 Tan(Fixed16Dot16 angle) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)angle.Value)); + } + + /// + /// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane. + /// + /// The horizontal vector coordinate. + /// The vertical vector coordinate. + /// The arc-tangent value (i.e. angle). + [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)); + } + + /// + /// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval. + /// + /// First angle. + /// Second angle. + /// Constrained value of ‘value2-value1’. + [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 + + /// + /// Return an FSSpec for the disk file containing the named font. + /// + /// Mac OS name of the font (e.g., Times New Roman Bold). + /// Index of the face. For passing to . + /// FSSpec to the file. For passing to . + 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; + } + + /// + /// Return an FSSpec for the disk file containing the named font. + /// + /// Mac OS name of the font in ATS framework. + /// Index of the face. For passing to . + /// FSSpec to the file. For passing to . + 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; + } + + /// + /// Return a pathname of the disk file and face index for given font name which is handled by ATS framework. + /// + /// Mac OS name of the font in ATS framework. + /// + /// Buffer to store pathname of the file. For passing to . The client must + /// allocate this buffer before calling this function. + /// + /// Index of the face. For passing to . + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/FTBitmap.cs b/SharpFont/Source/SharpFontShared/FTBitmap.cs new file mode 100644 index 000000000..5b2ad7271 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTBitmap.cs @@ -0,0 +1,546 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani + +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 +{ + /// + /// A structure used to describe a bitmap or pixmap to the raster. Note that we now manage pixmaps of various + /// depths through the field. + /// + /// + /// 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. + /// + 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 + + /// + /// Initializes a new instance of the class. + /// + /// The parent . + 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; + } + + /// + /// Finalizes an instance of the class. + /// + ~FTBitmap() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets the number of bitmap rows. + /// + public int Rows + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.rows; + } + } + + /// + /// Gets the number of pixels in bitmap row. + /// + public int Width + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.width; + } + } + + /// + /// 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. + /// + /// Note that ‘padding’ means the alignment of a bitmap to a byte border, and FreeType functions normally align + /// to the smallest possible integer value. + /// + /// For the B/W rasterizer, ‘pitch’ is always an even number. + /// + /// To change the pitch of a bitmap (say, to make it a multiple of 4), use . + /// 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. + /// + public int Pitch + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.pitch; + } + } + + /// + /// Gets a typeless pointer to the bitmap buffer. This value should be aligned on 32-bit boundaries in most + /// cases. + /// + public IntPtr Buffer + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.buffer; + } + } + + /// + /// Gets the number of gray levels used in the bitmap. This field is only used with + /// . + /// + public short GrayLevels + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.num_grays; + } + } + + /// + /// Gets the pixel mode, i.e., how pixel bits are stored. + /// + public PixelMode PixelMode + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.pixel_mode; + } + } + + /// + /// Gets how the palette is stored. This field is intended for paletted pixel modes. + /// + [Obsolete("Not used currently.")] + public byte PaletteMode + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.palette_mode; + } + } + + /// + /// Gets a typeless pointer to the bitmap palette; this field is intended for paletted pixel modes. + /// + [Obsolete("Not used currently.")] + public IntPtr Palette + { + get + { + if (disposed) + throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object."); + + return rec.palette; + } + } + + /// + /// Gets the 's buffer as a byte array. + /// + 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(reference); + } + } + + #endregion + + #region Methods + + /// + /// Copy a bitmap into another one. + /// + /// A handle to a library object. + /// A handle to the target bitmap. + 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; + } + + /// + /// Embolden a bitmap. The new bitmap will be about ‘xStrength’ pixels wider and ‘yStrength’ pixels higher. The + /// left and bottom borders are kept unchanged. + /// + /// + /// The current implementation restricts ‘xStrength’ to be less than or equal to 8 if bitmap is of pixel_mode + /// . + /// + /// If you want to embolden the bitmap owned by a , you should call + /// on the slot first. + /// + /// A handle to a library object. + /// + /// How strong the glyph is emboldened horizontally. Expressed in 26.6 pixel format. + /// + /// + /// How strong the glyph is emboldened vertically. Expressed in 26.6 pixel format. + /// + 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); + } + + /// + /// 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’. + /// + /// + /// It is possible to call multiple times without calling + /// (the memory is simply reallocated). + /// + /// Use to finally remove the bitmap object. + /// + /// The ‘library’ argument is taken to have access to FreeType's memory handling functions. + /// + /// A handle to a library object. + /// + /// The pitch of the bitmap is a multiple of this parameter. Common values are 1, 2, or 4. + /// + /// The target bitmap. + 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 + /// + /// Copies the contents of the to a GDI+ . + /// + /// A GDI+ containing this bitmap's data. + public Bitmap ToGdipBitmap() + { + return ToGdipBitmap(Color.Black); + } + + /// + /// Copies the contents of the to a GDI+ . + /// + /// The color of the text. + /// A GDI+ containing this bitmap's data with a transparent background. + 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 + + /// + /// Disposes an instance of the class. + /// + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/FTList.cs b/SharpFont/Source/SharpFontShared/FTList.cs new file mode 100644 index 000000000..d0597664f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTList.cs @@ -0,0 +1,195 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An iterator function which is called during a list parse by . + /// + /// The current iteration list node. + /// + /// A typeless pointer passed to . Can be used to point to the iteration's state. + /// + /// Error code. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate Error ListIterator(NativeReference node, IntPtr user); + + /// + /// An iterator function which is called during a list finalization by + /// to destroy all elements in a given list. + /// + /// The current system object. + /// The current object to destroy. + /// + /// A typeless pointer passed to . It can be used to point to the iteration's state. + /// + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void ListDestructor(NativeReference memory, IntPtr data, IntPtr user); + + /// + /// A structure used to hold a simple doubly-linked list. These are used in many parts of FreeType. + /// + public sealed class FTList + { + #region Fields + + private IntPtr reference; + private ListRec rec; + + #endregion + + #region Constructors + + internal FTList(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the head (first element) of doubly-linked list. + /// + public ListNode Head + { + get + { + return new ListNode(rec.head); + } + } + + /// + /// Gets the tail (last element) of doubly-linked list. + /// + public ListNode Tail + { + get + { + return new ListNode(rec.tail); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + + #region Methods + + /// + /// Find the list node for a given listed object. + /// + /// The address of the listed object. + /// List node. NULL if it wasn't found. + public ListNode Find(IntPtr data) + { + return new ListNode(FT.FT_List_Find(Reference, data)); + } + + /// + /// Append an element to the end of a list. + /// + /// The node to append. + public void Add(ListNode node) + { + FT.FT_List_Add(Reference, node.Reference); + } + + /// + /// Insert an element at the head of a list. + /// + /// The node to insert. + public void Insert(ListNode node) + { + FT.FT_List_Insert(Reference, node.Reference); + } + + /// + /// Remove a node from a list. This function doesn't check whether the node is in the list! + /// + /// The node to remove. + public void Remove(ListNode node) + { + FT.FT_List_Remove(Reference, node.Reference); + } + + /// + /// Move a node to the head/top of a list. Used to maintain LRU lists. + /// + /// The node to move. + public void Up(ListNode node) + { + FT.FT_List_Up(Reference, node.Reference); + } + + /// + /// 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. + /// + /// An iterator function, called on each node of the list. + /// A user-supplied field which is passed as the second argument to the iterator. + public void Iterate(ListIterator iterator, IntPtr user) + { + Error err = FT.FT_List_Iterate(Reference, iterator, user); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Destroy all elements in the list as well as the list itself. + /// + /// + /// This function expects that all nodes added by or have been + /// dynamically allocated. + /// + /// A list destructor that will be applied to each element of the list. + /// The current memory object which handles deallocation. + /// A user-supplied field which is passed as the last argument to the destructor. + public void Finalize(ListDestructor destroy, Memory memory, IntPtr user) + { + FT.FT_List_Finalize(Reference, destroy, memory.Reference, user); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/FTMatrix.cs b/SharpFont/Source/SharpFontShared/FTMatrix.cs new file mode 100644 index 000000000..f724f95c6 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTMatrix.cs @@ -0,0 +1,250 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// A simple structure used to store a 2x2 matrix. Coefficients are in 16.16 fixed float format. The computation + /// performed is: + /// + /// x' = x*xx + y*xy + /// y' = x*yx + y*yy + /// + /// + [StructLayout(LayoutKind.Sequential)] + public struct FTMatrix : IEquatable + { + #region Fields + + private IntPtr xx, xy; + private IntPtr yx, yy; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// Matrix coefficient XX. + /// Matrix coefficient XY. + /// Matrix coefficient YX. + /// Matrix coefficient YY. + 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; + } + + /// + /// Initializes a new instance of the struct. + /// + /// Matrix coefficients XX, XY. + /// Matrix coefficients YX, YY. + public FTMatrix(FTVector row0, FTVector row1) + : this(row0.X.Value, row0.Y.Value, row1.X.Value, row1.Y.Value) + { + } + + #endregion + + #region Properties + + /// + /// Gets or sets the matrix coefficient. + /// + public Fixed16Dot16 XX + { + get + { + return Fixed16Dot16.FromRawValue((int)xx); + } + + set + { + xx = (IntPtr)value.Value; + } + } + + /// + /// Gets or sets the matrix coefficient. + /// + public Fixed16Dot16 XY + { + get + { + return Fixed16Dot16.FromRawValue((int)xy); + } + + set + { + xy = (IntPtr)value.Value; + } + } + + /// + /// Gets or sets the matrix coefficient. + /// + public Fixed16Dot16 YX + { + get + { + return Fixed16Dot16.FromRawValue((int)yx); + } + + set + { + yx = (IntPtr)value.Value; + } + } + + /// + /// Gets or sets the matrix coefficient. + /// + public Fixed16Dot16 YY + { + get + { + return Fixed16Dot16.FromRawValue((int)yy); + } + + set + { + yy = (IntPtr)value.Value; + } + } + + #endregion + + #region Operators + + /// + /// Compares two instances of for equality. + /// + /// A . + /// Another . + /// A value indicating equality. + public static bool operator ==(FTMatrix left, FTMatrix right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// A . + /// Another . + /// A value indicating inequality. + public static bool operator !=(FTMatrix left, FTMatrix right) + { + return !left.Equals(right); + } + + #endregion + + #region Methods + + /// + /// Perform the matrix operation ‘b = a*b’. + /// + /// + /// The result is undefined if either ‘a’ or ‘b’ is zero. + /// + /// A pointer to matrix ‘a’. + /// A pointer to matrix ‘b’. + public static void Multiply(FTMatrix a, FTMatrix b) + { + FT.FT_Matrix_Multiply(ref a, ref b); + } + + /// + /// Perform the matrix operation ‘b = a*b’. + /// + /// + /// The result is undefined if either ‘a’ or ‘b’ is zero. + /// + /// A pointer to matrix ‘b’. + public void Multiply(FTMatrix b) + { + FT.FT_Matrix_Multiply(ref this, ref b); + } + + /// + /// Invert a 2x2 matrix. Return an error if it can't be inverted. + /// + public void Invert() + { + Error err = FT.FT_Matrix_Invert(ref this); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Compares this instance of to another for equality. + /// + /// A . + /// A value indicating equality. + public bool Equals(FTMatrix other) + { + return + xx == other.xx && + xy == other.xy && + yx == other.yx && + yy == other.yy; + } + + /// + /// Compares this instance of to an object for equality. + /// + /// An object. + /// A value indicating equality. + public override bool Equals(object obj) + { + if (obj is FTMatrix) + return this.Equals((FTMatrix)obj); + else + return false; + } + + /// + /// Gets a unique hash code for this instance. + /// + /// A hash code. + public override int GetHashCode() + { + return xx.GetHashCode() ^ xy.GetHashCode() ^ yx.GetHashCode() ^ yy.GetHashCode(); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/FTSize.cs b/SharpFont/Source/SharpFontShared/FTSize.cs new file mode 100644 index 000000000..ce07d745d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTSize.cs @@ -0,0 +1,269 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani + +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 +{ + /// + /// FreeType root size class structure. A size object models a face object at a given size. + /// + 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 + + /// + /// Initializes a new instance of the class. + /// + /// The parent face. + 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; + } + } + + /// + /// Finalizes an instance of the FTSize class. + /// + ~FTSize() + { + Dispose(false); + } + + #endregion + + #region Events + + /// + /// Occurs when the size is disposed. + /// + public event EventHandler Disposed; + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets a handle to the parent face object. + /// + public Face Face + { + get + { + if (disposed) + throw new ObjectDisposedException("Face", "Cannot access a disposed object."); + + return parentFace; + } + } + + /// + /// 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. + /// + [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(Reference, "generic")); + Reference = reference; //update rec. + } + } + + /// + /// Gets metrics for this size object. This field is read-only. + /// + public SizeMetrics Metrics + { + get + { + if (disposed) + throw new ObjectDisposedException("Metrics", "Cannot access a disposed object."); + + return new SizeMetrics(rec.metrics); + } + } + + /// + /// Gets or sets an object used to identify this instance of . This object will not be + /// modified or accessed internally. + /// + /// + /// 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. + /// + 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(reference); + } + } + + #endregion + + #region Public Methods + + /// + /// Even though it is possible to create several size objects for a given face (see + /// for details), functions like or + /// only use the one which has been activated last to determine the + /// ‘current character pixel size’. + /// + /// This function can be used to ‘activate’ a previously created size object. + /// + /// + /// If ‘face’ is the size's parent face object, this function changes the value of ‘face->size’ to the input + /// size handle. + /// + 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); + } + + /// + /// Diposes the FTSize. + /// + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/FTStream.cs b/SharpFont/Source/SharpFontShared/FTStream.cs new file mode 100644 index 000000000..927c6e072 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTStream.cs @@ -0,0 +1,315 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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 +{ + /// + /// A function used to seek and read data from a given input stream. + /// + /// + /// 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. + /// + /// A handle to the source stream. + /// The offset of read in stream (always from start). + /// The address of the read buffer. + /// The number of bytes to read from the stream. + /// The number of bytes effectively read by the stream. + [CLSCompliant(false)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate uint StreamIOFunc(NativeReference stream, uint offset, IntPtr buffer, uint count); + + /// + /// A function used to close a given input stream. + /// + /// A handle to the target stream. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void StreamCloseFunc(NativeReference stream); + + /// + /// A handle to an input stream. + /// + public sealed class FTStream : NativeObject + { + #region Fields + + private StreamRec rec; + + #endregion + + #region Constructors + + internal FTStream(IntPtr reference): base(reference) + { + } + + #endregion + + #region Properties + + /// + /// 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. + /// + public IntPtr Base + { + get + { + return rec.@base; + } + } + + /// + /// Gets the stream size in bytes. + /// + [CLSCompliant(false)] + public uint Size + { + get + { + return (uint)rec.size; + } + } + + /// + /// Gets the current position within the stream. + /// + [CLSCompliant(false)] + public uint Position + { + get + { + return (uint)rec.pos; + } + } + + /// + /// 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. + /// + public StreamDesc Descriptor + { + get + { + return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf(Reference, "descriptor")); + } + } + + /// + /// 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). + /// + public StreamDesc PathName + { + get + { + return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf(Reference, "pathname")); + } + } + + /// + /// Gets the stream's input function. + /// + [CLSCompliant(false)] + public StreamIOFunc Read + { + get + { + return rec.read; + } + } + + /// + /// Gets the stream's close function. + /// + public StreamCloseFunc Close + { + get + { + return rec.close; + } + } + + /// + /// Gets the memory manager to use to preload frames. This is set internally by FreeType and shouldn't be + /// touched by stream implementations. + /// + public Memory Memory + { + get + { + return new Memory(PInvokeHelper.AbsoluteOffsetOf(Reference, "memory")); + } + } + + /// + /// Gets the cursor. This field is set and used internally by FreeType when parsing frames. + /// + public IntPtr Cursor + { + get + { + return rec.cursor; + } + } + + /// + /// Gets the limit. This field is set and used internally by FreeType when parsing frames. + /// + public IntPtr Limit + { + get + { + return rec.limit; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + + #region Methods + + #region GZIP Streams + + /// + /// 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. + /// + /// + /// The source stream must be opened before calling this function. + /// + /// 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. + /// + /// The stream implementation is very basic and resets the decompression process each time seeking backwards is + /// needed within the stream. + /// + /// In certain builds of the library, gzip compression recognition is automatically handled when calling + /// or . 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. + /// + /// This function may return if your build of FreeType was not + /// compiled with zlib support. + /// + /// The source stream. + 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 + + /// + /// 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. + /// + /// + /// The source stream must be opened before calling this function. + /// + /// 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. + /// + /// The stream implementation is very basic and resets the decompression process each time seeking backwards is + /// needed within the stream. + /// + /// In certain builds of the library, LZW compression recognition is automatically handled when calling + /// or . 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. + /// + /// This function may return if your build of FreeType was not + /// compiled with LZW support. + /// + /// The source stream. + 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 + + /// + /// 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. + /// + /// + /// The source stream must be opened before calling this function. + /// + /// 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. + /// + /// The stream implementation is very basic and resets the decompression process each time seeking backwards is + /// needed within the stream. + /// + /// In certain builds of the library, bzip2 compression recognition is automatically handled when calling + /// or . 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. + /// + /// This function may return if your build of FreeType was not + /// compiled with bzip2 support. + /// + /// The source stream. + public void StreamOpenBzip2(FTStream source) + { + Error err = FT.FT_Stream_OpenBzip2(Reference, source.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + #endregion + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/FTUnitVector.cs b/SharpFont/Source/SharpFontShared/FTUnitVector.cs new file mode 100644 index 000000000..88a0c78fc --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTUnitVector.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2015 Robert Rouhani + +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 +{ + /// + /// A simple structure used to store a 2D vector unit vector. Uses types. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct FTUnitVector + { + /// + /// Horizontal coordinate. + /// + public Fixed2Dot14 X; + + /// + /// Vertical coordinate. + /// + public Fixed2Dot14 Y; + } +} diff --git a/SharpFont/Source/SharpFontShared/FTVector.cs b/SharpFont/Source/SharpFontShared/FTVector.cs new file mode 100644 index 000000000..543fff43d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTVector.cs @@ -0,0 +1,240 @@ +#region MIT License +/*Copyright (c) 2012-2016 Robert Rouhani + +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 +{ + /// + /// A simple structure used to store a 2D vector. + /// + [StructLayout(LayoutKind.Sequential)] + public struct FTVector : IEquatable + { + #region Fields + + private IntPtr x; + private IntPtr y; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// The horizontal coordinate. + /// The vertical coordinate. + 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 + + /// + /// Gets or sets the horizontal coordinate. + /// + public Fixed16Dot16 X + { + get + { + return Fixed16Dot16.FromRawValue((int)x); + } + + set + { + x = (IntPtr)value.Value; + } + } + + /// + /// Gets or sets the vertical coordinate. + /// + public Fixed16Dot16 Y + { + get + { + return Fixed16Dot16.FromRawValue((int)y); + } + + set + { + y = (IntPtr)value.Value; + } + } + + #endregion + + #region Operators + + /// + /// Compares two instances of for equality. + /// + /// A . + /// Another . + /// A value indicating equality. + public static bool operator ==(FTVector left, FTVector right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// A . + /// Another . + /// A value indicating inequality. + public static bool operator !=(FTVector left, FTVector right) + { + return !left.Equals(right); + } + + #endregion + + #region Methods + + /// + /// 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)’. + /// + /// This function is useful to retrieve both the sinus and cosinus of a given angle quickly. + /// + /// The address of angle. + /// The address of target vector. + public static FTVector Unit(Fixed16Dot16 angle) + { + FTVector vec; + FT.FT_Vector_Unit(out vec, (IntPtr)angle.Value); + + return vec; + } + + /// + /// Compute vector coordinates from a length and angle. + /// + /// The vector length. + /// The vector angle. + /// The address of source vector. + 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; + } + + /// + /// Transform a single vector through a 2x2 matrix. + /// + /// + /// The result is undefined if either ‘vector’ or ‘matrix’ is invalid. + /// + /// A pointer to the source 2x2 matrix. + public void Transform(FTMatrix matrix) + { + FT.FT_Vector_Transform(ref this, ref matrix); + } + + /// + /// Rotate a vector by a given angle. + /// + /// The address of angle. + public void Rotate(Fixed16Dot16 angle) + { + FT.FT_Vector_Rotate(ref this, (IntPtr)angle.Value); + } + + /// + /// Return the length of a given vector. + /// + /// The vector length, expressed in the same units that the original vector coordinates. + public Fixed16Dot16 Length() + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Vector_Length(ref this)); + } + + /// + /// Compute both the length and angle of a given vector. + /// + /// The vector length. + /// The vector angle. + 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); + } + + /// + /// Compares this instance of to another for equality. + /// + /// A . + /// A value indicating equality. + public bool Equals(FTVector other) + { + return x == other.x && y == other.y; + } + + /// + /// Compares this instance of to an object for equality. + /// + /// An object. + /// A value indicating equality. + public override bool Equals(object obj) + { + if (obj is FTVector) + return this.Equals((FTVector)obj); + else + return false; + } + + /// + /// Gets a unique hash code for this instance. + /// + /// A hash code. + public override int GetHashCode() + { + return x.GetHashCode() ^ y.GetHashCode(); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/FTVector26Dot6.cs b/SharpFont/Source/SharpFontShared/FTVector26Dot6.cs new file mode 100644 index 000000000..cf89ac38e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FTVector26Dot6.cs @@ -0,0 +1,164 @@ +#region MIT License +/*Copyright (c) 2015 Robert Rouhani + +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 +{ + /// + /// A simple structure used to store a 2D vector. + /// + [StructLayout(LayoutKind.Sequential)] + public struct FTVector26Dot6 : IEquatable + { + #region Fields + + private IntPtr x; + private IntPtr y; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// The horizontal coordinate. + /// The vertical coordinate. + 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 + + /// + /// Gets or sets the horizontal coordinate. + /// + public Fixed26Dot6 X + { + get + { + return Fixed26Dot6.FromRawValue((int)x); + } + + set + { + x = (IntPtr)value.Value; + } + } + + /// + /// Gets or sets the vertical coordinate. + /// + public Fixed26Dot6 Y + { + get + { + return Fixed26Dot6.FromRawValue((int)y); + } + + set + { + y = (IntPtr)value.Value; + } + } + + #endregion + + #region Operators + + /// + /// Compares two instances of for equality. + /// + /// A . + /// Another . + /// A value indicating equality. + public static bool operator ==(FTVector26Dot6 left, FTVector26Dot6 right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// A . + /// Another . + /// A value indicating inequality. + public static bool operator !=(FTVector26Dot6 left, FTVector26Dot6 right) + { + return !left.Equals(right); + } + + #endregion + + #region Methods + + /// + /// Compares this instance of to another for equality. + /// + /// A . + /// A value indicating equality. + public bool Equals(FTVector26Dot6 other) + { + return x == other.x && y == other.y; + } + + /// + /// Compares this instance of to an object for equality. + /// + /// An object. + /// A value indicating equality. + public override bool Equals(object obj) + { + if (obj is FTVector26Dot6) + return this.Equals((FTVector26Dot6)obj); + else + return false; + } + + /// + /// Gets a unique hash code for this instance. + /// + /// A hash code. + public override int GetHashCode() + { + return x.GetHashCode() ^ y.GetHashCode(); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Face.cs b/SharpFont/Source/SharpFontShared/Face.cs new file mode 100644 index 000000000..fea801bdf --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Face.cs @@ -0,0 +1,2412 @@ +#region MIT License +/*Copyright (c) 2012-2016 Robert Rouhani + +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.Bdf; +using SharpFont.Internal; +using SharpFont.MultipleMasters; +using SharpFont.PostScript; +using SharpFont.TrueType; + +namespace SharpFont +{ + /// + /// FreeType root face class structure. A face object models a typeface in a font file. + /// + /// + /// Fields may be changed after a call to or . + /// + public sealed class Face : NativeObject, IDisposable + { + #region Fields + + private FaceRec rec; + + private bool disposed; + + private GCHandle memoryFaceHandle; + + private Library parentLibrary; + private List childSizes; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class with a default faceIndex of 0. + /// + /// The parent library. + /// The path of the font file. + public Face(Library library, string path) + : this(library, path, 0) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent library. + /// The path of the font file. + /// The index of the face to take from the file. + public Face(Library library, string path, int faceIndex) + : this(library) + { + IntPtr reference; + Error err = FT.FT_New_Face(library.Reference, path, faceIndex, out reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = reference; + } + + //TODO make an overload with a FileStream instead of a byte[] + + /// + /// Initializes a new instance of the class from a file that's already loaded into memory. + /// + /// The parent library. + /// The loaded file. + /// The index of the face to take from the file. + public Face(Library library, byte[] file, int faceIndex) + : this(library) + { + IntPtr reference; + memoryFaceHandle = GCHandle.Alloc(file, GCHandleType.Pinned); + Error err = FT.FT_New_Memory_Face(library.Reference, memoryFaceHandle.AddrOfPinnedObject(), file.Length, faceIndex, out reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = reference; + } + + /// + /// Initializes a new instance of the class from a file that's already loaded into memory. + /// + /// The parent library. + /// A pointer to a buffer of a loaded file. Must not be freed before . + /// The length of bufferPtr. + /// The index of the face to take from the file. + public Face(Library library, IntPtr bufferPtr, int length, int faceIndex) + : this(library) + { + IntPtr reference; + Error err = FT.FT_New_Memory_Face(library.Reference, bufferPtr, length, faceIndex, out reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = reference; + } + + /// + /// Initializes a new instance of the class. + /// + /// A pointer to the unmanaged memory containing the Face. + /// The parent . + internal Face(IntPtr reference, Library parent) + : this(parent) + { + Reference = reference; + } + + private Face(Library parent): base(IntPtr.Zero) + { + childSizes = new List(); + + if (parent != null) + { + parentLibrary = parent; + parentLibrary.AddChildFace(this); + } + else + { + //if there's no parent, this is a marshalled duplicate. + FT.FT_Reference_Face(Reference); + } + } + + /// + /// Finalizes an instance of the class. + /// + ~Face() + { + Dispose(false); + } + + #endregion + + #region Events + + /// + /// Occurs when the face is disposed. + /// + public event EventHandler Disposed; + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets the number of faces in the font file. Some font formats can have multiple faces in a font file. + /// + public int FaceCount + { + get + { + if (disposed) + throw new ObjectDisposedException("FaceCount", "Cannot access a disposed object."); + + return (int)rec.num_faces; + } + } + + /// + /// Gets the index of the face in the font file. It is set to 0 if there is only one face in the font file. + /// + public int FaceIndex + { + get + { + if (disposed) + throw new ObjectDisposedException("FaceIndex", "Cannot access a disposed object."); + + return (int)rec.face_index; + } + } + + /// + /// Gets a set of bit flags that give important information about the face. + /// + /// + public FaceFlags FaceFlags + { + get + { + if (disposed) + throw new ObjectDisposedException("FaceFlags", "Cannot access a disposed object."); + + return (FaceFlags)rec.face_flags; + } + } + + /// + /// Gets a set of bit flags indicating the style of the face. + /// + /// + public StyleFlags StyleFlags + { + get + { + if (disposed) + throw new ObjectDisposedException("StyleFlags", "Cannot access a disposed object."); + + return (StyleFlags)rec.style_flags; + } + } + + /// + /// Gets the number of glyphs in the face. If the face is scalable and has sbits (see ‘num_fixed_sizes’), it is + /// set to the number of outline glyphs. + /// + /// For CID-keyed fonts, this value gives the highest CID used in the font. + /// + public int GlyphCount + { + get + { + if (disposed) + throw new ObjectDisposedException("GlyphCount", "Cannot access a disposed object."); + + return (int)rec.num_glyphs; + } + } + + /// + /// Gets the face's family name. This is an ASCII string, usually in English, which describes the typeface's + /// family (like ‘Times New Roman’, ‘Bodoni’, ‘Garamond’, etc). This is a least common denominator used to list + /// fonts. Some formats (TrueType & OpenType) provide localized and Unicode versions of this string. + /// Applications should use the format specific interface to access them. Can be NULL (e.g., in fonts embedded + /// in a PDF file). + /// + public string FamilyName + { + get + { + if (disposed) + throw new ObjectDisposedException("FamilyName", "Cannot access a disposed object."); + + return Marshal.PtrToStringAnsi(rec.family_name); + } + } + + /// + /// Gets the face's style name. This is an ASCII string, usually in English, which describes the typeface's + /// style (like ‘Italic’, ‘Bold’, ‘Condensed’, etc). Not all font formats provide a style name, so this field + /// is optional, and can be set to NULL. As for ‘family_name’, some formats provide localized and Unicode + /// versions of this string. Applications should use the format specific interface to access them. + /// + public string StyleName + { + get + { + if (disposed) + throw new ObjectDisposedException("StyleName", "Cannot access a disposed object."); + + return Marshal.PtrToStringAnsi(rec.style_name); + } + } + + /// + /// Gets the number of bitmap strikes in the face. Even if the face is scalable, there might still be bitmap + /// strikes, which are called ‘sbits’ in that case. + /// + public int FixedSizesCount + { + get + { + if (disposed) + throw new ObjectDisposedException("FixedSizesCount", "Cannot access a disposed object."); + + return rec.num_fixed_sizes; + } + } + + /// + /// Gets an array of FT_Bitmap_Size for all bitmap strikes in the face. It is set to NULL if there is no bitmap + /// strike. + /// + public BitmapSize[] AvailableSizes + { + get + { + if (disposed) + throw new ObjectDisposedException("AvailableSizes", "Cannot access a disposed object."); + + int count = FixedSizesCount; + + if (count == 0) + return null; + + BitmapSize[] sizes = new BitmapSize[count]; + IntPtr array = rec.available_sizes; + + for (int i = 0; i < count; i++) + { + sizes[i] = new BitmapSize(new IntPtr(array.ToInt64() + IntPtr.Size * i)); + } + + return sizes; + } + } + + /// + /// Gets the number of charmaps in the face. + /// + public int CharmapsCount + { + get + { + if (disposed) + throw new ObjectDisposedException("CharmapsCount", "Cannot access a disposed object."); + + return rec.num_charmaps; + } + } + + /// + /// Gets an array of the charmaps of the face. + /// + public CharMap[] CharMaps + { + get + { + if (disposed) + throw new ObjectDisposedException("CharMaps", "Cannot access a disposed object."); + + int count = CharmapsCount; + + if (count == 0) + return null; + + CharMap[] charmaps = new CharMap[count]; + + unsafe + { + IntPtr* array = (IntPtr*)rec.charmaps; + + for (int i = 0; i < count; i++) + { + charmaps[i] = new CharMap(*array, this); + array++; + } + } + + return charmaps; + } + } + + /// + /// Gets or sets a field reserved for client uses. + /// + /// + [Obsolete("Use the Tag property and Disposed event.")] + 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."); + + IntPtr reference = Reference; + value.WriteToUnmanagedMemory(PInvokeHelper.AbsoluteOffsetOf(reference, "generic")); + Reference = reference; + } + } + + /// + /// Gets the font bounding box. Coordinates are expressed in font units (see ‘units_per_EM’). The box is large + /// enough to contain any glyph from the font. Thus, ‘bbox.yMax’ can be seen as the ‘maximal ascender’, and + /// ‘bbox.yMin’ as the ‘minimal descender’. Only relevant for scalable formats. + /// + /// Note that the bounding box might be off by (at least) one pixel for hinted fonts. See FT_Size_Metrics for + /// further discussion. + /// + public BBox BBox + { + get + { + if (disposed) + throw new ObjectDisposedException("BBox", "Cannot access a disposed object."); + + return rec.bbox; + } + } + + /// + /// Gets the number of font units per EM square for this face. This is typically 2048 for TrueType fonts, and + /// 1000 for Type 1 fonts. Only relevant for scalable formats. + /// + [CLSCompliant(false)] + public ushort UnitsPerEM + { + get + { + if (disposed) + throw new ObjectDisposedException("UnitsPerEM", "Cannot access a disposed object."); + + return rec.units_per_EM; + } + } + + /// + /// Gets the typographic ascender of the face, expressed in font units. For font formats not having this + /// information, it is set to ‘bbox.yMax’. Only relevant for scalable formats. + /// + public short Ascender + { + get + { + if (disposed) + throw new ObjectDisposedException("Ascender", "Cannot access a disposed object."); + + return rec.ascender; + } + } + + /// + /// Gets the typographic descender of the face, expressed in font units. For font formats not having this + /// information, it is set to ‘bbox.yMin’.Note that this field is usually negative. Only relevant for scalable + /// formats. + /// + public short Descender + { + get + { + if (disposed) + throw new ObjectDisposedException("Descender", "Cannot access a disposed object."); + + return rec.descender; + } + } + + /// + /// Gets the height is the vertical distance between two consecutive baselines, expressed in font units. It is + /// always positive. Only relevant for scalable formats. + /// + public short Height + { + get + { + if (disposed) + throw new ObjectDisposedException("Height", "Cannot access a disposed object."); + + return rec.height; + } + } + + /// + /// Gets the maximal advance width, in font units, for all glyphs in this face. This can be used to make word + /// wrapping computations faster. Only relevant for scalable formats. + /// + public short MaxAdvanceWidth + { + get + { + if (disposed) + throw new ObjectDisposedException("MaxAdvanceWidth", "Cannot access a disposed object."); + + return rec.max_advance_width; + } + } + + /// + /// Gets the maximal advance height, in font units, for all glyphs in this face. This is only relevant for + /// vertical layouts, and is set to ‘height’ for fonts that do not provide vertical metrics. Only relevant for + /// scalable formats. + /// + public short MaxAdvanceHeight + { + get + { + if (disposed) + throw new ObjectDisposedException("MaxAdvanceHeight", "Cannot access a disposed object."); + + return rec.max_advance_height; + } + } + + /// + /// Gets the position, in font units, of the underline line for this face. It is the center of the underlining + /// stem. Only relevant for scalable formats. + /// + public short UnderlinePosition + { + get + { + if (disposed) + throw new ObjectDisposedException("UnderlinePosition", "Cannot access a disposed object."); + + return rec.underline_position; + } + } + + /// + /// Gets the thickness, in font units, of the underline for this face. Only relevant for scalable formats. + /// + public short UnderlineThickness + { + get + { + if (disposed) + throw new ObjectDisposedException("UnderlineThickness", "Cannot access a disposed object."); + + return rec.underline_thickness; + } + } + + /// + /// Gets the face's associated glyph slot(s). + /// + public GlyphSlot Glyph + { + get + { + if (disposed) + throw new ObjectDisposedException("Glyph", "Cannot access a disposed object."); + + return new GlyphSlot(rec.glyph, this, parentLibrary); + } + } + + /// + /// Gets the current active size for this face. + /// + public FTSize Size + { + get + { + if (disposed) + throw new ObjectDisposedException("Size", "Cannot access a disposed object."); + + return new FTSize(rec.size, false, this); + } + } + + /// + /// Gets the current active charmap for this face. + /// + public CharMap CharMap + { + get + { + if (disposed) + throw new ObjectDisposedException("CharMap", "Cannot access a disposed object."); + + if (rec.charmap == IntPtr.Zero) + return null; + + return new CharMap(rec.charmap, this); + } + } + + /// + /// Gets a value indicating whether a face object contains horizontal metrics (this is true for all font + /// formats though). + /// + public bool HasHoriziontal + { + get + { + return (FaceFlags & FaceFlags.Horizontal) == FaceFlags.Horizontal; + } + } + + /// + /// Gets a value indicating whether a face object contains vertical metrics. + /// + public bool HasVertical + { + get + { + return (FaceFlags & FaceFlags.Vertical) == FaceFlags.Vertical; + } + } + + /// + /// Gets a value indicating whether a face object contains kerning data that can be accessed with + /// . + /// + public bool HasKerning + { + get + { + return (FaceFlags & FaceFlags.Kerning) == FaceFlags.Kerning; + } + } + + /// + /// Gets a value indicating whether a face object contains a scalable font face (true for TrueType, Type 1, + /// Type 42, CID, OpenType/CFF, and PFR font formats. + /// + public bool IsScalable + { + get + { + return (FaceFlags & FaceFlags.Scalable) == FaceFlags.Scalable; + } + } + + /// + /// Gets a value indicating whether a face object contains a font whose format is based on the SFNT storage + /// scheme. This usually means: TrueType fonts, OpenType fonts, as well as SFNT-based embedded bitmap fonts. + /// + /// If this macro is true, all functions defined in FT_SFNT_NAMES_H and FT_TRUETYPE_TABLES_H are available. + /// + public bool IsSfnt + { + get + { + return (FaceFlags & FaceFlags.Sfnt) == FaceFlags.Sfnt; + } + } + + /// + /// Gets a value indicating whether a face object contains a font face that contains fixed-width (or + /// ‘monospace’, ‘fixed-pitch’, etc.) glyphs. + /// + public bool IsFixedWidth + { + get + { + return (FaceFlags & FaceFlags.FixedWidth) == FaceFlags.FixedWidth; + } + } + + /// + /// Gets a value indicating whether a face object contains some embedded bitmaps. + /// + /// + public bool HasFixedSizes + { + get + { + return (FaceFlags & FaceFlags.FixedSizes) == FaceFlags.FixedSizes; + } + } + + /// + /// Gets a value indicating whether a face object contains some glyph names that can be accessed through + /// . + /// + public bool HasGlyphNames + { + get + { + return (FaceFlags & FaceFlags.GlyphNames) == FaceFlags.GlyphNames; + } + } + + /// + /// Gets a value indicating whether a face object contains some multiple masters. The functions provided by + /// FT_MULTIPLE_MASTERS_H are then available to choose the exact design you want. + /// + public bool HasMultipleMasters + { + get + { + return (FaceFlags & FaceFlags.MultipleMasters) == FaceFlags.MultipleMasters; + } + } + + /// + /// Gets a value indicating whether a face object contains a CID-keyed font. See the discussion of + /// FT_FACE_FLAG_CID_KEYED for more details. + /// + /// If this macro is true, all functions defined in FT_CID_H are available. + /// + public bool IsCidKeyed + { + get + { + return (FaceFlags & FaceFlags.CidKeyed) == FaceFlags.CidKeyed; + } + } + + /// + /// Gets a value indicating whether a face represents a ‘tricky’ font. See the discussion of + /// FT_FACE_FLAG_TRICKY for more details. + /// + public bool IsTricky + { + get + { + return (FaceFlags & FaceFlags.Tricky) == FaceFlags.Tricky; + } + } + + /// + /// Gets a value indicating whether the font has color glyph tables. + /// + public bool HasColor + { + get + { + return (FaceFlags & FaceFlags.Color) == FaceFlags.Color; + } + } + + /// + /// Gets or sets an object used to identify this instance of . This object will not be + /// modified or accessed internally. + /// + /// + /// 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. + /// + public object Tag { get; set; } + + internal override IntPtr Reference + { + get + { + if (disposed) + throw new ObjectDisposedException("Reference", "Cannot access a disposed object."); + + return base.Reference; + } + + set + { + if (disposed) + throw new ObjectDisposedException("Reference", "Cannot access a disposed object."); + + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + + #region Methods + + #region FreeType Version + + /// + /// Parse all bytecode instructions of a TrueType font file to check whether any of the patented opcodes are + /// used. This is only useful if you want to be able to use the unpatented hinter with fonts that do not use + /// these opcodes. + /// + /// Note that this function parses all glyph instructions in the font file, which may be slow. + /// + /// + /// Since May 2010, TrueType hinting is no longer patented. + /// + /// True if this is a TrueType font that uses one of the patented opcodes, false otherwise. + public bool CheckTrueTypePatents() + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Face_CheckTrueTypePatents(Reference); + } + + /// + /// Enable or disable the unpatented hinter for a given . Only enable it if you have + /// determined that the face doesn't use any patented opcodes. + /// + /// + /// Since May 2010, TrueType hinting is no longer patented. + /// + /// New boolean setting. + /// + /// The old setting value. This will always be false if this is not an SFNT font, or if the unpatented hinter + /// is not compiled in this instance of the library. + /// + /// + public bool SetUnpatentedHinting(bool value) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Face_SetUnpatentedHinting(Reference, value); + } + + #endregion + + #region Base Interface + + /// + /// This function calls to attach a file. + /// + /// The pathname. + public void AttachFile(string path) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Attach_File(Reference, path); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// ‘Attach’ data to a face object. Normally, this is used to read additional information for the face object. + /// For example, you can attach an AFM file that comes with a Type 1 font to get the kerning values and other + /// metrics. + /// + /// + /// The meaning of the ‘attach’ (i.e., what really happens when the new file is read) is not fixed by FreeType + /// itself. It really depends on the font format (and thus the font driver). + /// + /// Client applications are expected to know what they are doing when invoking this function. Most drivers + /// simply do not implement file attachments. + /// + /// A pointer to which must be filled by the caller. + public void AttachStream(OpenArgs parameters) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Attach_Stream(Reference, parameters.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Select a bitmap strike. + /// + /// + /// The index of the bitmap strike in the field of + /// structure. + /// + public void SelectSize(int strikeIndex) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Select_Size(Reference, strikeIndex); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Resize the scale of the active object in a face. + /// + /// A pointer to a . + public unsafe void RequestSize(SizeRequest request) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Request_Size(Reference, (IntPtr)(&request)); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// This function calls to request the nominal size (in points). + /// + /// + /// If either the character width or height is zero, it is set equal to the other value. + /// + /// If either the horizontal or vertical resolution is zero, it is set equal to the other value. + /// + /// A character width or height smaller than 1pt is set to 1pt; if both resolution values are zero, they are + /// set to 72dpi. + /// + /// The nominal width, in 26.6 fractional points. + /// The nominal height, in 26.6 fractional points. + /// The horizontal resolution in dpi. + /// The vertical resolution in dpi. + [CLSCompliant(false)] + public void SetCharSize(Fixed26Dot6 width, Fixed26Dot6 height, uint horizontalResolution, uint verticalResolution) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Set_Char_Size(Reference, (IntPtr)width.Value, (IntPtr)height.Value, horizontalResolution, verticalResolution); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// This function calls to request the nominal size (in pixels). + /// + /// The nominal width, in pixels. + /// The nominal height, in pixels + [CLSCompliant(false)] + public void SetPixelSizes(uint width, uint height) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Set_Pixel_Sizes(Reference, width, height); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// A function used to load a single glyph into the glyph slot of a face object. + /// + /// + /// The loaded glyph may be transformed. See for the details. + /// + /// For subsetted CID-keyed fonts, is returned for invalid CID values (this + /// is, for CID values which don't have a corresponding glyph in the font). See the discussion of the + /// flag for more details. + /// + /// + /// The index of the glyph in the font file. For CID-keyed fonts (either in PS or in CFF format) this argument + /// specifies the CID value. + /// + /// + /// A flag indicating what to load for this glyph. The constants can be used to control + /// the glyph loading process (e.g., whether the outline should be scaled, whether to load bitmaps or not, + /// whether to hint the outline, etc). + /// + /// The target to OR with the flags. + [CLSCompliant(false)] + public void LoadGlyph(uint glyphIndex, LoadFlags flags, LoadTarget target) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Load_Glyph(Reference, glyphIndex, (int)flags | (int)target); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// A function used to load a single glyph into the glyph slot of a face object, according to its character + /// code. + /// + /// + /// This function simply calls and + /// + /// + /// The glyph's character code, according to the current charmap used in the face. + /// + /// + /// A flag indicating what to load for this glyph. The constants can be used to control + /// the glyph loading process (e.g., whether the outline should be scaled, whether to load bitmaps or not, + /// whether to hint the outline, etc). + /// + /// The target to OR with the flags. + [CLSCompliant(false)] + public void LoadChar(uint charCode, LoadFlags flags, LoadTarget target) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Load_Char(Reference, charCode, (int)flags | (int)target); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// A function used to set the transformation that is applied to glyph images when they are loaded into a glyph + /// slot through . + /// + /// + /// The transformation is only applied to scalable image formats after the glyph has been loaded. It means that + /// hinting is unaltered by the transformation and is performed on the character size given in the last call to + /// or . + /// + /// Note that this also transforms the ‘face.glyph.advance’ field, but not the values in ‘face.glyph.metrics’. + /// + /// + /// A pointer to the transformation's 2x2 matrix. Use the method overloads for the identity matrix. + /// + /// + /// A pointer to the translation vector. Use the method overloads for the null vector. + /// + public unsafe void SetTransform(FTMatrix matrix, FTVector delta) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + FT.FT_Set_Transform(Reference, (IntPtr)(&matrix), (IntPtr)(&delta)); + } + + /// + /// A function used to set the transformation that is applied to glyph images when they are loaded into a glyph + /// slot through with the identity matrix. + /// + /// + /// The transformation is only applied to scalable image formats after the glyph has been loaded. It means that + /// hinting is unaltered by the transformation and is performed on the character size given in the last call to + /// or . + /// + /// Note that this also transforms the ‘face.glyph.advance’ field, but not the values in ‘face.glyph.metrics’. + /// + /// + /// A pointer to the translation vector. Use the method overloads for the null vector. + /// + public unsafe void SetTransform(FTVector delta) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + FT.FT_Set_Transform(Reference, IntPtr.Zero, (IntPtr)(&delta)); + } + + /// + /// A function used to set the transformation that is applied to glyph images when they are loaded into a glyph + /// slot through with the null vector. + /// + /// + /// The transformation is only applied to scalable image formats after the glyph has been loaded. It means that + /// hinting is unaltered by the transformation and is performed on the character size given in the last call to + /// or . + /// + /// Note that this also transforms the ‘face.glyph.advance’ field, but not the values in ‘face.glyph.metrics’. + /// + /// + /// A pointer to the transformation's 2x2 matrix. Use the method overloads for the identity matrix. + /// + public unsafe void SetTransform(FTMatrix matrix) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + FT.FT_Set_Transform(Reference, (IntPtr)(&matrix), IntPtr.Zero); + } + + /// + /// A function used to set the transformation that is applied to glyph images when they are loaded into a glyph + /// slot through with the null vector and the identity matrix. + /// + /// + /// The transformation is only applied to scalable image formats after the glyph has been loaded. It means that + /// hinting is unaltered by the transformation and is performed on the character size given in the last call to + /// or . + /// + /// Note that this also transforms the ‘face.glyph.advance’ field, but not the values in ‘face.glyph.metrics’. + /// + public unsafe void SetTransform() + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + FT.FT_Set_Transform(Reference, IntPtr.Zero, IntPtr.Zero); + } + + /// + /// Return the kerning vector between two glyphs of a same face. + /// + /// + /// Only horizontal layouts (left-to-right & right-to-left) are supported by this method. Other layouts, or + /// more sophisticated kernings, are out of the scope of this API function -- they can be implemented through + /// format-specific interfaces. + /// + /// The index of the left glyph in the kern pair. + /// The index of the right glyph in the kern pair. + /// Determines the scale and dimension of the returned kerning vector. + /// + /// The kerning vector. This is either in font units or in pixels (26.6 format) for scalable formats, and in + /// pixels for fixed-sizes formats. + /// + [CLSCompliant(false)] + public FTVector26Dot6 GetKerning(uint leftGlyph, uint rightGlyph, KerningMode mode) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + FTVector26Dot6 kern; + Error err = FT.FT_Get_Kerning(Reference, leftGlyph, rightGlyph, (uint)mode, out kern); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return kern; + } + + /// + /// Return the track kerning for a given face object at a given size. + /// + /// The point size in 16.16 fractional points. + /// The degree of tightness. + /// The kerning in 16.16 fractional points. + public Fixed16Dot16 GetTrackKerning(Fixed16Dot16 pointSize, int degree) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + IntPtr kerning; + + Error err = FT.FT_Get_Track_Kerning(Reference, (IntPtr)pointSize.Value, degree, out kerning); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return Fixed16Dot16.FromRawValue((int)kerning); + } + + /// + /// Retrieve the ASCII name of a given glyph in a face. This only works for those faces where + /// returns 1. + /// + /// + /// An error is returned if the face doesn't provide glyph names or if the glyph index is invalid. In all cases + /// of failure, the first byte of ‘buffer’ is set to 0 to indicate an empty name. + /// + /// The glyph name is truncated to fit within the buffer if it is too long. The returned string is always + /// zero-terminated. + /// + /// Be aware that FreeType reorders glyph indices internally so that glyph index 0 always corresponds to the + /// ‘missing glyph’ (called ‘.notdef’). + /// + /// This function is not compiled within the library if the config macro ‘FT_CONFIG_OPTION_NO_GLYPH_NAMES’ is + /// defined in ‘include/freetype/config/ftoptions.h’. + /// + /// The glyph index. + /// The maximal number of bytes available in the buffer. + /// The ASCII name of a given glyph in a face. + [CLSCompliant(false)] + public string GetGlyphName(uint glyphIndex, int bufferSize) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return GetGlyphName(glyphIndex, new byte[bufferSize]); + } + + /// + /// Retrieve the ASCII name of a given glyph in a face. This only works for those faces where + /// returns 1. + /// + /// + /// An error is returned if the face doesn't provide glyph names or if the glyph index is invalid. In all cases + /// of failure, the first byte of ‘buffer’ is set to 0 to indicate an empty name. + /// + /// The glyph name is truncated to fit within the buffer if it is too long. The returned string is always + /// zero-terminated. + /// + /// Be aware that FreeType reorders glyph indices internally so that glyph index 0 always corresponds to the + /// ‘missing glyph’ (called ‘.notdef’). + /// + /// This function is not compiled within the library if the config macro ‘FT_CONFIG_OPTION_NO_GLYPH_NAMES’ is + /// defined in ‘include/freetype/config/ftoptions.h’. + /// + /// The glyph index. + /// The target buffer where the name is copied to. + /// The ASCII name of a given glyph in a face. + [CLSCompliant(false)] + public unsafe string GetGlyphName(uint glyphIndex, byte[] buffer) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + fixed (byte* ptr = buffer) + { + IntPtr intptr = new IntPtr(ptr); + Error err = FT.FT_Get_Glyph_Name(Reference, glyphIndex, intptr, (uint)buffer.Length); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return Marshal.PtrToStringAnsi(intptr); + } + } + + /// + /// Retrieve the ASCII Postscript name of a given face, if available. This only works with Postscript and + /// TrueType fonts. + /// + /// + /// The returned pointer is owned by the face and is destroyed with it. + /// + /// A pointer to the face's Postscript name. NULL if unavailable. + public string GetPostscriptName() + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return Marshal.PtrToStringAnsi(FT.FT_Get_Postscript_Name(Reference)); + } + + /// + /// Select a given charmap by its encoding tag (as listed in ‘freetype.h’). + /// + /// + /// This function returns an error if no charmap in the face corresponds to the encoding queried here. + /// + /// Because many fonts contain more than a single cmap for Unicode encoding, this function has some special + /// code to select the one which covers Unicode best. It is thus preferable to in + /// this case. + /// + /// A handle to the selected encoding. + [CLSCompliant(false)] + public void SelectCharmap(Encoding encoding) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Select_Charmap(Reference, encoding); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Select a given charmap for character code to glyph index mapping. + /// + /// + /// This function returns an error if the charmap is not part of the face (i.e., if it is not listed in the + /// ’ table). + /// + /// A handle to the selected charmap. + public void SetCharmap(CharMap charmap) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + Error err = FT.FT_Set_Charmap(Reference, charmap.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Return the glyph index of a given character code. This function uses a charmap object to do the mapping. + /// + /// + /// If you use FreeType to manipulate the contents of font files directly, be aware that the glyph index + /// returned by this function doesn't always correspond to the internal indices used within the file. This is + /// done to ensure that value 0 always corresponds to the ‘missing glyph’. + /// + /// The character code. + /// The glyph index. 0 means ‘undefined character code’. + [CLSCompliant(false)] + public uint GetCharIndex(uint charCode) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Get_Char_Index(Reference, charCode); + } + + /// + /// This function is used to return the first character code in the current charmap of a given face. It also + /// returns the corresponding glyph index. + /// + /// + /// You should use this function with to be able to parse all character codes + /// available in a given charmap. + /// + /// Note that ‘agindex’ is set to 0 if the charmap is empty. The result itself can be 0 in two cases: if the + /// charmap is empty or when the value 0 is the first valid character code. + /// + /// Glyph index of first character code. 0 if charmap is empty. + /// The charmap's first character code. + [CLSCompliant(false)] + public uint GetFirstChar(out uint glyphIndex) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Get_First_Char(Reference, out glyphIndex); + } + + /// + /// This function is used to return the next character code in the current charmap of a given face following + /// the value ‘charCode’, as well as the corresponding glyph index. + /// + /// + /// You should use this function with to walk over all character codes available + /// in a given charmap. See the note for this function for a simple code example. + /// + /// Note that ‘*agindex’ is set to 0 when there are no more codes in the charmap. + /// + /// The starting character code. + /// Glyph index of first character code. 0 if charmap is empty. + /// The charmap's next character code. + [CLSCompliant(false)] + public uint GetNextChar(uint charCode, out uint glyphIndex) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Get_Next_Char(Reference, charCode, out glyphIndex); + } + + /// + /// Return the glyph index of a given glyph name. This function uses driver specific objects to do the + /// translation. + /// + /// The glyph name. + /// The glyph index. 0 means ‘undefined character code’. + [CLSCompliant(false)] + public uint GetNameIndex(string name) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Get_Name_Index(Reference, Marshal.StringToHGlobalAnsi(name)); + } + + /// + /// Return the flags for a font. + /// + /// + /// Use this function rather than directly reading the ‘fs_type’ field in the + /// structure which is only guaranteed to return the correct results for Type 1 fonts. + /// + /// The fsType flags, . + [CLSCompliant(false)] + public EmbeddingTypes GetFSTypeFlags() + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Get_FSType_Flags(Reference); + } + + #endregion + + #region Glyph Variants + + /// + /// Return the glyph index of a given character code as modified by the variation selector. + /// + /// + /// If you use FreeType to manipulate the contents of font files directly, be aware that the glyph index + /// returned by this function doesn't always correspond to the internal indices used within the file. This is + /// done to ensure that value 0 always corresponds to the ‘missing glyph’. + /// + /// This function is only meaningful if a) the font has a variation selector cmap sub table, and b) the current + /// charmap has a Unicode encoding. + /// + /// The character code point in Unicode. + /// The Unicode code point of the variation selector. + /// + /// The glyph index. 0 means either ‘undefined character code’, or ‘undefined selector code’, or ‘no variation + /// selector cmap subtable’, or ‘current CharMap is not Unicode’. + /// + [CLSCompliant(false)] + public uint GetCharVariantIndex(uint charCode, uint variantSelector) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Face_GetCharVariantIndex(Reference, charCode, variantSelector); + } + + /// + /// Check whether this variant of this Unicode character is the one to be found in the ‘cmap’. + /// + /// + /// This function is only meaningful if the font has a variation selector cmap subtable. + /// + /// The character codepoint in Unicode. + /// The Unicode codepoint of the variation selector. + /// + /// 1 if found in the standard (Unicode) cmap, 0 if found in the variation selector cmap, or -1 if it is not a + /// variant. + /// + [CLSCompliant(false)] + public int GetCharVariantIsDefault(uint charCode, uint variantSelector) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + return FT.FT_Face_GetCharVariantIsDefault(Reference, charCode, variantSelector); + } + + /// + /// Return a zero-terminated list of Unicode variant selectors found in the font. + /// + /// + /// The last item in the array is 0; the array is owned by the object but can be overwritten + /// or released on the next call to a FreeType function. + /// + /// + /// A pointer to an array of selector code points, or NULL if there is no valid variant selector cmap subtable. + /// + [CLSCompliant(false)] + public uint[] GetVariantSelectors() + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + IntPtr ptr = FT.FT_Face_GetVariantSelectors(Reference); + + List list = new List(); + + //temporary non-zero value to prevent complaining about uninitialized variable. + uint curValue = 1; + + for (int i = 0; curValue != 0; i++) + { + curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i); + list.Add(curValue); + } + + return list.ToArray(); + } + + /// + /// Return a zero-terminated list of Unicode variant selectors found in the font. + /// + /// + /// The last item in the array is 0; the array is owned by the object but can be overwritten + /// or released on the next call to a FreeType function. + /// + /// The character codepoint in Unicode. + /// + /// A pointer to an array of variant selector code points which are active for the given character, or NULL if + /// the corresponding list is empty. + /// + [CLSCompliant(false)] + public uint[] GetVariantsOfChar(uint charCode) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + IntPtr ptr = FT.FT_Face_GetVariantsOfChar(Reference, charCode); + + List list = new List(); + + //temporary non-zero value to prevent complaining about uninitialized variable. + uint curValue = 1; + + for (int i = 0; curValue != 0; i++) + { + curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i); + list.Add(curValue); + } + + return list.ToArray(); + } + + /// + /// Return a zero-terminated list of Unicode character codes found for the specified variant selector. + /// + /// + /// The last item in the array is 0; the array is owned by the object but can be overwritten + /// or released on the next call to a FreeType function. + /// + /// The variant selector code point in Unicode. + /// + /// A list of all the code points which are specified by this selector (both default and non-default codes are + /// returned) or NULL if there is no valid cmap or the variant selector is invalid. + /// + [CLSCompliant(false)] + public uint[] GetCharsOfVariant(uint variantSelector) + { + if (disposed) + throw new ObjectDisposedException("face", "Cannot access a disposed object."); + + IntPtr ptr = FT.FT_Face_GetCharsOfVariant(Reference, variantSelector); + + List list = new List(); + + //temporary non-zero value to prevent complaining about uninitialized variable. + uint curValue = 1; + + for (int i = 0; curValue != 0; i++) + { + curValue = (uint)Marshal.ReadInt32(Reference, sizeof(uint) * i); + list.Add(curValue); + } + + return list.ToArray(); + } + + #endregion + + #region Size Management + + /// + /// Create a new size object from a given face object. + /// + /// + /// You need to call in order to select the new size for upcoming calls to + /// , , , , + /// etc. + /// + /// A handle to a new size object. + public FTSize NewSize() + { + return new FTSize(this); + } + + #endregion + + #region Multiple Masters + + /// + /// Retrieve the Multiple Master descriptor of a given font. + /// + /// This function can't be used with GX fonts. + /// + /// The Multiple Masters descriptor. + public MultiMaster GetMultiMaster() + { + IntPtr masterRef; + Error err = FT.FT_Get_Multi_Master(Reference, out masterRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new MultiMaster(masterRef); + } + + /// + /// Retrieve the Multiple Master/GX var descriptor of a given font. + /// + /// + /// The Multiple Masters/GX var descriptor. Allocates a data structure, which the user must free (a single call + /// to FT_FREE will do it). + /// + public MMVar GetMMVar() + { + IntPtr varRef; + Error err = FT.FT_Get_MM_Var(Reference, out varRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new MMVar(varRef); + } + + /// + /// For Multiple Masters fonts, choose an interpolated font design through design coordinates. + /// + /// This function can't be used with GX fonts. + /// + /// An array of design coordinates. + public unsafe void SetMMDesignCoordinates(long[] coords) + { + fixed (void* ptr = coords) + { + IntPtr coordsPtr = (IntPtr)ptr; + Error err = FT.FT_Set_MM_Design_Coordinates(Reference, (uint)coords.Length, coordsPtr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + } + + /// + /// For Multiple Master or GX Var fonts, choose an interpolated font design through design coordinates. + /// + /// An array of design coordinates. + public unsafe void SetVarDesignCoordinates(long[] coords) + { + fixed (void* ptr = coords) + { + IntPtr coordsPtr = (IntPtr)ptr; + Error err = FT.FT_Set_Var_Design_Coordinates(Reference, (uint)coords.Length, coordsPtr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + } + + /// + /// For Multiple Masters and GX var fonts, choose an interpolated font design through normalized blend + /// coordinates. + /// + /// The design coordinates array (each element must be between 0 and 1.0). + public unsafe void SetMMBlendCoordinates(long[] coords) + { + fixed (void* ptr = coords) + { + IntPtr coordsPtr = (IntPtr)ptr; + Error err = FT.FT_Set_MM_Blend_Coordinates(Reference, (uint)coords.Length, coordsPtr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + } + + /// + /// This is another name of . + /// + /// The design coordinates array (each element must be between 0 and 1.0). + public unsafe void SetVarBlendCoordinates(long[] coords) + { + fixed (void* ptr = coords) + { + IntPtr coordsPtr = (IntPtr)ptr; + Error err = FT.FT_Set_Var_Blend_Coordinates(Reference, (uint)coords.Length, coordsPtr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + } + + #endregion + + #region TrueType Tables + + /// + /// Return a pointer to a given SFNT table within a face. + /// + /// + /// The table is owned by the face object and disappears with it. + /// + /// This function is only useful to access SFNT tables that are loaded by the sfnt, truetype, and opentype + /// drivers. See for a list. + /// + /// The index of the SFNT table. + /// + /// A type-less pointer to the table. This will be 0 in case of error, or if the corresponding table was not + /// found OR loaded from the file. + /// + /// Use a typecast according to ‘tag’ to access the structure elements. + /// + public object GetSfntTable(SfntTag tag) + { + IntPtr tableRef = FT.FT_Get_Sfnt_Table(Reference, tag); + + if (tableRef == IntPtr.Zero) + return null; + + switch (tag) + { + case SfntTag.Header: + return new Header(tableRef); + case SfntTag.HorizontalHeader: + return new HoriHeader(tableRef); + case SfntTag.MaxProfile: + return new MaxProfile(tableRef); + case SfntTag.OS2: + return new OS2(tableRef); + case SfntTag.Pclt: + return new Pclt(tableRef); + case SfntTag.Postscript: + return new Postscript(tableRef); + case SfntTag.VertHeader: + return new VertHeader(tableRef); + default: + return null; + } + } + + /// + /// Load any font table into client memory. + /// + /// + /// If you need to determine the table's length you should first call this function with ‘*length’ set to 0, as + /// in the following example: + /// + /// FT_ULong length = 0; + /// + /// + /// error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length ); + /// if ( error ) { ... table does not exist ... } + /// + /// buffer = malloc( length ); + /// if ( buffer == NULL ) { ... not enough memory ... } + /// + /// error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length ); + /// if ( error ) { ... could not load table ... } + /// + /// + /// + /// The four-byte tag of the table to load. Use the value 0 if you want to access the whole font file. + /// Otherwise, you can use one of the definitions found in the FT_TRUETYPE_TAGS_H file, or forge a new one with + /// FT_MAKE_TAG. + /// + /// The starting offset in the table (or file if tag == 0). + /// + /// The target buffer address. The client must ensure that the memory array is big enough to hold the data. + /// + /// + /// If the ‘length’ parameter is NULL, then try to load the whole table. Return an error code if it fails. + /// + /// Else, if ‘*length’ is 0, exit immediately while returning the table's (or file) full size in it. + /// + /// Else the number of bytes to read from the table or file, from the starting offset. + /// + [CLSCompliant(false)] + public void LoadSfntTable(uint tag, int offset, IntPtr buffer, ref uint length) + { + Error err = FT.FT_Load_Sfnt_Table(Reference, tag, offset, buffer, ref length); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Return information on an SFNT table. + /// + /// + /// The index of an SFNT table. The function returns for an invalid value. + /// + /// + /// The name tag of the SFNT table. If the value is NULL, ‘table_index’ is ignored, and ‘length’ returns the + /// number of SFNT tables in the font. + /// + /// The length of the SFNT table (or the number of SFNT tables, depending on ‘tag’). + [CLSCompliant(false)] + public unsafe uint SfntTableInfo(uint tableIndex, SfntTag tag) + { + uint length; + Error err = FT.FT_Sfnt_Table_Info(Reference, tableIndex, &tag, out length); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return length; + } + + /// + /// Only gets the number of SFNT tables. + /// + /// The number of SFNT tables. + [CLSCompliant(false)] + public unsafe uint SfntTableInfo() + { + uint length; + Error err = FT.FT_Sfnt_Table_Info(Reference, 0, null, out length); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return length; + } + + #endregion + + #region Type 1 Tables + + /// + /// Return true if a given face provides reliable PostScript glyph names. This is similar to using the + /// macro, except that certain fonts (mostly TrueType) contain incorrect + /// glyph name tables. + /// + /// When this function returns true, the caller is sure that the glyph names returned by + /// are reliable. + /// + /// Boolean. True if glyph names are reliable. + public bool HasPSGlyphNames() + { + return FT.FT_Has_PS_Glyph_Names(Reference); + } + + /// + /// Retrieve the structure corresponding to a given PostScript font. + /// + /// + /// The string pointers within the font info structure are owned by the face and don't need to be freed by the + /// caller. + /// + /// If the font's format is not PostScript-based, this function will return the + /// error code. + /// + /// Output font info structure pointer. + public FontInfo GetPSFontInfo() + { + PostScript.Internal.FontInfoRec fontInfoRec; + Error err = FT.FT_Get_PS_Font_Info(Reference, out fontInfoRec); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new FontInfo(fontInfoRec); + } + + /// + /// Retrieve the structure corresponding to a given PostScript font. + /// + /// + /// The string pointers within the structure are owned by the face and don't + /// need to be freed by the caller. + /// + /// If the font's format is not PostScript-based, this function returns the + /// error code. + /// + /// Output private dictionary structure pointer. + public Private GetPSFontPrivate() + { + PostScript.Internal.PrivateRec privateRec; + Error err = FT.FT_Get_PS_Font_Private(Reference, out privateRec); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Private(privateRec); + } + + /// + /// Retrieve the value for the supplied key from a PostScript font. + /// + /// + /// The values returned are not pointers into the internal structures of the face, but are ‘fresh’ copies, so + /// that the memory containing them belongs to the calling application. This also enforces the ‘read-only’ + /// nature of these values, i.e., this function cannot be used to manipulate the face. + /// + /// ‘value’ is a void pointer because the values returned can be of various types. + /// + /// If either ‘value’ is NULL or ‘value_len’ is too small, just the required memory size for the requested + /// entry is returned. + /// + /// The ‘idx’ parameter is used, not only to retrieve elements of, for example, the FontMatrix or FontBBox, but + /// also to retrieve name keys from the CharStrings dictionary, and the charstrings themselves. It is ignored + /// for atomic values. + /// + /// returns a value that is scaled up by 1000. To get the + /// value as in the font stream, you need to divide by 65536000.0 (to remove the FT_Fixed scale, and the x1000 + /// scale). + /// + /// IMPORTANT: Only key/value pairs read by the FreeType interpreter can be retrieved. So, for example, + /// PostScript procedures such as NP, ND, and RD are not available. Arbitrary keys are, obviously, not be + /// available either. + /// + /// If the font's format is not PostScript-based, this function returns the + /// error code. + /// + /// An enumeration value representing the dictionary key to retrieve. + /// For array values, this specifies the index to be returned. + /// A pointer to memory into which to write the value. + /// The size, in bytes, of the memory supplied for the value. + /// + /// The amount of memory (in bytes) required to hold the requested value (if it exists, -1 otherwise). + /// + [CLSCompliant(false)] + public int GetPSFontValue(DictionaryKeys key, uint idx, ref IntPtr value, int valueLength) + { + return FT.FT_Get_PS_Font_Value(Reference, key, idx, ref value, valueLength); + } + + #endregion + + #region SFNT Names + + /// + /// Retrieve the number of name strings in the SFNT ‘name’ table. + /// + /// The number of strings in the ‘name’ table. + [CLSCompliant(false)] + public uint GetSfntNameCount() + { + return FT.FT_Get_Sfnt_Name_Count(Reference); + } + + /// + /// Retrieve a string of the SFNT ‘name’ table for a given index. + /// + /// + /// The ‘string’ array returned in the ‘aname’ structure is not null-terminated. The application should + /// deallocate it if it is no longer in use. + /// + /// Use to get the total number of available ‘name’ table entries, then do a + /// loop until you get the right platform, encoding, and name ID. + /// + /// The index of the ‘name’ string. + /// The indexed structure. + [CLSCompliant(false)] + public SfntName GetSfntName(uint idx) + { + TrueType.Internal.SfntNameRec nameRec; + + Error err = FT.FT_Get_Sfnt_Name(Reference, idx, out nameRec); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new SfntName(nameRec); + } + + #endregion + + #region BDF and PCF Files + + /// + /// Retrieve a BDF font character set identity, according to the BDF specification. + /// + /// + /// This function only works with BDF faces, returning an error otherwise. + /// + /// Charset encoding, as a C string, owned by the face. + /// Charset registry, as a C string, owned by the face. + public void GetBdfCharsetId(out string encoding, out string registry) + { + Error err = FT.FT_Get_BDF_Charset_ID(Reference, out encoding, out registry); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Retrieve a BDF property from a BDF or PCF font file. + /// + /// + /// This function works with BDF and PCF fonts. It returns an error otherwise. It also returns an error if the + /// property is not in the font. + /// + /// A ‘property’ is a either key-value pair within the STARTPROPERTIES ... ENDPROPERTIES block of a BDF font or + /// a key-value pair from the ‘info->props’ array within a ‘FontRec’ structure of a PCF font. + /// + /// Integer properties are always stored as ‘signed’ within PCF fonts; consequently, + /// is a possible return value for BDF fonts only. + /// + /// In case of error, ‘aproperty->type’ is always set to . + /// + /// The property name. + /// The property. + public Property GetBdfProperty(string propertyName) + { + IntPtr propertyRef; + + Error err = FT.FT_Get_BDF_Property(Reference, propertyName, out propertyRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Property(propertyRef); + } + + #endregion + + #region CID Fonts + + /// + /// Retrieve the Registry/Ordering/Supplement triple (also known as the "R/O/S") from a CID-keyed font. + /// + /// + /// This function only works with CID faces, returning an error otherwise. + /// + /// The registry, as a C string, owned by the face. + /// The ordering, as a C string, owned by the face. + /// The supplement. + public void GetCidRegistryOrderingSupplement(out string registry, out string ordering, out int supplement) + { + Error err = FT.FT_Get_CID_Registry_Ordering_Supplement(Reference, out registry, out ordering, out supplement); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Retrieve the type of the input face, CID keyed or not. In constrast to the + /// macro this function returns successfully also for CID-keyed fonts in an + /// SNFT wrapper. + /// + /// + /// This function only works with CID faces and OpenType fonts, returning an error otherwise. + /// + /// The type of the face as an FT_Bool. + public bool GetCidIsInternallyCidKeyed() + { + byte is_cid; + Error err = FT.FT_Get_CID_Is_Internally_CID_Keyed(Reference, out is_cid); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return is_cid == 1; + } + + /// + /// Retrieve the CID of the input glyph index. + /// + /// + /// This function only works with CID faces and OpenType fonts, returning an error otherwise. + /// + /// The input glyph index. + /// The CID as an uint. + [CLSCompliant(false)] + public uint GetCidFromGlyphIndex(uint glyphIndex) + { + uint cid; + Error err = FT.FT_Get_CID_From_Glyph_Index(Reference, glyphIndex, out cid); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return cid; + } + + #endregion + + #region PFR Fonts + + /// + /// Return the outline and metrics resolutions of a given PFR face. + /// + /// + /// If the input face is not a PFR, this function will return an error. However, in all cases, it will return + /// valid values. + /// + /// + /// Outline resolution. This is equivalent to ‘face->units_per_EM’ for non-PFR fonts. Optional (parameter can + /// be NULL). + /// + /// + /// Metrics resolution. This is equivalent to ‘outline_resolution’ for non-PFR fonts. Optional (parameter can + /// be NULL). + /// + /// + /// A 16.16 fixed-point number used to scale distance expressed in metrics units to device sub-pixels. This is + /// equivalent to ‘face->size->x_scale’, but for metrics only. Optional (parameter can be NULL). + /// + /// + /// Same as ‘ametrics_x_scale’ but for the vertical direction. optional (parameter can be NULL). + /// + [CLSCompliant(false)] + public void GetPfrMetrics(out uint outlineResolution, out uint metricsResolution, out Fixed16Dot16 metricsXScale, out Fixed16Dot16 metricsYScale) + { + IntPtr tmpXScale, tmpYScale; + Error err = FT.FT_Get_PFR_Metrics(Reference, out outlineResolution, out metricsResolution, out tmpXScale, out tmpYScale); + + metricsXScale = Fixed16Dot16.FromRawValue((int)tmpXScale); + metricsYScale = Fixed16Dot16.FromRawValue((int)tmpYScale); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Return the kerning pair corresponding to two glyphs in a PFR face. The distance is expressed in metrics + /// units, unlike the result of . + /// + /// + /// This function always return distances in original PFR metrics units. This is unlike + /// with the mode, which always returns + /// distances converted to outline units. + /// + /// You can use the value of the ‘x_scale’ and ‘y_scale’ parameters returned by to + /// scale these to device sub-pixels. + /// + /// Index of the left glyph. + /// Index of the right glyph. + /// A kerning vector. + [CLSCompliant(false)] + public FTVector GetPfrKerning(uint left, uint right) + { + FTVector vector; + Error err = FT.FT_Get_PFR_Kerning(Reference, left, right, out vector); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return vector; + } + + /// + /// Return a given glyph advance, expressed in original metrics units, from a PFR font. + /// + /// + /// You can use the ‘x_scale’ or ‘y_scale’ results of to convert the advance to + /// device sub-pixels (i.e., 1/64th of pixels). + /// + /// The glyph index. + /// The glyph advance in metrics units. + [CLSCompliant(false)] + public int GetPfrAdvance(uint glyphIndex) + { + int advance; + Error err = FT.FT_Get_PFR_Advance(Reference, glyphIndex, out advance); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return advance; + } + + #endregion + + #region Windows FNT Files + + /// + /// Retrieve a Windows FNT font info header. + /// + /// + /// This function only works with Windows FNT faces, returning an error otherwise. + /// + /// The WinFNT header. + public Fnt.Header GetWinFntHeader() + { + IntPtr headerRef; + Error err = FT.FT_Get_WinFNT_Header(Reference, out headerRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Fnt.Header(headerRef); + } + + #endregion + + #region Font Formats + + /// + /// Return a string describing the format of a given face, using values which can be used as an X11 + /// FONT_PROPERTY. Possible values are ‘TrueType’, ‘Type 1’, ‘BDF’, ‘PCF’, ‘Type 42’, ‘CID Type 1’, ‘CFF’, + /// ‘PFR’, and ‘Windows FNT’. + /// + /// Font format string. NULL in case of error. + public string GetX11FontFormat() + { + return Marshal.PtrToStringAnsi(FT.FT_Get_X11_Font_Format(Reference)); + } + + #endregion + + #region Gasp Table + + /// + /// Read the ‘gasp’ table from a TrueType or OpenType font file and return the entry corresponding to a given + /// character pixel size. + /// + /// The vertical character pixel size. + /// + /// Bit flags (see ), or if there is no ‘gasp’ table in the face. + /// + [CLSCompliant(false)] + public Gasp GetGasp(uint ppem) + { + return FT.FT_Get_Gasp(Reference, ppem); + } + + #endregion + + #region Quick retrieval of advance values + + /// + /// Retrieve the advance value of a given glyph outline in a . By default, the unhinted + /// advance is returned in font units. + /// + /// + /// This function may fail if you use and if the corresponding font + /// backend doesn't have a quick way to retrieve the advances. + /// + /// A scaled advance is returned in 16.16 format but isn't transformed by the affine transformation specified + /// by . + /// + /// The glyph index. + /// + /// A set of bit flags similar to those used when calling , used to determine what kind + /// of advances you need. + /// + /// + /// The advance value, in either font units or 16.16 format. + /// + /// If is set, this is the vertical advance corresponding to a vertical + /// layout. Otherwise, it is the horizontal advance in a horizontal layout. + /// + [CLSCompliant(false)] + public Fixed16Dot16 GetAdvance(uint glyphIndex, LoadFlags flags) + { + IntPtr padvance; + Error err = FT.FT_Get_Advance(Reference, glyphIndex, flags, out padvance); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return Fixed16Dot16.FromRawValue((int)padvance); + } + + /// + /// Retrieve the advance values of several glyph outlines in an + /// . By default, the unhinted advances are returned + /// in font units. + /// + /// + /// This function may fail if you use + /// and if the + /// corresponding font backend doesn't have a quick way to retrieve the + /// advances. + /// + /// Scaled advances are returned in 16.16 format but aren't transformed + /// by the affine transformation specified by + /// . + /// + /// The first glyph index. + /// The number of advance values you want to retrieve. + /// A set of bit flags similar to those used when calling . + /// The advances, in either font units or 16.16 format. This array must contain at least ‘count’ elements. + /// + /// If is set, these are the vertical advances corresponding to a vertical layout. Otherwise, they are the horizontal advances in a horizontal layout. + [CLSCompliant(false)] + public unsafe Fixed16Dot16[] GetAdvances(uint start, uint count, LoadFlags flags) + { + IntPtr advPtr; + Error err = FT.FT_Get_Advances(Reference, start, count, flags, out advPtr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + //create a new array and copy the data from the pointer over + Fixed16Dot16[] advances = new Fixed16Dot16[count]; + IntPtr* ptr = (IntPtr*)advPtr; + + for (int i = 0; i < count; i++) + advances[i] = Fixed16Dot16.FromRawValue((int)ptr[i]); + + return advances; + } + + #endregion + + #region OpenType Validation + + /// + /// Validate various OpenType tables to assure that all offsets and indices are valid. The idea is that a + /// higher-level library which actually does the text layout can access those tables without error checking + /// (which can be quite time consuming). + /// + /// + /// This function only works with OpenType fonts, returning an error otherwise. + /// + /// After use, the application should deallocate the five tables with . A NULL value + /// indicates that the table either doesn't exist in the font, or the application hasn't asked for validation. + /// + /// A bit field which specifies the tables to be validated. + /// A pointer to the BASE table. + /// A pointer to the GDEF table. + /// A pointer to the GPOS table. + /// A pointer to the GSUB table. + /// A pointer to the JSTF table. + [CLSCompliant(false)] + public void OpenTypeValidate(OpenTypeValidationFlags flags, out IntPtr baseTable, out IntPtr gdefTable, out IntPtr gposTable, out IntPtr gsubTable, out IntPtr jstfTable) + { + Error err = FT.FT_OpenType_Validate(Reference, flags, out baseTable, out gdefTable, out gposTable, out gsubTable, out jstfTable); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Free the buffer allocated by OpenType validator. + /// + /// + /// This function must be used to free the buffer allocated by only. + /// + /// The pointer to the buffer that is allocated by . + public void OpenTypeFree(IntPtr table) + { + FT.FT_OpenType_Free(Reference, table); + } + + #endregion + + #region TrueTypeGX/AAT Validation + + /// + /// Validate various TrueTypeGX tables to assure that all offsets and indices are valid. The idea is that a + /// higher-level library which actually does the text layout can access those tables without error checking + /// (which can be quite time consuming). + /// + /// + /// This function only works with TrueTypeGX fonts, returning an error otherwise. + /// + /// After use, the application should deallocate the buffers pointed to by each ‘tables’ element, by calling + /// . A NULL value indicates that the table either doesn't exist in the font, the + /// application hasn't asked for validation, or the validator doesn't have the ability to validate the sfnt + /// table. + /// + /// A bit field which specifies the tables to be validated. + /// + /// The array where all validated sfnt tables are stored. The array itself must be allocated by a client. + /// + /// + /// The size of the ‘tables’ array. Normally, FT_VALIDATE_GX_LENGTH should be passed. + /// + [CLSCompliant(false)] + public void TrueTypeGXValidate(TrueTypeValidationFlags flags, byte[][] tables, uint tableLength) + { + FT.FT_TrueTypeGX_Validate(Reference, flags, tables, tableLength); + } + + /// + /// Free the buffer allocated by TrueTypeGX validator. + /// + /// + /// This function must be used to free the buffer allocated by only. + /// + /// The pointer to the buffer allocated by . + public void TrueTypeGXFree(IntPtr table) + { + FT.FT_TrueTypeGX_Free(Reference, table); + } + + /// + /// Validate classic (16-bit format) kern table to assure that the offsets and indices are valid. The idea is + /// that a higher-level library which actually does the text layout can access those tables without error + /// checking (which can be quite time consuming). + /// + /// The ‘kern’ table validator in deals with both the new 32-bit format and + /// the classic 16-bit format, while only supports the classic 16-bit format. + /// + /// + /// After use, the application should deallocate the buffers pointed to by ‘ckern_table’, by calling + /// . A NULL value indicates that the table doesn't exist in the font. + /// + /// A bit field which specifies the dialect to be validated. + /// A pointer to the kern table. + [CLSCompliant(false)] + public IntPtr ClassicKernValidate(ClassicKernValidationFlags flags) + { + IntPtr ckernRef; + FT.FT_ClassicKern_Validate(Reference, flags, out ckernRef); + return ckernRef; + } + + /// + /// Free the buffer allocated by classic Kern validator. + /// + /// + /// This function must be used to free the buffer allocated by only. + /// + /// + /// The pointer to the buffer that is allocated by . + /// + public void ClassicKernFree(IntPtr table) + { + FT.FT_ClassicKern_Free(Reference, table); + } + + #endregion + + /// + /// Disposes the Face. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + internal void AddChildSize(FTSize child) + { + childSizes.Add(child); + } + + internal void RemoveChildSize(FTSize child) + { + childSizes.Remove(child); + } + + private void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + + foreach (FTSize s in childSizes) + s.Dispose(); + + childSizes.Clear(); + + FT.FT_Done_Face(base.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.RemoveChildFace(this); + + base.Reference = IntPtr.Zero; + rec = new FaceRec(); + + if (memoryFaceHandle.IsAllocated) + memoryFaceHandle.Free(); + + EventHandler handler = Disposed; + if (handler != null) + handler(this, EventArgs.Empty); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/FaceFlags.cs b/SharpFont/Source/SharpFontShared/FaceFlags.cs new file mode 100644 index 000000000..6d25d76f7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FaceFlags.cs @@ -0,0 +1,145 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// A list of bit flags used in the ‘face_flags’ field of the structure. They inform client + /// applications of properties of the corresponding face. + /// + [Flags] + public enum FaceFlags : long + { + /// + /// No style flags. + /// + None = 0x0000, + + /// + /// Indicates that the face contains outline glyphs. This doesn't prevent bitmap strikes, i.e., a face can have + /// both this and and set. + /// + Scalable = 0x0001, + + /// + /// Indicates that the face contains bitmap strikes. See also and + /// . + /// + FixedSizes = 0x0002, + + /// + /// Indicates that the face contains fixed-width characters (like Courier, Lucido, MonoType, etc.). + /// + FixedWidth = 0x0004, + + /// + /// Indicates that the face uses the ‘sfnt’ storage scheme. For now, this means TrueType and OpenType. + /// + Sfnt = 0x0008, + + /// + /// Indicates that the face contains horizontal glyph metrics. This should be set for all common formats. + /// + Horizontal = 0x0010, + + /// + /// Indicates that the face contains vertical glyph metrics. This is only available in some formats, not all of + /// them. + /// + Vertical = 0x0020, + + /// + /// Indicates that the face contains kerning information. If set, the kerning distance can be retrieved through + /// the function . 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). + /// + Kerning = 0x0040, + + /// + /// THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT. + /// + [Obsolete("THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT.")] + FastGlyphs = 0x0080, + + /// + /// Indicates that the font contains multiple masters and is capable of interpolating between them. See the + /// multiple-masters specific API for details. + /// + MultipleMasters = 0x0100, + + /// + /// Indicates that the font contains glyph names that can be retrieved through + /// . Note that some TrueType fonts contain broken glyph name + /// tables. Use the function when needed. + /// + GlyphNames = 0x0200, + + /// + /// Used internally by FreeType to indicate that a face's stream was provided by the client application and + /// should not be destroyed when is called. Don't read or test this flag. + /// + ExternalStream = 0x0400, + + /// + /// 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. + /// + Hinter = 0x0800, + + /// + /// 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 + /// . Only the CID values for which corresponding glyphs in the subsetted font + /// exist make return successfully; in all other cases you get an + /// error. + /// + /// 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. + /// + CidKeyed = 0x1000, + + /// + /// 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. + /// + /// It is not possible to autohint such fonts using ; it will also ignore + /// . You have to set both and + /// to really disable hinting; however, you probably never want this + /// except for demonstration purposes. + /// + /// Currently, there are about a dozen TrueType fonts in the list of tricky fonts; they are hard-coded in file + /// ‘ttobjs.c’. + /// + Tricky = 0x2000, + + /// + /// Set if the font has color glyph tables. To access color glyphs use . + /// + Color = 0x4000, + } +} diff --git a/SharpFont/Source/SharpFontShared/Fixed16Dot16.cs b/SharpFont/Source/SharpFontShared/Fixed16Dot16.cs new file mode 100644 index 000000000..f43e26849 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fixed16Dot16.cs @@ -0,0 +1,752 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// Represents a fixed-point decimal value with 16 bits of decimal precision. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct Fixed16Dot16 : IEquatable, IComparable + { + #region Fields + + /// + /// The angle pi expressed in FT_Angle units. + /// + public static readonly Fixed16Dot16 AnglePI = new Fixed16Dot16(180); + + /// + /// The angle 2*pi expressed in FT_Angle units. + /// + public static readonly Fixed16Dot16 Angle2PI = new Fixed16Dot16(360); + + /// + /// The angle pi/2 expressed in FT_Angle units. + /// + public static readonly Fixed16Dot16 AnglePI2 = new Fixed16Dot16(90); + + /// + /// The angle pi/4 expressed in FT_Angle units. + /// + public static readonly Fixed16Dot16 AnglePI4 = new Fixed16Dot16(45); + + /// + /// The raw 16.16 integer. + /// + private int value; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// An integer value. + public Fixed16Dot16(int value) + { + this.value = value << 16; + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed16Dot16(float value) + { + this.value = (int)(value * 65536); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed16Dot16(double value) + { + this.value = (int)(value * 65536); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed16Dot16(decimal value) + { + this.value = (int)(value * 65536); + } + + #endregion + + #region Properties + + /// + /// Gets the raw 16.16 integer. + /// + public int Value + { + get + { + return value; + } + } + + #endregion + + #region Methods + + #region Static + + /// + /// Creates a from an int containing a 16.16 value. + /// + /// A 16.16 value. + /// An instance of . + public static Fixed16Dot16 FromRawValue(int value) + { + Fixed16Dot16 f = new Fixed16Dot16(); + f.value = value; + return f; + } + + /// + /// Creates a new from a + /// + /// A value. + /// The equivalent value. + public static Fixed16Dot16 FromInt32(int value) + { + return new Fixed16Dot16(value); + } + + /// + /// Creates a new from . + /// + /// A floating-point value. + /// A fixed 16.16 value. + public static Fixed16Dot16 FromSingle(float value) + { + return new Fixed16Dot16(value); + } + + /// + /// Creates a new from a . + /// + /// A floating-point value. + /// A fixed 16.16 value. + public static Fixed16Dot16 FromDouble(double value) + { + return new Fixed16Dot16(value); + } + + /// + /// Creates a new from a . + /// + /// A floating-point value. + /// A fixed 16.16 value. + public static Fixed16Dot16 FromDecimal(decimal value) + { + return new Fixed16Dot16(value); + } + + /// + /// Adds two 16.16 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed16Dot16 Add(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Fixed16Dot16.FromRawValue(left.value + right.value); + } + + /// + /// Subtacts one 16.16 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed16Dot16 Subtract(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Fixed16Dot16.FromRawValue(left.value - right.value); + } + + /// + /// Multiplies two 16.16 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + 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; + } + + /// + /// 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. + /// + /// + /// NOTE: This is a native FreeType function. + /// + /// 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. + /// + /// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make + /// a great difference. + /// + /// The first multiplier. + /// The second multiplier. Use a 16.16 factor here whenever possible (see note below). + /// The result of ‘(a*b)/0x10000’. + public static Fixed16Dot16 MultiplyFix(int a, Fixed16Dot16 b) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_MulFix((IntPtr)a, (IntPtr)b.Value)); + } + + /// + /// Divides one 16.16 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + 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; + } + + /// + /// 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. + /// + /// + /// NOTE: This is a native FreeType function. + /// + /// The optimization for is simple: If (a << 16) fits in 32 bits, then the division + /// is computed directly. Otherwise, we use a specialized version of . + /// + /// The first multiplier. + /// The second multiplier. Use a 16.16 factor here whenever possible (see note below). + /// The result of ‘(a*0x10000)/b’. + public static Fixed16Dot16 DivideFix(int a, Fixed16Dot16 b) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_DivFix((IntPtr)a, (IntPtr)b.Value)); + } + + /// + /// A very simple function used to perform the computation ‘(a*b)/c’ with maximal accuracy (it uses a 64-bit + /// intermediate integer whenever necessary). + /// + /// This function isn't necessarily as fast as some processor specific operations, but is at least completely + /// portable. + /// + /// This is a native FreeType function. + /// The first multiplier. + /// The second multiplier. + /// The divisor. + /// + /// 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’. + /// + 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)); + } + + /// + /// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane. + /// + /// This is a native FreeType function. + /// The horizontal vector coordinate. + /// The vertical vector coordinate. + /// The arc-tangent value (i.e. angle). + public static Fixed16Dot16 Atan2(Fixed16Dot16 x, Fixed16Dot16 y) + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Atan2((IntPtr)x.Value, (IntPtr)y.Value)); + } + + /// + /// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval. + /// + /// This is a native FreeType function. + /// First angle. + /// Second angle. + /// Constrained value of ‘value2-value1’. + 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 + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed16Dot16(short value) + { + return new Fixed16Dot16(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed16Dot16(int value) + { + return new Fixed16Dot16(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed16Dot16(float value) + { + return new Fixed16Dot16(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed16Dot16(double value) + { + return new Fixed16Dot16(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed16Dot16(decimal value) + { + return new Fixed16Dot16(value); + } + + /// + /// Casts a to a . + /// + /// + /// This operation can result in a loss of data. + /// + /// A value. + /// The equivalent value. + public static explicit operator int(Fixed16Dot16 value) + { + return value.ToInt32(); + } + + /// + /// Casts a to a . + /// + /// + /// This operation can result in a loss of data. + /// + /// A value. + /// The equivalent value. + public static explicit operator float(Fixed16Dot16 value) + { + return value.ToSingle(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator double(Fixed16Dot16 value) + { + return value.ToDouble(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator decimal(Fixed16Dot16 value) + { + return value.ToDecimal(); + } + + /// + /// Adds two 16.16 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed16Dot16 operator +(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Add(left, right); + } + + /// + /// Subtacts one 16.16 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed16Dot16 operator -(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Subtract(left, right); + } + + /// + /// Multiplies two 16.16 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + public static Fixed16Dot16 operator *(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Multiply(left, right); + } + + /// + /// Divides one 16.16 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + public static Fixed16Dot16 operator /(Fixed16Dot16 left, Fixed16Dot16 right) + { + return Divide(left, right); + } + + /// + /// Compares two instances of for equality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are equal. + public static bool operator ==(Fixed16Dot16 left, Fixed16Dot16 right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are not equal. + public static bool operator !=(Fixed16Dot16 left, Fixed16Dot16 right) + { + return !(left == right); + } + + /// + /// Checks if the left operand is less than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than right. + public static bool operator <(Fixed16Dot16 left, Fixed16Dot16 right) + { + return left.CompareTo(right) < 0; + } + + /// + /// Checks if the left operand is less than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than or equal to right. + public static bool operator <=(Fixed16Dot16 left, Fixed16Dot16 right) + { + return left.CompareTo(right) <= 0; + } + + /// + /// Checks if the left operand is greater than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than right. + public static bool operator >(Fixed16Dot16 left, Fixed16Dot16 right) + { + return left.CompareTo(right) > 0; + } + + /// + /// Checks if the left operand is greater than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than or equal to right. + public static bool operator >=(Fixed16Dot16 left, Fixed16Dot16 right) + { + return left.CompareTo(right) >= 0; + } + + #endregion + + #region Instance + + /// + /// Removes the decimal part of the value. + /// + /// The truncated number. + public int Floor() + { + return value >> 16; + } + + /// + /// A very simple function used to compute the floor function of a 16.16 fixed number. + /// + /// This is a native FreeType function. + /// The result of ‘a & -0x10000’. + 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)); + } + + /// + /// Rounds to the nearest whole number. + /// + /// The nearest whole number. + public int Round() + { + //add 2^15, rounds the integer part up if the decimal value is >= 0.5 + return (value + 32768) >> 16; + } + + /// + /// A very simple function used to round a 16.16 fixed number. + /// + /// This is a native FreeType function. + /// The result of ‘(a + 0x8000) & -0x10000’. + public Fixed16Dot16 RoundFix() + { + return FromRawValue((int)FT.FT_RoundFix((IntPtr)this.Value)); + } + + /// + /// Rounds up to the next whole number. + /// + /// The next whole number. + public int Ceiling() + { + //add 2^16 - 1, rounds the integer part up if there's any decimal value + return (value + 65535) >> 16; + } + + /// + /// A very simple function used to compute the ceiling function of a 16.16 fixed number. + /// + /// This is a native FreeType function. + /// The result of ‘(a + 0x10000 - 1) & -0x10000’. + public Fixed16Dot16 CeilingFix() + { + return FromRawValue((int)FT.FT_CeilFix((IntPtr)this.Value)); + } + + /// + /// Return the sinus of a given angle in fixed point format. + /// + /// + /// NOTE: This is a native FreeType function. + /// + /// If you need both the sinus and cosinus for a given angle, use the function . + /// + /// The sinus value. + public Fixed16Dot16 Sin() + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)this.Value)); + } + + /// + /// Return the cosinus of a given angle in fixed point format. + /// + /// + /// NOTE: This is a native FreeType function. + /// + /// If you need both the sinus and cosinus for a given angle, use the function . + /// + /// The cosinus value. + public Fixed16Dot16 Cos() + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)this.Value)); + } + + /// + /// Return the tangent of a given angle in fixed point format. + /// + /// This is a native FreeType function. + /// The tangent value. + public Fixed16Dot16 Tan() + { + return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)this.Value)); + } + + /// + /// Converts the value to a . The value is floored. + /// + /// An integer value. + public int ToInt32() + { + return Floor(); + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public float ToSingle() + { + return value / 65536f; + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public double ToDouble() + { + return value / 65536d; + } + + /// + /// Converts the value to a . + /// + /// A decimal value. + public decimal ToDecimal() + { + return value / 65536m; + } + + /// + /// Compares this instance to another for equality. + /// + /// A . + /// A value indicating whether the two instances are equal. + public bool Equals(Fixed16Dot16 other) + { + return value == other.value; + } + + /// + /// Compares this instnace with another 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 . + /// + /// A . + /// A value indicating the relative order of the instances. + public int CompareTo(Fixed16Dot16 other) + { + return value.CompareTo(other.value); + } + + #endregion + + #region Overrides + + /// + /// Returns a string that represents the current object. + /// + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(IFormatProvider provider) + { + return ToDecimal().ToString(provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// A string that represents the current object. + public string ToString(string format) + { + return ToDecimal().ToString(format); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(string format, IFormatProvider provider) + { + return ToDecimal().ToString(format, provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. + public override string ToString() + { + return ToDecimal().ToString(); + } + + /// + /// Calculates a hash code for the current object. + /// + /// A hash code for the current object. + public override int GetHashCode() + { + return value.GetHashCode(); + } + + /// + /// Determines whether the specified object isequal to the current object. + /// + /// The object to compare with the current object. + /// A value indicating equality between the two objects. + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Fixed26Dot6.cs b/SharpFont/Source/SharpFontShared/Fixed26Dot6.cs new file mode 100644 index 000000000..a83e21bfa --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fixed26Dot6.cs @@ -0,0 +1,579 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani + +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 +{ + /// + /// Represents a fixed-point decimal value with 6 bits of decimal precision. + /// + [StructLayout(LayoutKind.Sequential)] + public struct Fixed26Dot6 : IEquatable, IComparable + { + #region Fields + + /// + /// The raw 26.6 integer. + /// + private int value; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// An integer value. + public Fixed26Dot6(int value) + { + this.value = value << 6; + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed26Dot6(float value) + { + this.value = (int)(value * 64); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed26Dot6(double value) + { + this.value = (int)(value * 64); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed26Dot6(decimal value) + { + this.value = (int)(value * 64); + } + + #endregion + + #region Properties + + /// + /// Gets the raw 26.6 integer. + /// + public int Value + { + get + { + return value; + } + } + + #endregion + + #region Methods + + #region Static + + /// + /// Creates a from an int containing a 26.6 value. + /// + /// A 26.6 value. + /// An instance of . + public static Fixed26Dot6 FromRawValue(int value) + { + Fixed26Dot6 f = new Fixed26Dot6(); + f.value = value; + return f; + } + + /// + /// Creates a new from a + /// + /// A value. + /// The equivalent value. + public static Fixed26Dot6 FromInt32(int value) + { + return new Fixed26Dot6(value); + } + + /// + /// Creates a new from . + /// + /// A floating-point value. + /// A fixed 26.6 value. + public static Fixed26Dot6 FromSingle(float value) + { + return new Fixed26Dot6(value); + } + + /// + /// Creates a new from a . + /// + /// A floating-point value. + /// A fixed 26.6 value. + public static Fixed26Dot6 FromDouble(double value) + { + return new Fixed26Dot6(value); + } + + /// + /// Creates a new from a . + /// + /// A floating-point value. + /// A fixed 26.6 value. + public static Fixed26Dot6 FromDecimal(decimal value) + { + return new Fixed26Dot6(value); + } + + /// + /// Adds two 26.6 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed26Dot6 Add(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Fixed26Dot6.FromRawValue(left.value + right.value); + } + + /// + /// Subtacts one 26.6 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed26Dot6 Subtract(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Fixed26Dot6.FromRawValue(left.value - right.value); + } + + /// + /// Multiplies two 26.6 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + 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; + } + + /// + /// Divides one 26.6 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + 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 + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed26Dot6(short value) + { + return new Fixed26Dot6(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed26Dot6(int value) + { + return new Fixed26Dot6(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed26Dot6(float value) + { + return new Fixed26Dot6(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed26Dot6(double value) + { + return new Fixed26Dot6(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator Fixed26Dot6(decimal value) + { + return new Fixed26Dot6(value); + } + + /// + /// Casts a to a . + /// + /// + /// This operation can result in a loss of data. + /// + /// A value. + /// The equivalent value. + public static explicit operator int(Fixed26Dot6 value) + { + return value.ToInt32(); + } + + /// + /// Casts a to a . + /// + /// + /// This operation can result in a loss of data. + /// + /// A value. + /// The equivalent value. + public static explicit operator float(Fixed26Dot6 value) + { + return value.ToSingle(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator double(Fixed26Dot6 value) + { + return value.ToDouble(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator decimal(Fixed26Dot6 value) + { + return value.ToDecimal(); + } + + /// + /// Adds two 26.6 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed26Dot6 operator +(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Add(left, right); + } + + /// + /// Subtacts one 26.6 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed26Dot6 operator -(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Subtract(left, right); + } + + /// + /// Multiplies two 26.6 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + public static Fixed26Dot6 operator *(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Multiply(left, right); + } + + /// + /// Divides one 26.6 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + public static Fixed26Dot6 operator /(Fixed26Dot6 left, Fixed26Dot6 right) + { + return Divide(left, right); + } + + /// + /// Compares two instances of for equality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are equal. + public static bool operator ==(Fixed26Dot6 left, Fixed26Dot6 right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are not equal. + public static bool operator !=(Fixed26Dot6 left, Fixed26Dot6 right) + { + return !(left == right); + } + + /// + /// Checks if the left operand is less than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than right. + public static bool operator <(Fixed26Dot6 left, Fixed26Dot6 right) + { + return left.CompareTo(right) < 0; + } + + /// + /// Checks if the left operand is less than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than or equal to right. + public static bool operator <=(Fixed26Dot6 left, Fixed26Dot6 right) + { + return left.CompareTo(right) <= 0; + } + + /// + /// Checks if the left operand is greater than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than right. + public static bool operator >(Fixed26Dot6 left, Fixed26Dot6 right) + { + return left.CompareTo(right) > 0; + } + + /// + /// Checks if the left operand is greater than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than or equal to right. + public static bool operator >=(Fixed26Dot6 left, Fixed26Dot6 right) + { + return left.CompareTo(right) >= 0; + } + + #endregion + + #region Instance + + /// + /// Removes the decimal part of the value. + /// + /// The truncated number. + public int Floor() + { + return value >> 6; + } + + /// + /// Rounds to the nearest whole number. + /// + /// The nearest whole number. + public int Round() + { + //add 2^5, rounds the integer part up if the decimal value is >= 0.5 + return (value + 32) >> 6; + } + + /// + /// Rounds up to the next whole number. + /// + /// The next whole number. + public int Ceiling() + { + //add 2^6 - 1, rounds the integer part up if there's any decimal value + return (value + 63) >> 6; + } + + /// + /// Converts the value to a . The value is floored. + /// + /// An integer value. + public int ToInt32() + { + return Floor(); + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public float ToSingle() + { + return value / 64f; + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public double ToDouble() + { + return value / 64d; + } + + /// + /// Converts the value to a . + /// + /// A decimal value. + public decimal ToDecimal() + { + return value / 64m; + } + + /// + /// Compares this instance to another for equality. + /// + /// A . + /// A value indicating whether the two instances are equal. + public bool Equals(Fixed26Dot6 other) + { + return value == other.value; + } + + /// + /// Compares this instnace with another 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 . + /// + /// A . + /// A value indicating the relative order of the instances. + public int CompareTo(Fixed26Dot6 other) + { + return value.CompareTo(other.value); + } + + #endregion + + #region Overrides + + /// + /// Returns a string that represents the current object. + /// + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(IFormatProvider provider) + { + return ToDecimal().ToString(provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// A string that represents the current object. + public string ToString(string format) + { + return ToDecimal().ToString(format); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(string format, IFormatProvider provider) + { + return ToDecimal().ToString(format, provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. + public override string ToString() + { + return ToDecimal().ToString(); + } + + /// + /// Calculates a hash code for the current object. + /// + /// A hash code for the current object. + public override int GetHashCode() + { + return value.GetHashCode(); + } + + /// + /// Determines whether the specified object isequal to the current object. + /// + /// The object to compare with the current object. + /// A value indicating equality between the two objects. + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Fixed2Dot14.cs b/SharpFont/Source/SharpFontShared/Fixed2Dot14.cs new file mode 100644 index 000000000..75460763f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fixed2Dot14.cs @@ -0,0 +1,546 @@ +#region MIT License +/*Copyright (c) 2015 Robert Rouhani + +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 +{ + /// + /// Represents a fixed-point decimal value with 14 bits of decimal precision. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct Fixed2Dot14 : IEquatable, IComparable + { + #region Fields + + /// + /// The raw 2.14 short. + /// + private short value; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the struct. + /// + /// An integer value. + public Fixed2Dot14(short value) + { + this.value = (short)(value << 14); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed2Dot14(float value) + { + this.value = (short)(value * 16384); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed2Dot14(double value) + { + this.value = (short)(value * 16384); + } + + /// + /// Initializes a new instance of the struct. + /// + /// A floating point value. + public Fixed2Dot14(decimal value) + { + this.value = (short)(value * 16384); + } + + #endregion + + #region Properties + + /// + /// Gets the raw 2.14 integer. + /// + public int Value + { + get + { + return value; + } + } + + #endregion + + #region Methods + + #region Static + + /// + /// Creates a from an int containing a 2.14 value. + /// + /// A 2.14 value. + /// An instance of . + public static Fixed2Dot14 FromRawValue(short value) + { + Fixed2Dot14 f = new Fixed2Dot14(); + f.value = value; + return f; + } + + /// + /// Creates a new from a + /// + /// A value. + /// The equivalent value. + public static Fixed2Dot14 FromInt16(short value) + { + return new Fixed2Dot14(value); + } + + /// + /// Creates a new from . + /// + /// A floating-point value. + /// A fixed 2.14 value. + public static Fixed2Dot14 FromSingle(float value) + { + return new Fixed2Dot14(value); + } + + /// + /// Creates a new from . + /// + /// A floating-point value. + /// A fixed 2.14 value. + public static Fixed2Dot14 FromDouble(double value) + { + return new Fixed2Dot14(value); + } + + /// + /// Creates a new from . + /// + /// A floating-point value. + /// A fixed 2.14 value. + public static Fixed2Dot14 FromDecimal(decimal value) + { + return new Fixed2Dot14(value); + } + + /// + /// Adds two 2.14 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed2Dot14 Add(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Fixed2Dot14.FromRawValue((short)(left.value + right.value)); + } + + /// + /// Subtacts one 2.14 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed2Dot14 Subtract(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Fixed2Dot14.FromRawValue((short)(left.value - right.value)); + } + + /// + /// Multiplies two 2.14 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + 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; + } + + /// + /// Divides one 2.14 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + 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 + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed2Dot14(float value) + { + return new Fixed2Dot14(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed2Dot14(double value) + { + return new Fixed2Dot14(value); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static explicit operator Fixed2Dot14(decimal value) + { + return new Fixed2Dot14(value); + } + + /// + /// Casts a to a . + /// + /// + /// This operation can result in a loss of data. + /// + /// A value. + /// The equivalent value. + public static explicit operator float(Fixed2Dot14 value) + { + return value.ToSingle(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator double(Fixed2Dot14 value) + { + return value.ToDouble(); + } + + /// + /// Casts a to a . + /// + /// A value. + /// The equivalent value. + public static implicit operator decimal(Fixed2Dot14 value) + { + return value.ToDecimal(); + } + + /// + /// Adds two 2.14 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the addition. + public static Fixed2Dot14 operator +(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Add(left, right); + } + + /// + /// Subtacts one 2.14 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the subtraction. + public static Fixed2Dot14 operator -(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Subtract(left, right); + } + + /// + /// Multiplies two 2.14 values together. + /// + /// The left operand. + /// The right operand. + /// The result of the multiplication. + public static Fixed2Dot14 operator *(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Multiply(left, right); + } + + /// + /// Divides one 2.14 values from another. + /// + /// The left operand. + /// The right operand. + /// The result of the division. + public static Fixed2Dot14 operator /(Fixed2Dot14 left, Fixed2Dot14 right) + { + return Divide(left, right); + } + + /// + /// Compares two instances of for equality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are equal. + public static bool operator ==(Fixed2Dot14 left, Fixed2Dot14 right) + { + return left.Equals(right); + } + + /// + /// Compares two instances of for inequality. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether the two instances are not equal. + public static bool operator !=(Fixed2Dot14 left, Fixed2Dot14 right) + { + return !(left == right); + } + + /// + /// Checks if the left operand is less than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than right. + public static bool operator <(Fixed2Dot14 left, Fixed2Dot14 right) + { + return left.CompareTo(right) < 0; + } + + /// + /// Checks if the left operand is less than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is less than or equal to right. + public static bool operator <=(Fixed2Dot14 left, Fixed2Dot14 right) + { + return left.CompareTo(right) <= 0; + } + + /// + /// Checks if the left operand is greater than the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than right. + public static bool operator >(Fixed2Dot14 left, Fixed2Dot14 right) + { + return left.CompareTo(right) > 0; + } + + /// + /// Checks if the left operand is greater than or equal to the right operand. + /// + /// The left operand. + /// The right operand. + /// A value indicating whether left is greater than or equal to right. + public static bool operator >=(Fixed2Dot14 left, Fixed2Dot14 right) + { + return left.CompareTo(right) >= 0; + } + + #endregion + + #region Instance + + /// + /// Removes the decimal part of the value. + /// + /// The truncated number. + public short Floor() + { + return (short)(value >> 14); + } + + /// + /// Rounds to the nearest whole number. + /// + /// The nearest whole number. + public short Round() + { + //add 2^13, rounds the integer part up if the decimal value is >= 0.5 + return (short)((value + 8192) >> 14); + } + + /// + /// Rounds up to the next whole number. + /// + /// The next whole number. + public short Ceiling() + { + //add 2^14 - 1, rounds the integer part up if there's any decimal value + return (short)((value + 16383) >> 14); + } + + /// + /// Converts the value to a . The value is floored. + /// + /// An integer value. + public short ToInt16() + { + return Floor(); + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public float ToSingle() + { + return value / 16384f; + } + + /// + /// Converts the value to a . + /// + /// A floating-point value. + public double ToDouble() + { + return value / 16384d; + } + + /// + /// Converts the value to a . + /// + /// A decimal value. + public decimal ToDecimal() + { + return value / 16384m; + } + + /// + /// Compares this instance to another for equality. + /// + /// A . + /// A value indicating whether the two instances are equal. + public bool Equals(Fixed2Dot14 other) + { + return value == other.value; + } + + /// + /// Compares this instnace with another 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 . + /// + /// A . + /// A value indicating the relative order of the instances. + public int CompareTo(Fixed2Dot14 other) + { + return value.CompareTo(other.value); + } + + #endregion + + #region Overrides + + /// + /// Returns a string that represents the current object. + /// + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(IFormatProvider provider) + { + return ToDecimal().ToString(provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// A string that represents the current object. + public string ToString(string format) + { + return ToDecimal().ToString(format); + } + + /// + /// Returns a string that represents the current object. + /// + /// A numeric format string. + /// An object that supplies culture-specific formatting information. + /// A string that represents the current object. + public string ToString(string format, IFormatProvider provider) + { + return ToDecimal().ToString(format, provider); + } + + /// + /// Returns a string that represents the current object. + /// + /// A string that represents the current object. + public override string ToString() + { + return ToDecimal().ToString(); + } + + /// + /// Calculates a hash code for the current object. + /// + /// A hash code for the current object. + public override int GetHashCode() + { + return value.GetHashCode(); + } + + /// + /// Determines whether the specified object isequal to the current object. + /// + /// The object to compare with the current object. + /// A value indicating equality between the two objects. + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Fnt/Header.cs b/SharpFont/Source/SharpFontShared/Fnt/Header.cs new file mode 100644 index 000000000..2f6f67a41 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fnt/Header.cs @@ -0,0 +1,594 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// Describes the general appearance of the font. + /// + public enum Family + { + /// + /// Don't care or don't know which family. + /// + DontCare = 0, + + /// + /// The font has a Roman appearance. + /// + Roman = 1, + + /// + /// The font has a Swiss appearance. + /// + Swiss = 2, + + /// + /// The font has a Modern appearance. + /// + Modern = 3, + + /// + /// The font has a script-like appearance. + /// + Script = 4, + + /// + /// The font is decorative. + /// + Decorative = 5 + } + + /// + /// Provides flags for font proportions and color. + /// + [Flags] + [CLSCompliant(false)] + public enum Flags : ushort + { + /// + /// Font is fixed. + /// + Fixed = 1 << 0, + + /// + /// Font is proportional. + /// + Proportional = 1 << 1, + + /// + /// Font is ABC fixed. + /// + AbcFixed = 1 << 2, + + /// + /// Font is ABC proportional. + /// + AbcProportional = 1 << 3, + + /// + /// Font is 2-bit color. + /// + Color1 = 1 << 4, + + /// + /// Font is 4-bit color. + /// + Color16 = 1 << 5, + + /// + /// Font is 8-bit color. + /// + Color256 = 1 << 6, + + /// + /// Font is RGB color. + /// + RgbColor = 1 << 7 + } + + /// + /// Windows FNT Header info. + /// + public class Header + { + #region Fields + + private IntPtr reference; + private HeaderRec rec; + + #endregion + + #region Constructors + + internal Header(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the version format of the file (e.g. 0x0200). + /// + [CLSCompliant(false)] + public ushort Version + { + get + { + return rec.version; + } + } + + /// + /// Gets the size of the file in bytes. + /// + [CLSCompliant(false)] + public uint FileSize + { + get + { + return (uint)rec.file_size; + } + } + + /// + /// Gets the copyright text. + /// Limited to 60 bytes. + /// + public byte[] Copyright + { + get + { + return rec.copyright; + } + } + + /// + /// Gets the filetype (vector or bitmap). This is exclusively for GDI use. + /// + [CLSCompliant(false)] + public ushort FileType + { + get + { + return rec.file_type; + } + } + + /// + /// Gets the nominal point size determined by the designer at which the font looks + /// best. + /// + [CLSCompliant(false)] + public ushort NominalPointSize + { + get + { + return rec.nominal_point_size; + } + } + + /// + /// Gets the nominal vertical resolution in dots per inch. + /// + [CLSCompliant(false)] + public ushort VerticalResolution + { + get + { + return rec.vertical_resolution; + } + } + + /// + /// Gets the nominal horizontal resolution in dots per inch. + /// + [CLSCompliant(false)] + public ushort HorizontalResolution + { + get + { + return rec.horizontal_resolution; + } + } + + /// + /// Gets the height of the font's ascent from the baseline. + /// + [CLSCompliant(false)] + public ushort Ascent + { + get + { + return rec.ascent; + } + } + + /// + /// Gets the amount of leading inside the bounds of . + /// + [CLSCompliant(false)] + public ushort InternalLeading + { + get + { + return rec.internal_leading; + } + } + + /// + /// Gets the amount of leading the designer recommends to be added between + /// rows. + /// + [CLSCompliant(false)] + public ushort ExternalLeading + { + get + { + return rec.external_leading; + } + } + + /// + /// Gets whether the font is italic. + /// + public bool Italic + { + get + { + return (0x01 & rec.italic) == 0x01; + } + } + + /// + /// Ges whether the font includes underlining. + /// + public bool Underline + { + get + { + return (0x01 & rec.underline) == 0x01; + } + } + + /// + /// Ges whether the font includes strikeout. + /// + public bool Strikeout + { + get + { + return (0x01 & rec.strike_out) == 0x01; + } + } + + /// + /// Gets the weight of characters on a scale of 1 to 1000, with + /// 400 being regular weight. + /// + [CLSCompliant(false)] + public ushort Weight + { + get + { + return rec.weight; + } + } + + /// + /// Gets the character set specified by the font. + /// + public byte Charset + { + get + { + return rec.charset; + } + } + + /// + /// 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. + /// + [CLSCompliant(false)] + public ushort PixelWidth + { + get + { + return rec.pixel_width; + } + } + + /// + /// Gets the height of the vector grid (vector fonts) or the height + /// of the bitmap for all characters (raster fonts). + /// + [CLSCompliant(false)] + public ushort PixelHeight + { + get + { + return rec.pixel_height; + } + } + + /// + /// Gets whether the font is variable pitch. + /// + public byte PitchAndFamily + { + get + { + return rec.pitch_and_family; + } + } + + /// + /// Gets the width of characters in the font, based on the width of 'X'. + /// + [CLSCompliant(false)] + public ushort AverageWidth + { + get + { + return rec.avg_width; + } + } + + /// + /// Gets the maximum width of all characters in the font. + /// + [CLSCompliant(false)] + public ushort MaximumWidth + { + get + { + return rec.max_width; + } + } + + /// + /// Gets the first character code specified in the font. + /// + public byte FirstChar + { + get + { + return rec.first_char; + } + } + + /// + /// Gets the last character code specified in the font. + /// + public byte LastChar + { + get + { + return rec.last_char; + } + } + + /// + /// Gets the character to substitute when a character is needed that + /// isn't defined in the font. + /// + public byte DefaultChar + { + get + { + return rec.default_char; + } + } + + /// + /// Gets the character that defines word breaks, for purposes of word + /// wrapping and word spacing justification. This value is relative to + /// the , so the character code is this value + /// minus . + /// + public byte BreakChar + { + get + { + return rec.break_char; + } + } + + /// + /// Gets the number of bytes in each row of the bitmap (raster fonts). + /// + [CLSCompliant(false)] + public ushort BytesPerRow + { + get + { + return rec.bytes_per_row; + } + } + + /// + /// Gets the offset in the file, in bytes, to the string that gives the device name. + /// The value is 0 for generic fonts. + /// + [CLSCompliant(false)] + public uint DeviceOffset + { + get + { + return (uint)rec.device_offset; + } + } + + /// + /// Gets the offset in the file, in bytes, to the string that gives the face name + /// (null-terminated). + /// + [CLSCompliant(false)] + public uint FaceNameOffset + { + get + { + return (uint)rec.face_name_offset; + } + } + + /// + /// Gets the absolute machine address of the bitmap, + /// which is set by GDI at load time. + /// + [CLSCompliant(false)] + public uint BitsPointer + { + get + { + return (uint)rec.bits_pointer; + } + } + + /// + /// Gets the offset in the file, in bytes, to the beginning of the character data + /// (raster or vector). + /// + [CLSCompliant(false)] + public uint BitsOffset + { + get + { + return (uint)rec.bits_offset; + } + } + + /// + /// Reservied. + /// + public byte Reserved + { + get + { + return rec.reserved; + } + } + + /// + /// Gets that describe font proportion and color. + /// + [CLSCompliant(false)] + public Flags Flags + { + get + { + return (Flags)rec.flags; + } + } + + /// + /// ASpace has not been used since before Windows 3.0. + /// Set it to 0 for compatibility. + /// + [CLSCompliant(false)] + public ushort ASpace + { + get + { + return rec.A_space; + } + } + + /// + /// BSpace has not been used since before Windows 3.0. + /// Set it to 0 for compatibility. + /// + [CLSCompliant(false)] + public ushort BSpace + { + get + { + return rec.B_space; + } + } + + /// + /// CSpace has not been used since before Windows 3.0. + /// Set it to 0 for compatibility. + /// + [CLSCompliant(false)] + public ushort CSpace + { + get + { + return rec.C_space; + } + } + + /// + /// Gets the offset of the color table. + /// + [CLSCompliant(false)] + public ushort ColorTableOffset + { + get + { + return rec.color_table_offset; + } + } + + /// + /// This field is reserved. + /// + [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(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Fnt/Internal/HeaderRec.cs b/SharpFont/Source/SharpFontShared/Fnt/Internal/HeaderRec.cs new file mode 100644 index 000000000..7ea86c587 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fnt/Internal/HeaderRec.cs @@ -0,0 +1,77 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Fnt/WinFntID.cs b/SharpFont/Source/SharpFontShared/Fnt/WinFntID.cs new file mode 100644 index 000000000..c26c6693f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Fnt/WinFntID.cs @@ -0,0 +1,148 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of valid values for the ‘charset’ byte in . Exact mapping tables for the various + /// cpXXXX encodings (except for cp1361) can be found at in the + /// MAPPINGS/VENDORS/MICSFT/WINDOWS subdirectory. cp1361 is roughly a superset of + /// MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT. + /// + public enum WinFntId : byte + { + /// + /// ANSI encoding. A superset of ISO 8859-1. + /// + CP1252 = 0, + + /// + /// 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. + /// + Default = 1, + + /// + /// There is no known mapping table available. + /// + Symbol = 2, + + /// + /// Mac Roman encoding. + /// + Mac = 77, + + /// + /// A superset of Japanese Shift-JIS (with minor deviations). + /// + CP932 = 128, + + /// + /// A superset of Korean Hangul KS C 5601-1987 (with different ordering and minor deviations). + /// + CP949 = 129, + + /// + /// Korean (Johab). + /// + CP1361 = 130, + + /// + /// A superset of simplified Chinese GB 2312-1980 (with different ordering and minor deviations). + /// + CP936 = 134, + + /// + /// A superset of traditional Chinese Big 5 ETen (with different ordering and minor deviations). + /// + CP950 = 136, + + /// + /// A superset of Greek ISO 8859-7 (with minor modifications). + /// + CP1253 = 161, + + /// + /// A superset of Turkish ISO 8859-9. + /// + CP1254 = 162, + + /// + /// For Vietnamese. This encoding doesn't cover all necessary characters. + /// + CP1258 = 163, + + /// + /// A superset of Hebrew ISO 8859-8 (with some modifications). + /// + CP1255 = 177, + + /// + /// A superset of Arabic ISO 8859-6 (with different ordering). + /// + CP1256 = 178, + + /// + /// A superset of Baltic ISO 8859-13 (with some deviations). + /// + CP1257 = 186, + + /// + /// A superset of Russian ISO 8859-5 (with different ordering). + /// + CP1251 = 204, + + /// + /// A superset of Thai TIS 620 and ISO 8859-11. + /// + CP874 = 222, + + /// + /// A superset of East European ISO 8859-2 (with slightly different ordering). + /// + CP1250 = 238, + + /// + /// From Michael Pöttgen <michael@poettgen.de>: + /// The ‘Windows Font Mapping’ article says that is used for the charset of vector + /// fonts, like ‘modern.fon’, ‘roman.fon’, and ‘script.fon’ on Windows. + /// + /// The ‘CreateFont’ documentation says: The value specifies a character set that is + /// operating-system dependent. + /// + /// 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. + /// + /// 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 + /// , 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. + /// + Oem = 255 + } +} diff --git a/SharpFont/Source/SharpFontShared/FreeTypeException.cs b/SharpFont/Source/SharpFontShared/FreeTypeException.cs new file mode 100644 index 000000000..ea10a4a93 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/FreeTypeException.cs @@ -0,0 +1,153 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An exception that gets thrown when FreeType returns an error code. + /// + public class FreeTypeException : Exception + { + private Error error; + + /// + /// Initializes a new instance of the class. + /// + /// The error returned by FreeType. + public FreeTypeException(Error error) + : base("FreeType error: " + GetErrorMessage(error)) + { + this.error = error; + } + + /// + /// Gets the FreeType error code that caused the exception. + /// + 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; + } + } + } +} diff --git a/SharpFont/Source/SharpFontShared/Gasp.cs b/SharpFont/Source/SharpFontShared/Gasp.cs new file mode 100644 index 000000000..4f1be20dc --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Gasp.cs @@ -0,0 +1,70 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of values and/or bit-flags returned by the FT_Get_Gasp function. + /// + /// + /// The bit-flags and are to be used for standard font + /// rasterization only. Independently of that, and + /// are to be used if ClearType is enabled (and + /// and are consequently ignored). + /// + /// ‘ClearType’ is Microsoft's implementation of LCD rendering, partly protected by patents. + /// + [Flags] + public enum Gasp + { + /// + /// This special value means that there is no GASP table in this face. It is up to the client to decide what to + /// do. + /// + NoTable = -1, + + /// + /// 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. + /// + DoGridfit = 0x01, + + /// + /// Anti-aliased rendering should be performed at the specified ppem. If not set, do monochrome rendering. + /// + DoGray = 0x02, + + /// + /// If set, smoothing along multiple axes must be used with ClearType. + /// + SymmetricSmoothing = 0x08, + + /// + /// Grid-fitting must be used with ClearType's symmetric smoothing. + /// + SymmetricGridfit = 0x10 + } +} diff --git a/SharpFont/Source/SharpFontShared/Generic.cs b/SharpFont/Source/SharpFontShared/Generic.cs new file mode 100644 index 000000000..20b7f8973 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Generic.cs @@ -0,0 +1,156 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// Describe a function used to destroy the ‘client’ data of any FreeType object. See the description of the + /// type for details of usage. + /// + /// + /// The address of the FreeType object which is under finalization. Its client data is accessed through its + /// ‘generic’ field. + /// + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void GenericFinalizer(IntPtr @object); + + /// + /// 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. + /// + /// Most FreeType object contains a ‘generic’ field, of type , which usage is left to client + /// applications and font servers. + /// + /// 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). + /// + [Obsolete("Use the Tag property and Disposed event.")] + public class Generic + { + #region Fields + + private GenericRec rec; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// + /// A typeless pointer to some client data. The data it cointains must stay fixed until finalizer is called. + /// + /// A delegate that gets called when the contained object gets finalized. + 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(reference); + } + + internal Generic(IntPtr reference, int offset) + : this(new IntPtr(reference.ToInt64() + offset)) + { + } + + #endregion + + #region Properties + + /// + /// Gets the size of a , in bytes. + /// + public static int SizeInBytes + { + get + { + return Marshal.SizeOf(typeof(GenericRec)); + } + } + + /// + /// Gets or sets a typeless pointer to any client-specified data. This field is completely ignored by the + /// FreeType library. + /// + public IntPtr Data + { + get + { + return rec.data; + } + + set + { + rec.data = value; + } + } + + /// + /// Gets or sets a pointer to a function, which will be called when the object + /// is destroyed. If this field is set to NULL, no code will be called. + /// + /*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 + } +} diff --git a/SharpFont/Source/SharpFontShared/Glyph.cs b/SharpFont/Source/SharpFontShared/Glyph.cs new file mode 100644 index 000000000..c024d8393 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Glyph.cs @@ -0,0 +1,444 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// The root glyph structure contains a given glyph image plus its advance width in 16.16 fixed float format. + /// + 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); + } + + /// + /// Finalizes an instance of the Glyph class. + /// + ~Glyph() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets a handle to the FreeType library object. + /// + public Library Library + { + get + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return parentLibrary; + } + } + + /// + /// Gets the format of the glyph's image. + /// + [CLSCompliant(false)] + public GlyphFormat Format + { + get + { + if (disposed) + throw new ObjectDisposedException("Format", "Cannot access a disposed object."); + + return rec.format; + } + } + + /// + /// Gets a 16.16 vector that gives the glyph's advance width. + /// + 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(reference); + } + } + + #endregion + + #region Operators + + /// + /// Downcasts a to a + /// + /// A . + /// A . + /// + /// If the 's format is not . + /// + 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."); + } + + /// + /// Downcasts a to a + /// + /// A . + /// A . + /// + /// If the 's format is not . + /// + 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 + + /// + /// CLS-compliant equivalent of an explicit cast to . + /// + /// A . + public BitmapGlyph ToBitmapGlyph() + { + return (BitmapGlyph)this; + } + + /// + /// CLS-compliant equivalent of an explicit cast to . + /// + /// A . + public OutlineGlyph ToOutlineGlyph() + { + return (OutlineGlyph)this; + } + + /// + /// A function used to copy a glyph image. Note that the created object must be released + /// with . + /// + /// A handle to the target glyph object. 0 in case of error. + 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); + } + + /// + /// Transform a glyph image if its format is scalable. + /// + /// A pointer to a 2x2 matrix to apply. + /// + /// A pointer to a 2d vector to apply. Coordinates are expressed in 1/64th of a pixel. + /// + 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); + } + + /// + /// 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). + /// + /// 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. + /// + /// + /// Coordinates are relative to the glyph origin, using the y upwards convention. + /// + /// If the glyph has been loaded with , ‘bbox_mode’ must be set to + /// to get unscaled font units in 26.6 pixel format. The value + /// is another name for this constant. + /// + /// If the font is tricky and the glyph has been loaded with , 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. + /// + /// 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: + /// + /// + /// width = bbox.xMax - bbox.xMin; + /// height = bbox.yMax - bbox.yMin; + /// + /// + /// Note also that for 26.6 coordinates, if ‘bbox_mode’ is set to , the + /// coordinates will also be grid-fitted, which corresponds to: + /// + /// + /// bbox.xMin = FLOOR(bbox.xMin); + /// bbox.yMin = FLOOR(bbox.yMin); + /// bbox.xMax = CEILING(bbox.xMax); + /// bbox.yMax = CEILING(bbox.yMax); + /// + /// + /// To get the bbox in pixel coordinates, set ‘bbox_mode’ to . + /// + /// To get the bbox in grid-fitted pixel coordinates, set ‘bbox_mode’ to . + /// + /// The mode which indicates how to interpret the returned bounding box values. + /// + /// The glyph coordinate bounding box. Coordinates are expressed in 1/64th of pixels if it is grid-fitted. + /// + [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; + } + + /// + /// Convert a given glyph object to a bitmap glyph object. + /// + /// + /// This function does nothing if the glyph format isn't scalable. + /// + /// The glyph image is translated with the ‘origin’ vector before rendering. + /// + /// The first parameter is a pointer to an handle, that will be replaced by this function + /// (with newly allocated data). Typically, you would use (omitting error handling): + /// + /// --sample code ommitted-- + /// + /// An enumeration that describes how the data is rendered. + /// + /// 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. + /// + /// + /// A boolean that indicates that the original glyph image should be destroyed by this function. It is never + /// destroyed in case of error. + /// + 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 + + /// + /// Stroke a given outline glyph object with a given stroker. + /// + /// + /// The source glyph is untouched in case of error. + /// + /// A stroker handle. + /// A Boolean. If 1, the source glyph object is destroyed on success. + /// New glyph handle. + 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); + } + + /// + /// Stroke a given outline glyph object with a given stroker, but only return either its inside or outside + /// border. + /// + /// + /// The source glyph is untouched in case of error. + /// + /// A stroker handle. + /// A Boolean. If 1, return the inside border, otherwise the outside border. + /// A Boolean. If 1, the source glyph object is destroyed on success. + /// New glyph handle. + 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 + + /// + /// Disposes the Glyph. + /// + 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 + } +} diff --git a/SharpFont/Source/SharpFontShared/GlyphBBoxMode.cs b/SharpFont/Source/SharpFontShared/GlyphBBoxMode.cs new file mode 100644 index 000000000..f0e889c7d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/GlyphBBoxMode.cs @@ -0,0 +1,50 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The mode how the values of are returned. + /// + [CLSCompliant(false)] + public enum GlyphBBoxMode : uint + { + /// Return unscaled font units. + Unscaled = 0, + + /// Return unfitted 26.6 coordinates. + Subpixels = 0, + + /// Return grid-fitted 26.6 coordinates. + Gridfit = 1, + + /// Return coordinates in integer pixels. + Truncate = 2, + + /// Return grid-fitted pixel coordinates. + Pixels = 3 + } +} diff --git a/SharpFont/Source/SharpFontShared/GlyphFormat.cs b/SharpFont/Source/SharpFontShared/GlyphFormat.cs new file mode 100644 index 000000000..761a5547b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/GlyphFormat.cs @@ -0,0 +1,67 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// 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. + /// + [CLSCompliant(false)] + public enum GlyphFormat : uint + { + /// + /// The value 0 is reserved. + /// + None = 0, + + /// + /// The glyph image is a composite of several other images. This format is only used with + /// , and is used to report compound glyphs (like accented characters). + /// + Composite = ('c' << 24 | 'o' << 16 | 'm' << 8 | 'p'), + + /// + /// The glyph image is a bitmap, and can be described as an . You generally need to + /// access the ‘bitmap’ field of the structure to read it. + /// + Bitmap = ('b' << 24 | 'i' << 16 | 't' << 8 | 's'), + + /// + /// The glyph image is a vectorial outline made of line segments and Bézier arcs; it can be described as an + /// ; you generally want to access the ‘outline’ field of the + /// structure to read it. + /// + Outline = ('o' << 24 | 'u' << 16 | 't' << 8 | 'l'), + + /// + /// 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 , but + /// FreeType isn't currently capable of rendering them correctly. + /// + Plotter = ('p' << 24 | 'l' << 16 | 'o' << 8 | 't') + } +} diff --git a/SharpFont/Source/SharpFontShared/GlyphMetrics.cs b/SharpFont/Source/SharpFontShared/GlyphMetrics.cs new file mode 100644 index 000000000..93cc1615f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/GlyphMetrics.cs @@ -0,0 +1,180 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// A structure used to model the metrics of a single glyph. The values are expressed in 26.6 fractional pixel + /// format; if the flag has been used while loading the glyph, values are expressed + /// in font units instead. + /// + /// + /// If not disabled with , the values represent dimensions of the hinted glyph (in + /// case hinting is applicable). + /// + 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 + + /// + /// Gets the glyph's width. If getting metrics from a face loaded with , call + /// to get the unscaled value. + /// + public Fixed26Dot6 Width + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.width); + } + } + + /// + /// Gets the glyph's height. If getting metrics from a face loaded with , call + /// to get the unscaled value. + /// + public Fixed26Dot6 Height + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.height); + } + } + + /// + /// Gets the left side bearing for horizontal layout. If getting metrics from a face loaded with + /// , call to get the unscaled value. + /// + public Fixed26Dot6 HorizontalBearingX + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.horiBearingX); + } + } + + /// + /// Gets the top side bearing for horizontal layout. If getting metrics from a face loaded with + /// , call to get the unscaled value. + /// + public Fixed26Dot6 HorizontalBearingY + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.horiBearingY); + } + } + + /// + /// Gets the advance width for horizontal layout. If getting metrics from a face loaded with + /// , call to get the unscaled value. + /// + public Fixed26Dot6 HorizontalAdvance + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.horiAdvance); + } + } + + /// + /// Gets the left side bearing for vertical layout. If getting metrics from a face loaded with + /// , call to get the unscaled value. + /// + public Fixed26Dot6 VerticalBearingX + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.vertBearingX); + } + } + + /// + /// 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 , call + /// to get the unscaled value. + /// + public Fixed26Dot6 VerticalBearingY + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.vertBearingY); + } + } + + /// + /// 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 , call + /// to get the unscaled value. + /// + public Fixed26Dot6 VerticalAdvance + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.vertAdvance); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/GlyphSlot.cs b/SharpFont/Source/SharpFontShared/GlyphSlot.cs new file mode 100644 index 000000000..ed5818dea --- /dev/null +++ b/SharpFont/Source/SharpFontShared/GlyphSlot.cs @@ -0,0 +1,475 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani + +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 +{ + /// + /// 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. + /// + /// + /// If is called with default flags (see ) + /// the glyph image is loaded in the glyph slot in its native format (e.g., an outline glyph for TrueType and Type + /// 1 formats). + /// + /// This image can later be converted into a bitmap by calling . This function finds the + /// current renderer for the native image's format, then invokes it. + /// + /// 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’. + /// + /// 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 . + /// + /// + /// + /// FT_Pos origin_x = 0; + /// FT_Pos prev_rsb_delta = 0; + /// + /// + /// for all glyphs do + /// <compute kern between current and previous glyph and add it to + /// `origin_x'> + /// + /// <load glyph with `FT_Load_Glyph'> + /// + /// if ( prev_rsb_delta - face->glyph->lsb_delta >= 32 ) + /// origin_x -= 64; + /// else if ( prev_rsb_delta - face->glyph->lsb_delta < -32 ) + /// origin_x += 64; + /// + /// prev_rsb_delta = face->glyph->rsb_delta; + /// + /// <save glyph image, or render glyph, or ...> + /// + /// origin_x += face->glyph->advance.x; + /// endfor + /// + /// + 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 + + /// + /// Gets a handle to the FreeType library instance this slot belongs to. + /// + public Library Library + { + get + { + return parentLibrary; + } + } + + /// + /// Gets a handle to the parent face object. + /// + public Face Face + { + get + { + return parentFace; + } + } + + /// + /// Gets the next . 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. + /// + public GlyphSlot Next + { + get + { + return new GlyphSlot(rec.next, parentFace, parentLibrary); + } + } + + /// + /// 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. + /// + [Obsolete("Use the Tag property, Dispose callback not handled currently.")] + public Generic Generic + { + get + { + return new Generic(rec.generic); + } + } + + /// + /// Gets the metrics of the last loaded glyph in the slot. The returned values depend on the last load flags + /// (see the API function) and can be expressed either in 26.6 + /// fractional pixels or font units. + /// + /// Note that even when the glyph image is transformed, the metrics are not. + /// + public GlyphMetrics Metrics + { + get + { + return new GlyphMetrics(rec.metrics); + } + } + + /// + /// Gets the advance width of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless + /// is set when loading the glyph. This field can be important to perform + /// correct WYSIWYG layout. Only relevant for outline glyphs. + /// + public Fixed16Dot16 LinearHorizontalAdvance + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.linearHoriAdvance); + } + } + + /// + /// Gets the advance height of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless + /// is set when loading the glyph. This field can be important to perform + /// correct WYSIWYG layout. Only relevant for outline glyphs. + /// + public Fixed16Dot16 LinearVerticalAdvance + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.linearVertAdvance); + } + } + + /// + /// Gets the advance. This shorthand is, depending on , the transformed + /// advance width for the glyph (in 26.6 fractional pixel format). As specified with + /// , it uses either the ‘horiAdvance’ or the ‘vertAdvance’ value of + /// ‘metrics’ field. + /// + public FTVector26Dot6 Advance + { + get + { + return rec.advance; + } + } + + /// + /// Gets the glyph format. This field indicates the format of the image contained in the glyph slot. Typically + /// , , or + /// , but others are possible. + /// + [CLSCompliant(false)] + public GlyphFormat Format + { + get + { + return rec.format; + } + } + + /// + /// Gets the bitmap. This field is used as a bitmap descriptor when the slot format is + /// . Note that the address and content of the bitmap buffer can change between + /// calls of and a few other functions. + /// + public FTBitmap Bitmap + { + get + { + return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf(Reference, "bitmap"), rec.bitmap, parentLibrary); + } + } + + /// + /// Gets the bitmap's left bearing expressed in integer pixels. Of course, this is only valid if the format is + /// . + /// + public int BitmapLeft + { + get + { + return rec.bitmap_left; + } + } + + /// + /// 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. + /// + public int BitmapTop + { + get + { + return rec.bitmap_top; + } + } + + /// + /// Gets the outline descriptor for the current glyph image if its format is . + /// Once a glyph is loaded, ‘outline’ can be transformed, distorted, embolded, etc. However, it must not be + /// freed. + /// + public Outline Outline + { + get + { + return new Outline(PInvokeHelper.AbsoluteOffsetOf(Reference, "outline"), rec.outline); + } + } + + /// + /// 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 flag. For now this is + /// internal to FreeType. + /// + [CLSCompliant(false)] + public uint SubglyphsCount + { + get + { + return rec.num_subglyphs; + } + } + + /// + /// Gets an array of subglyph descriptors for composite glyphs. There are ‘num_subglyphs’ elements in there. + /// Currently internal to FreeType. + /// + 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; + } + } + + /// + /// 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. + /// + public IntPtr ControlData + { + get + { + return rec.control_data; + } + } + + /// + /// Gets the length in bytes of the control data. + /// + public int ControlLength + { + get + { + return (int)rec.control_len; + } + } + + /// + /// Gets the difference between hinted and unhinted left side bearing while autohinting is active. Zero + /// otherwise. + /// + public int DeltaLsb + { + get + { + return (int)rec.lsb_delta; + } + } + + /// + /// Gets the difference between hinted and unhinted right side bearing while autohinting is active. Zero + /// otherwise. + /// + public int DeltaRsb + { + get + { + return (int)rec.rsb_delta; + } + } + + /// + /// Gets or sets an object used to identify this instance of . This object will not be + /// modified or accessed internally. + /// + /// + /// 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. + /// + public object Tag { get; set; } + + /// + /// 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. + /// + public IntPtr Other + { + get + { + return rec.other; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + + #region Public Methods + + #region Base Interface + + /// + /// Convert a given glyph image to a bitmap. It does so by inspecting the glyph image format, finding the + /// relevant renderer, and invoking it. + /// + /// This is the render mode used to render the glyph image into a bitmap. + public void RenderGlyph(RenderMode mode) + { + Error err = FT.FT_Render_Glyph(Reference, mode); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Retrieve a description of a given subglyph. Only use it if is + /// ; an error is returned otherwise. + /// + /// + /// 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. + /// + /// + /// The index of the subglyph. Must be less than . + /// + /// The glyph index of the subglyph. + /// The subglyph flags, see . + /// The subglyph's first argument (if any). + /// The subglyph's second argument (if any). + /// The subglyph transformation (if any). + [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 + + /// + /// A function used to extract a glyph image from a slot. Note that the created object must + /// be released with . + /// + /// A handle to the glyph object. + 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 + + /// + /// Make sure that a glyph slot owns ‘slot->bitmap’. + /// + /// + /// This function is to be used in combination with . + /// + public void OwnBitmap() + { + Error err = FT.FT_GlyphSlot_Own_Bitmap(Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + #endregion + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/GlyphToScriptMapProperty.cs b/SharpFont/Source/SharpFontShared/GlyphToScriptMapProperty.cs new file mode 100644 index 000000000..4159b57cf --- /dev/null +++ b/SharpFont/Source/SharpFontShared/GlyphToScriptMapProperty.cs @@ -0,0 +1,96 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The data exchange structure for the glyph-to-script-map property. + /// + public class GlyphToScriptMapProperty + { + private GlyphToScriptMapPropertyRec rec; + private Face face; + + /// + /// Initializes a new instance of the class. + /// + /// The face to apply the property to. + public GlyphToScriptMapProperty(Face face) + { + Face = face; + } + + internal GlyphToScriptMapProperty(GlyphToScriptMapPropertyRec rec, Face face) + { + this.rec = rec; + this.face = face; + } + + /// + /// Gets or sets the associated face. + /// + public Face Face + { + get + { + return face; + } + + set + { + face = value; + rec.face = face.Reference; + } + } + + /// + /// Gets or sets the associated map. + /// + public IntPtr Map + { + get + { + return rec.map; + } + + set + { + rec.map = value; + } + } + + internal GlyphToScriptMapPropertyRec Rec + { + get + { + return rec; + } + } + } +} diff --git a/SharpFont/Source/SharpFontShared/IncreaseXHeightProperty.cs b/SharpFont/Source/SharpFontShared/IncreaseXHeightProperty.cs new file mode 100644 index 000000000..162ea3d49 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/IncreaseXHeightProperty.cs @@ -0,0 +1,97 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The data exchange structure for the increase-x-height property. + /// + public class IncreaseXHeightProperty + { + private IncreaseXHeightPropertyRec rec; + private Face face; + + /// + /// Initializes a new instance of the class. + /// + /// The face to increase the X height of. + public IncreaseXHeightProperty(Face face) + { + this.rec.face = face.Reference; + this.face = face; + } + + internal IncreaseXHeightProperty(IncreaseXHeightPropertyRec rec, Face face) + { + this.rec = rec; + this.face = face; + } + + /// + /// Gets or sets the associated face. + /// + public Face Face + { + get + { + return face; + } + + set + { + face = value; + rec.face = face.Reference; + } + } + + /// + /// Gets or sets the limit property. + /// + [CLSCompliant(false)] + public uint Limit + { + get + { + return rec.limit; + } + + set + { + rec.limit = value; + } + } + + internal IncreaseXHeightPropertyRec Rec + { + get + { + return rec; + } + } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/BitmapGlyphRec.cs b/SharpFont/Source/SharpFontShared/Internal/BitmapGlyphRec.cs new file mode 100644 index 000000000..394b8a218 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/BitmapGlyphRec.cs @@ -0,0 +1,38 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/BitmapRec.cs b/SharpFont/Source/SharpFontShared/Internal/BitmapRec.cs new file mode 100644 index 000000000..77fdea325 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/BitmapRec.cs @@ -0,0 +1,48 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// Internally represents a Bitmap. + /// + /// + /// Refer to for FreeType documentation. + /// + [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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/BitmapSizeRec.cs b/SharpFont/Source/SharpFontShared/Internal/BitmapSizeRec.cs new file mode 100644 index 000000000..158cc3131 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/BitmapSizeRec.cs @@ -0,0 +1,52 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// Internally represents a BitmapSize. + /// + /// + /// Refer to for FreeType documentation. + /// + [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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/CharMapRec.cs b/SharpFont/Source/SharpFontShared/Internal/CharMapRec.cs new file mode 100644 index 000000000..b36cb6412 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/CharMapRec.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// Internally represents a CharMap. + /// + /// + /// Refer to for FreeType documentation. + /// + [StructLayout(LayoutKind.Sequential)] + internal struct CharMapRec + { + internal IntPtr face; + internal Encoding encoding; + internal PlatformId platform_id; + internal ushort encoding_id; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/FaceRec.cs b/SharpFont/Source/SharpFontShared/Internal/FaceRec.cs new file mode 100644 index 000000000..6c248b9af --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/FaceRec.cs @@ -0,0 +1,90 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// Internally represents a Face. + /// + /// + /// Refer to for FreeType documentation. + /// + [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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/GenericRec.cs b/SharpFont/Source/SharpFontShared/Internal/GenericRec.cs new file mode 100644 index 000000000..9cc80070e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/GenericRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/GlyphMetricsRec.cs b/SharpFont/Source/SharpFontShared/Internal/GlyphMetricsRec.cs new file mode 100644 index 000000000..df7496a5a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/GlyphMetricsRec.cs @@ -0,0 +1,53 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// Internally represents a GlyphMetrics. + /// + /// + /// Refer to for FreeType documentation. + /// + [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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/GlyphRec.cs b/SharpFont/Source/SharpFontShared/Internal/GlyphRec.cs new file mode 100644 index 000000000..d4c2f64a2 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/GlyphRec.cs @@ -0,0 +1,38 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/GlyphSlotRec.cs b/SharpFont/Source/SharpFontShared/Internal/GlyphSlotRec.cs new file mode 100644 index 000000000..d971b7f25 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/GlyphSlotRec.cs @@ -0,0 +1,74 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// Internally represents a GlyphSlot. + /// + /// + /// Refer to for FreeType documentation. + /// + [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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/GlyphToScriptMapPropertyRec.cs b/SharpFont/Source/SharpFontShared/Internal/GlyphToScriptMapPropertyRec.cs new file mode 100644 index 000000000..bfa7098b8 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/GlyphToScriptMapPropertyRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/IncreaseXHeightPropertyRec.cs b/SharpFont/Source/SharpFontShared/Internal/IncreaseXHeightPropertyRec.cs new file mode 100644 index 000000000..7527a3e1a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/IncreaseXHeightPropertyRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/ListNodeRec.cs b/SharpFont/Source/SharpFontShared/Internal/ListNodeRec.cs new file mode 100644 index 000000000..46984ede3 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/ListNodeRec.cs @@ -0,0 +1,39 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/ListRec.cs b/SharpFont/Source/SharpFontShared/Internal/ListRec.cs new file mode 100644 index 000000000..e09d2f602 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/ListRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/MemoryRec.cs b/SharpFont/Source/SharpFontShared/Internal/MemoryRec.cs new file mode 100644 index 000000000..8b3d1e157 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/MemoryRec.cs @@ -0,0 +1,40 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/ModuleClassRec.cs b/SharpFont/Source/SharpFontShared/Internal/ModuleClassRec.cs new file mode 100644 index 000000000..b25622339 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/ModuleClassRec.cs @@ -0,0 +1,50 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/NativeObject.cs b/SharpFont/Source/SharpFontShared/Internal/NativeObject.cs new file mode 100644 index 000000000..55d58601e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/NativeObject.cs @@ -0,0 +1,33 @@ +using System; + +namespace SharpFont +{ + /// + /// Provide a consistent means for using pointers as references. + /// + public abstract class NativeObject + { + private IntPtr reference; + + /// + /// Construct a new NativeObject and assign the reference. + /// + /// + protected NativeObject(IntPtr reference) + { + this.reference = reference; + } + + internal virtual IntPtr Reference + { + get + { + return reference; + } + set + { + reference = value; + } + } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/NativeReference.cs b/SharpFont/Source/SharpFontShared/Internal/NativeReference.cs new file mode 100644 index 000000000..272c23f3a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/NativeReference.cs @@ -0,0 +1,58 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// Struct NativeReference + /// + /// + [StructLayout(LayoutKind.Sequential)] + public struct NativeReference where T : NativeObject + { + private readonly IntPtr memoryPtr; + + /// + /// Initializes a new instance of the struct. + /// + /// The memory PTR. + public NativeReference(IntPtr memoryPtr) + { + this.memoryPtr = memoryPtr; + } + + /// + /// Performs an implicit conversion from to . + /// + /// The memory. + /// The result of the conversion. + public static implicit operator NativeReference(T memory) + { + return new NativeReference(memory.Reference); + } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/OpenArgsRec.cs b/SharpFont/Source/SharpFontShared/Internal/OpenArgsRec.cs new file mode 100644 index 000000000..58740832b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/OpenArgsRec.cs @@ -0,0 +1,48 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/OutlineFuncsRec.cs b/SharpFont/Source/SharpFontShared/Internal/OutlineFuncsRec.cs new file mode 100644 index 000000000..e67258c3d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/OutlineFuncsRec.cs @@ -0,0 +1,43 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/OutlineGlyphRec.cs b/SharpFont/Source/SharpFontShared/Internal/OutlineGlyphRec.cs new file mode 100644 index 000000000..d0b0d8681 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/OutlineGlyphRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/OutlineRec.cs b/SharpFont/Source/SharpFontShared/Internal/OutlineRec.cs new file mode 100644 index 000000000..a6713120a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/OutlineRec.cs @@ -0,0 +1,42 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/ParameterRec.cs b/SharpFont/Source/SharpFontShared/Internal/ParameterRec.cs new file mode 100644 index 000000000..14cae95b4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/ParameterRec.cs @@ -0,0 +1,41 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/RasterFuncsRec.cs b/SharpFont/Source/SharpFontShared/Internal/RasterFuncsRec.cs new file mode 100644 index 000000000..a3dbc2d6b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/RasterFuncsRec.cs @@ -0,0 +1,40 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/RasterParamsRec.cs b/SharpFont/Source/SharpFontShared/Internal/RasterParamsRec.cs new file mode 100644 index 000000000..f8fc3e4ee --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/RasterParamsRec.cs @@ -0,0 +1,50 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/RendererClassRec.cs b/SharpFont/Source/SharpFontShared/Internal/RendererClassRec.cs new file mode 100644 index 000000000..8e764f8fe --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/RendererClassRec.cs @@ -0,0 +1,44 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 RendererClassRec + { + internal ModuleClassRec root; + + internal GlyphFormat glyph_format; + + internal IntPtr render_glyph; + internal IntPtr transform_glyph; + internal IntPtr get_glyph_cbox; + internal IntPtr set_mode; + + internal IntPtr raster_class; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/SizeMetricsRec.cs b/SharpFont/Source/SharpFontShared/Internal/SizeMetricsRec.cs new file mode 100644 index 000000000..149c9f581 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/SizeMetricsRec.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 SizeMetricsRec + { + internal ushort x_ppem; + internal ushort y_ppem; + + internal FT_Long x_scale; + internal FT_Long y_scale; + internal FT_Long ascender; + internal FT_Long descender; + internal FT_Long height; + internal FT_Long max_advance; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/SizeRec.cs b/SharpFont/Source/SharpFontShared/Internal/SizeRec.cs new file mode 100644 index 000000000..05cbf061b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/SizeRec.cs @@ -0,0 +1,39 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 SizeRec + { + internal IntPtr face; + internal GenericRec generic; + internal SizeMetricsRec metrics; + private IntPtr @internal; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/SizeRequestRec.cs b/SharpFont/Source/SharpFontShared/Internal/SizeRequestRec.cs new file mode 100644 index 000000000..ddc8fde87 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/SizeRequestRec.cs @@ -0,0 +1,48 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// Internally represents a . + /// + /// + /// Refer to for FreeType documentation. + /// + [StructLayout(LayoutKind.Sequential)] + internal struct SizeRequestRec + { + internal SizeRequestType type; + internal FT_Long width; + internal FT_Long height; + internal uint horiResolution; + internal uint vertResolution; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/SpanRec.cs b/SharpFont/Source/SharpFontShared/Internal/SpanRec.cs new file mode 100644 index 000000000..742411f35 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/SpanRec.cs @@ -0,0 +1,39 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 SpanRec + { + internal short x; + internal ushort len; + internal byte coverage; + + internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(SpanRec)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/StreamDescRec.cs b/SharpFont/Source/SharpFontShared/Internal/StreamDescRec.cs new file mode 100644 index 000000000..75d2b8ba5 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/StreamDescRec.cs @@ -0,0 +1,42 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.Explicit)] + internal struct StreamDescRec + { + [FieldOffset(0)] + internal FT_Long value; + + [FieldOffset(0)] + internal IntPtr pointer; + } +} diff --git a/SharpFont/Source/SharpFontShared/Internal/StreamRec.cs b/SharpFont/Source/SharpFontShared/Internal/StreamRec.cs new file mode 100644 index 000000000..45486b4c0 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Internal/StreamRec.cs @@ -0,0 +1,51 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 StreamRec + { + internal IntPtr @base; + internal FT_ULong size; + internal FT_ULong pos; + + internal StreamDescRec descriptor; + internal StreamDescRec pathname; + internal StreamIOFunc read; + internal StreamCloseFunc close; + + internal IntPtr memory; + internal IntPtr cursor; + internal IntPtr limit; + + internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(StreamRec)); } } + } +} diff --git a/SharpFont/Source/SharpFontShared/KerningMode.cs b/SharpFont/Source/SharpFontShared/KerningMode.cs new file mode 100644 index 000000000..0cf3db41f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/KerningMode.cs @@ -0,0 +1,49 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An enumeration used to specify which kerning values to return in . + /// + public enum KerningMode + { + /// + /// Return scaled and grid-fitted kerning distances. + /// + Default = 0, + + /// + /// Return scaled but un-grid-fitted kerning distances. + /// + Unfitted, + + /// + /// Return the kerning vector in original font units. + /// + Unscaled + } +} diff --git a/SharpFont/Source/SharpFontShared/LcdFilter.cs b/SharpFont/Source/SharpFontShared/LcdFilter.cs new file mode 100644 index 000000000..075773dd4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/LcdFilter.cs @@ -0,0 +1,61 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of values to identify various types of LCD filters. + /// + public enum LcdFilter + { + /// + /// Do not perform filtering. When used with subpixel rendering, this results in sometimes severe color + /// fringes. + /// + None = 0, + + /// + /// The default filter reduces color fringes considerably, at the cost of a slight blurriness in the output. + /// + Default = 1, + + /// + /// The light filter is a variant that produces less blurriness at the cost of slightly more color fringes than + /// the default one. It might be better, depending on taste, your monitor, or your personal vision. + /// + Light = 2, + + /// + /// This filter corresponds to the original libXft color filter. It provides high contrast output but can + /// exhibit really bad color fringes if glyphs are not extremely well hinted to the pixel grid. In other words, + /// it only works well if the TrueType bytecode interpreter is enabled and high-quality hinted fonts are used. + /// + /// This filter is only provided for comparison purposes, and might be disabled or stay unsupported in the + /// future. + /// + Legacy = 16 + } +} diff --git a/SharpFont/Source/SharpFontShared/Library.cs b/SharpFont/Source/SharpFontShared/Library.cs new file mode 100644 index 000000000..5d4fc205e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Library.cs @@ -0,0 +1,897 @@ +#region MIT License +/*Copyright (c) 2012-2014, 2016 Robert Rouhani + +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 System.Collections.Generic; +using System.Runtime.InteropServices; + +using SharpFont.Cache; +using SharpFont.Internal; +using SharpFont.TrueType; + +namespace SharpFont +{ + /// + /// A handle to a FreeType library instance. Each ‘library’ is completely independent from the others; it is the + /// ‘root’ of a set of objects like fonts, faces, sizes, etc. + /// + /// It also embeds a memory manager (see ), as well as a scan-line converter object (see + /// ). + /// + /// For multi-threading applications each thread should have its own object. + /// + public sealed class Library : IDisposable + { + #region Fields + + private IntPtr reference; + + private bool customMemory; + private bool disposed; + + private List childFaces; + private List childGlyphs; + private List childOutlines; + private List childStrokers; + private List childManagers; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// + /// SharpFont assumes that you have the correct version of FreeType for your operating system and processor + /// architecture. If you get a here on Windows, there's a good chance + /// that you're trying to run your program as a 64-bit process and have a 32-bit version of FreeType or vice + /// versa. See the SharpFont.Examples project for how to handle this situation. + /// + public Library() + : this(false) + { + IntPtr libraryRef; + Error err = FT.FT_Init_FreeType(out libraryRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = libraryRef; + } + + /// + /// Initializes a new instance of the class. + /// + /// A custom FreeType memory manager. + public Library(Memory memory) + : this(false) + { + IntPtr libraryRef; + Error err = FT.FT_New_Library(memory.Reference, out libraryRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = libraryRef; + customMemory = true; + } + + private Library(bool duplicate) + { + childFaces = new List(); + childGlyphs = new List(); + childOutlines = new List(); + childStrokers = new List(); + childManagers = new List(); + } + + /// + /// Finalizes an instance of the class. + /// + ~Library() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets the version of the FreeType library being used. + /// + public Version Version + { + get + { + if (disposed) + throw new ObjectDisposedException("Version", "Cannot access a disposed object."); + + int major, minor, patch; + FT.FT_Library_Version(Reference, out major, out minor, out patch); + return new Version(major, minor, patch); + } + } + + 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 Methods + + #region Base Interface + + /// + /// This function calls to open a font by its pathname. + /// + /// A path to the font file. + /// The index of the face within the font. The first face has index 0. + /// + /// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL. + /// + /// + public Face NewFace(string path, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return new Face(this, path, faceIndex); + } + + /// + /// This function calls to open a font which has been loaded into memory. + /// + /// + /// You must not deallocate the memory before calling . + /// + /// A pointer to the beginning of the font data. + /// The index of the face within the font. The first face has index 0. + /// + /// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL. + /// + /// + public Face NewMemoryFace(byte[] file, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return new Face(this, file, faceIndex); + } + + /// + /// This function calls to open a font which has been loaded into memory. + /// + /// A pointer to the beginning of the font data. + /// Length of the buffer + /// The index of the face within the font. The first face has index 0. + /// + /// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL. + /// + public Face NewMemoryFace(IntPtr bufferPtr, int length, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return new Face(this, bufferPtr, length, faceIndex); + } + + /// + /// Create a object from a given resource described by . + /// + /// + /// Unlike FreeType 1.x, this function automatically creates a glyph slot for the face object which can be + /// accessed directly through . + /// + /// OpenFace can be used to quickly check whether the font format of a given font resource is supported by + /// FreeType. If the ‘faceIndex’ field is negative, the function's return value is 0 if the font format is + /// recognized, or non-zero otherwise; the function returns a more or less empty face handle in ‘*aface’ (if + /// ‘aface’ isn't NULL). The only useful field in this special case is which gives + /// the number of faces within the font file. After examination, the returned structure + /// should be deallocated with a call to . + /// + /// Each new face object created with this function also owns a default object, accessible + /// as . + /// + /// See the discussion of reference counters in the description of FT_Reference_Face. + /// + /// + /// A pointer to an structure which must be filled by the caller. + /// + /// The index of the face within the font. The first face has index 0. + /// + /// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL. + /// + public Face OpenFace(OpenArgs args, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + IntPtr faceRef; + + Error err = FT.FT_Open_Face(Reference, args.Reference, faceIndex, out faceRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Face(faceRef, this); + } + + #endregion + +#if !SHARPFONT_PLATFORM_IOS + #region Mac Specific Interface + + /// + /// Create a new face object from a FOND resource. + /// + /// + /// This function can be used to create objects from fonts that are installed in the system + /// as follows. + /// + /// fond = GetResource( 'FOND', fontName ); + /// error = FT_New_Face_From_FOND( library, fond, 0, &face ); + /// + /// + /// A FOND resource. + /// Only supported for the -1 ‘sanity check’ special case. + /// A handle to a new face object. + public Face NewFaceFromFond(IntPtr fond, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + IntPtr faceRef; + + Error err = FT.FT_New_Face_From_FOND(Reference, fond, faceIndex, out faceRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Face(faceRef, this); + } + + /// + /// Create a new face object from a given resource and typeface index using an FSSpec to the font file. + /// + /// + /// is identical to except it accepts an FSSpec instead + /// of a path. + /// + /// FSSpec to the font file. + /// The index of the face within the resource. The first face has index 0. + /// A handle to a new face object. + public Face NewFaceFromFSSpec(IntPtr spec, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + IntPtr faceRef; + + Error err = FT.FT_New_Face_From_FSSpec(Reference, spec, faceIndex, out faceRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Face(faceRef, this); + } + + /// + /// Create a new face object from a given resource and typeface index using an FSRef to the font file. + /// + /// + /// is identical to except it accepts an FSRef instead of + /// a path. + /// + /// FSRef to the font file. + /// The index of the face within the resource. The first face has index 0. + /// A handle to a new face object. + public Face NewFaceFromFSRef(IntPtr @ref, int faceIndex) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + IntPtr faceRef; + + Error err = FT.FT_New_Face_From_FSRef(Reference, @ref, faceIndex, out faceRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return new Face(faceRef, this); + } + + #endregion +#endif + + #region Module Management + + /// + /// Add a new module to a given library instance. + /// + /// + /// An error will be returned if a module already exists by that name, or if the module requires a version of + /// FreeType that is too great. + /// + /// A pointer to class descriptor for the module. + public void AddModule(ModuleClass clazz) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Add_Module(Reference, clazz.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Find a module by its name. + /// + /// + /// FreeType's internal modules aren't documented very well, and you should look up the source code for + /// details. + /// + /// The module's name (as an ASCII string). + /// A module handle. 0 if none was found. + public Module GetModule(string moduleName) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return new Module(FT.FT_Get_Module(Reference, moduleName)); + } + + /// + /// Remove a given module from a library instance. + /// + /// + /// The module object is destroyed by the function in case of success. + /// + /// A handle to a module object. + public void RemoveModule(Module module) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + if (module == null) + throw new ArgumentNullException("module"); + + Error err = FT.FT_Remove_Module(Reference, module.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Set a property for a given module. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertySet(string moduleName, string propertyName, IntPtr value) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Property_Set(Reference, moduleName, propertyName, value); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Set a property for a given module. + /// + /// The type of property to set. + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertySet(string moduleName, string propertyName, ref T value) + where T : struct + { + GCHandle gch = GCHandle.Alloc(value, GCHandleType.Pinned); + PropertySet(moduleName, propertyName, gch.AddrOfPinnedObject()); + gch.Free(); + } + + /// + /// Set a property for a given module. + /// + /// The type of property to set. + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertySet(string moduleName, string propertyName, T value) + where T : struct + { + PropertySet(moduleName, propertyName, ref value); + } + + /// + /// Set a property for a given module. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertySet(string moduleName, string propertyName, GlyphToScriptMapProperty value) + { + var rec = value.Rec; + PropertySet(moduleName, propertyName, ref rec); + } + + /// + /// Set a property for a given module. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection + /// of the module's documentation. + /// + /// Note that only a few modules have properties. + /// A generic pointer to a variable or structure which gives the new value of the property. + /// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertySet(string moduleName, string propertyName, IncreaseXHeightProperty value) + { + var rec = value.Rec; + PropertySet(moduleName, propertyName, ref rec); + } + + /// + /// Get a module's property value. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// A generic pointer to a variable or structure which gives the value of the property. The + /// exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's + /// documentation. + public void PropertyGet(string moduleName, string propertyName, IntPtr value) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Property_Get(Reference, moduleName, propertyName, value); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Get a module's property value. + /// + /// The type of property to get. + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// The value read from the module. + public void PropertyGet(string moduleName, string propertyName, out T value) + where T : struct + { + value = default(T); + + GCHandle gch = GCHandle.Alloc(value, GCHandleType.Pinned); + PropertyGet(moduleName, propertyName, gch.AddrOfPinnedObject()); + value = PInvokeHelper.PtrToStructure(gch.AddrOfPinnedObject()); + gch.Free(); + } + + /// + /// Get a module's property value. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// The value read from the module. + [Obsolete("Use PropertyGetGlyphToScriptMap instead")] + public void PropertyGet(string moduleName, string propertyName, out GlyphToScriptMapProperty value) + { + value = PropertyGetGlyphToScriptMap(moduleName, propertyName); + } + + /// + /// Get a module's property value. + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// The value read from the module. + [Obsolete("Use PropertyGetIncreaseXHeight instead")] + public void PropertyGet(string moduleName, string propertyName, out IncreaseXHeightProperty value) + { + value = PropertyGetIncreaseXHeight(moduleName, propertyName); + } + + /// + /// Gets a module's property value of the type . + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// The value read from the module. + public GlyphToScriptMapProperty PropertyGetGlyphToScriptMap(string moduleName, string propertyName) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + GlyphToScriptMapPropertyRec rec; + PropertyGet(moduleName, propertyName, out rec); + + Face face = childFaces.Find(f => f.Reference == rec.face); + return new GlyphToScriptMapProperty(rec, face); + } + + /// + /// Gets a module's property value of the type . + /// + /// The module name. + /// The property name. Properties are described in the ‘Synopsis’ subsection of the + /// module's documentation. + /// The value read from the module. + public IncreaseXHeightProperty PropertyGetIncreaseXHeight(string moduleName, string propertyName) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + IncreaseXHeightPropertyRec rec; + PropertyGet(moduleName, propertyName, out rec); + + Face face = childFaces.Find(f => f.Reference == rec.face); + return new IncreaseXHeightProperty(rec, face); + } + + /// + /// Set a debug hook function for debugging the interpreter of a font format. + /// + /// + /// Currently, four debug hook slots are available, but only two (for the TrueType and the Type 1 interpreter) + /// are defined. + /// + /// Since the internal headers of FreeType are no longer installed, the symbol ‘FT_DEBUG_HOOK_TRUETYPE’ isn't + /// available publicly. This is a bug and will be fixed in a forthcoming release. + /// + /// The index of the debug hook. You should use the values defined in ‘ftobjs.h’, e.g., + /// ‘FT_DEBUG_HOOK_TRUETYPE’. + /// The function used to debug the interpreter. + [CLSCompliant(false)] + public void SetDebugHook(uint hookIndex, IntPtr debugHook) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + FT.FT_Set_Debug_Hook(Reference, hookIndex, debugHook); + } + + /// + /// Add the set of default drivers to a given library object. This is only useful when you create a library + /// object with (usually to plug a custom memory manager). + /// + public void AddDefaultModules() + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + FT.FT_Add_Default_Modules(Reference); + } + + /// + /// Retrieve the current renderer for a given glyph format. + /// + /// + /// An error will be returned if a module already exists by that name, or if the module requires a version of + /// FreeType that is too great. + /// + /// To add a new renderer, simply use . To retrieve a renderer by its name, use + /// . + /// + /// The glyph format. + /// A renderer handle. 0 if none found. + [CLSCompliant(false)] + public Renderer GetRenderer(GlyphFormat format) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return new Renderer(FT.FT_Get_Renderer(Reference, format)); + } + + /// + /// Set the current renderer to use, and set additional mode. + /// + /// + /// In case of success, the renderer will be used to convert glyph images in the renderer's known format into + /// bitmaps. + /// + /// This doesn't change the current renderer for other formats. + /// + /// Currently, only the B/W renderer, if compiled with FT_RASTER_OPTION_ANTI_ALIASING (providing a 5-levels + /// anti-aliasing mode; this option must be set directly in ‘ftraster.c’ and is undefined by default) accepts a + /// single tag ‘pal5’ to set its gray palette as a character string with 5 elements. Consequently, the third + /// and fourth argument are zero normally. + /// + /// A handle to the renderer object. + /// The number of additional parameters. + /// Additional parameters. + [CLSCompliant(false)] + public unsafe void SetRenderer(Renderer renderer, uint numParams, Parameter[] parameters) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + if (renderer == null) + throw new ArgumentNullException("renderer"); + + if (parameters == null) + throw new ArgumentNullException("parameters"); + + ParameterRec[] paramRecs = parameters.Select(x => x.Record).ToArray(); + fixed (void* ptr = paramRecs) + { + Error err = FT.FT_Set_Renderer(Reference, renderer.Reference, numParams, (IntPtr)ptr); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + } + + #endregion + + #region LCD Filtering + + /// + /// This function is used to apply color filtering to LCD decimated bitmaps, like the ones used when calling + /// with or + /// . + /// + /// + /// This feature is always disabled by default. Clients must make an explicit call to this function with a + /// ‘filter’ value other than in order to enable it. + /// + /// Due to PATENTS covering subpixel rendering, this function doesn't do anything except returning + /// if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is + /// not defined in your build of the library, which should correspond to all default builds of FreeType. + /// + /// The filter affects glyph bitmaps rendered through , + /// , , and . + /// + /// It does not affect the output of and + /// . + /// + /// If this feature is activated, the dimensions of LCD glyph bitmaps are either larger or taller than the + /// dimensions of the corresponding outline with regards to the pixel grid. For example, for + /// , the filter adds up to 3 pixels to the left, and up to 3 pixels to the right. + /// + /// The bitmap offset values are adjusted correctly, so clients shouldn't need to modify their layout and glyph + /// positioning code when enabling the filter. + /// + /// + /// The filter type. + /// + /// You can use here to disable this feature, or + /// to use a default filter that should work well on most LCD screens. + /// + public void SetLcdFilter(LcdFilter filter) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + Error err = FT.FT_Library_SetLcdFilter(Reference, filter); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Use this function to override the filter weights selected by . By default, + /// FreeType uses the quintuple (0x00, 0x55, 0x56, 0x55, 0x00) for , and (0x10, + /// 0x40, 0x70, 0x40, 0x10) for and . + /// + /// + /// Due to PATENTS covering subpixel rendering, this function doesn't do anything except returning + /// if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is + /// not defined in your build of the library, which should correspond to all default builds of FreeType. + /// + /// This function must be called after to have any effect. + /// + /// + /// A pointer to an array; the function copies the first five bytes and uses them to specify the filter + /// weights. + /// + public void SetLcdFilterWeights(byte[] weights) + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + if (weights == null) + throw new ArgumentNullException("weights"); + + Error err = FT.FT_Library_SetLcdFilterWeights(Reference, weights); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + #endregion + + #region The TrueType Engine + + /// + /// Return an value to indicate which level of the TrueType virtual machine a given + /// library instance supports. + /// + /// A value indicating which level is supported. + public EngineType GetTrueTypeEngineType() + { + if (disposed) + throw new ObjectDisposedException("Library", "Cannot access a disposed object."); + + return FT.FT_Get_TrueType_Engine_Type(Reference); + } + + #endregion + + /// + /// Disposes the Library. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + internal void AddChildFace(Face child) + { + childFaces.Add(child); + } + + internal void RemoveChildFace(Face child) + { + childFaces.Remove(child); + } + + internal void AddChildGlyph(Glyph child) + { + childGlyphs.Add(child); + } + + internal void RemoveChildGlyph(Glyph child) + { + childGlyphs.Remove(child); + } + + internal void AddChildOutline(Outline child) + { + childOutlines.Add(child); + } + + internal void RemoveChildOutline(Outline child) + { + childOutlines.Remove(child); + } + + internal void AddChildStroker(Stroker child) + { + childStrokers.Add(child); + } + + internal void RemoveChildStroker(Stroker child) + { + childStrokers.Remove(child); + } + + internal void AddChildManager(Manager child) + { + childManagers.Add(child); + } + + internal void RemoveChildManager(Manager child) + { + childManagers.Remove(child); + } + + private void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + + //dipose all the children before disposing the library. + foreach (Face f in childFaces) + f.Dispose(); + + foreach (Glyph g in childGlyphs) + g.Dispose(); + + foreach (Outline o in childOutlines) + o.Dispose(); + + foreach (Stroker s in childStrokers) + s.Dispose(); + + foreach (Manager m in childManagers) + m.Dispose(); + + childFaces.Clear(); + childGlyphs.Clear(); + childOutlines.Clear(); + childStrokers.Clear(); + childManagers.Clear(); + + Error err = customMemory ? FT.FT_Done_Library(reference) : FT.FT_Done_FreeType(reference); + reference = IntPtr.Zero; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/ListNode.cs b/SharpFont/Source/SharpFontShared/ListNode.cs new file mode 100644 index 000000000..dd094d3b4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/ListNode.cs @@ -0,0 +1,108 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A structure used to hold a single list element. + /// + public class ListNode: NativeObject + { + #region Fields + + private ListNodeRec rec; + + #endregion + + #region Constructors + + internal ListNode(IntPtr reference): base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets the previous element in the list. NULL if first. + /// + public ListNode Previous + { + get + { + if (rec.prev == IntPtr.Zero) + return null; + + return new ListNode(rec.prev); + } + } + + /// + /// Gets the next element in the list. NULL if last. + /// + public ListNode Next + { + get + { + if (rec.next == IntPtr.Zero) + return null; + + return new ListNode(rec.next); + } + } + + /// + /// Gets a typeless pointer to the listed object. + /// + public IntPtr Data + { + get + { + return rec.data; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/LoadFlags.cs b/SharpFont/Source/SharpFontShared/LoadFlags.cs new file mode 100644 index 000000000..54cc15c1a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/LoadFlags.cs @@ -0,0 +1,196 @@ +#region MIT License +/*Copyright (c) 2012-2016 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants used with to indicate what kind of operations to + /// perform during glyph loading. + /// + /// + /// By default, hinting is enabled and the font's native hinter (see ) is preferred + /// over the auto-hinter. You can disable hinting by setting or change the + /// precedence by setting . You can also set + /// in case you don't want the auto-hinter to be used at all. + /// + /// See the description of for a special exception (affecting only a handful of + /// Asian fonts). + /// + /// Besides deciding which hinter to use, you can also decide which hinting algorithm to use. See + /// for details. + /// + [Flags] + [CLSCompliant(false)] + public enum LoadFlags : uint + { + /// + /// Corresponding to 0, this value is used as the default glyph load operation. In this case, the following + /// happens: + /// + /// + /// FreeType looks for a bitmap for the glyph corresponding to the face's current size. If one is found, the + /// function returns. The bitmap data can be accessed from the glyph slot (see note below). + /// + /// + /// If no embedded bitmap is searched or found, FreeType looks for a scalable outline. If one is found, it is + /// loaded from the font file, scaled to device pixels, then ‘hinted’ to the pixel grid in order to optimize + /// it. The outline data can be accessed from the glyph slot (see note below). + /// + /// + /// Note that by default, the glyph loader doesn't render outlines into bitmaps. The following flags are used + /// to modify this default behaviour to more specific and useful cases. + /// + Default = 0x000000, + + /// + /// Don't scale the outline glyph loaded, but keep it in font units. + /// + /// This flag implies and , and unsets + /// . + /// + NoScale = 0x000001, + + /// + /// Disable hinting. This generally generates ‘blurrier’ bitmap glyph when the glyph is rendered in any of the + /// anti-aliased modes. See also the note below. + /// + /// This flag is implied by . + /// + NoHinting = 0x000002, + + /// + /// Call after the glyph is loaded. By default, the glyph is rendered in + /// mode. This can be overridden by or + /// . + /// + /// This flag is unset by . + /// + Render = 0x000004, + + /// + /// Ignore bitmap strikes when loading. Bitmap-only fonts ignore this flag. + /// + /// always sets this flag. + /// + NoBitmap = 0x000008, + + /// + /// Load the glyph for vertical text layout. Don't use it as it is problematic currently. + /// + VerticalLayout = 0x000010, + + /// + /// Indicates that the auto-hinter is preferred over the font's native hinter. See also the note below. + /// + ForceAutohint = 0x000020, + + /// + /// Indicates that the font driver should crop the loaded bitmap glyph (i.e., remove all space around its black + /// bits). Not all drivers implement this. + /// + CropBitmap = 0x000040, + + /// + /// Indicates that the font driver should perform pedantic verifications during glyph loading. This is mostly + /// used to detect broken glyphs in fonts. By default, FreeType tries to handle broken fonts also. + /// + Pedantic = 0x000080, + + /// + /// Ignored. Deprecated. + /// + [Obsolete("Ignored. Deprecated.")] + IgnoreGlobalAdvanceWidth = 0x000200, + + /// + /// This flag is only used internally. It merely indicates that the font driver should not load composite + /// glyphs recursively. Instead, it should set the ‘num_subglyph’ and ‘subglyphs’ values of the glyph slot + /// accordingly, and set ‘glyph->format’ to . + /// + /// The description of sub-glyphs is not available to client applications for now. + /// + /// This flag implies and . + /// + NoRecurse = 0x000400, + + /// + /// Indicates that the transform matrix set by should be ignored. + /// + IgnoreTransform = 0x000800, + + /// + /// This flag is used with to indicate that you want to render an outline glyph + /// to a 1-bit monochrome bitmap glyph, with 8 pixels packed into each byte of the bitmap data. + /// + /// Note that this has no effect on the hinting algorithm used. You should rather use + /// so that the monochrome-optimized hinting algorithm is used. + /// + Monochrome = 0x001000, + + /// + /// Indicates that the ‘linearHoriAdvance’ and ‘linearVertAdvance’ fields of should be + /// kept in font units. See for details. + /// + LinearDesign = 0x002000, + + /// + /// Disable auto-hinter. See also the note below. + /// + NoAutohint = 0x008000, + + /// + /// This flag is used to request loading of color embedded-bitmap images. The resulting color bitmaps, if + /// available, will have the format. When the flag is not used and color bitmaps + /// are found, they will be converted to 256-level gray bitmaps transparently. Those bitmaps will be in the + /// format. + /// + Color = 0x100000, + + /// + /// This flag sets computing glyph metrics without the use of bundled + /// metrics tables. Well-behaving fonts have optimized bundled metrics + /// and these should be used. This flag is mainly used by font + /// validating or font editing applications which need to ignore, verify + /// or edit those tables. + /// + ComputeMetrics = 0x200000, + + /// + /// A bit-flag to be OR-ed with the ‘flags’ parameter of the and + /// functions. + /// + /// If set, it indicates that you want these functions to fail if the corresponding hinting mode or font driver + /// doesn't allow for very quick advance computation. + /// + /// Typically, glyphs which are either unscaled, unhinted, bitmapped, or light-hinted can have their advance + /// width computed very quickly. + /// + /// Normal and bytecode hinted modes, which require loading, scaling, and hinting of the glyph outline, are + /// extremely slow by comparison. + /// + AdvanceFlagFastOnly = 0x20000000 + } +} diff --git a/SharpFont/Source/SharpFontShared/LoadTarget.cs b/SharpFont/Source/SharpFontShared/LoadTarget.cs new file mode 100644 index 000000000..c41aad440 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/LoadTarget.cs @@ -0,0 +1,88 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of values that are used to select a specific hinting algorithm to use by the hinter. You should OR one + /// of these values to your ‘load_flags’ when calling . + /// + /// Note that font's native hinters may ignore the hinting algorithm you have specified (e.g., the TrueType + /// bytecode interpreter). You can set to ensure that the auto-hinter is + /// used. + /// + /// Also note that is an exception, in that it always implies + /// . + /// + /// + /// You should use only one of the values in your ‘load_flags’. They can't be ORed. + /// + /// If is also set, the glyph is rendered in the corresponding mode (i.e., the mode + /// which matches the used algorithm best) unless is set. + /// + /// You can use a hinting algorithm that doesn't correspond to the same rendering mode. As an example, it is + /// possible to use the ‘light’ hinting algorithm and have the results rendered in horizontal LCD pixel mode, with + /// code like: + /// + /// FT_Load_Glyph( face, glyph_index, + /// load_flags | FT_LOAD_TARGET_LIGHT ); + /// + /// FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD ); + /// + /// + public enum LoadTarget + { + /// + /// This corresponds to the default hinting algorithm, optimized for standard gray-level rendering. For + /// monochrome output, use instead. + /// + Normal = (RenderMode.Normal & 15) << 16, + + /// + /// A lighter hinting algorithm for non-monochrome modes. Many generated glyphs are more fuzzy but better + /// resemble its original shape. A bit like rendering on Mac OS X. + /// + /// As a special exception, this target implies . + /// + Light = (RenderMode.Light & 15) << 16, + + /// + /// Strong hinting algorithm that should only be used for monochrome output. The result is probably unpleasant + /// if the glyph is rendered in non-monochrome modes. + /// + Mono = (RenderMode.Mono & 15) << 16, + + /// + /// A variant of optimized for horizontally decimated LCD displays. + /// + Lcd = (RenderMode.Lcd & 15) << 16, + + /// + /// A variant of optimized for vertically decimated LCD displays. + /// + VerticalLcd = (RenderMode.VerticalLcd & 15) << 16 + } +} diff --git a/SharpFont/Source/SharpFontShared/Memory.cs b/SharpFont/Source/SharpFontShared/Memory.cs new file mode 100644 index 000000000..9deb8a4a7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Memory.cs @@ -0,0 +1,174 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// A function used to allocate ‘size’ bytes from ‘memory’. + /// + /// A handle to the source memory manager. + /// The size in bytes to allocate. + /// Address of new memory block. 0 in case of failure. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate IntPtr AllocFunc(NativeReference memory, IntPtr size); + + /// + /// A function used to release a given block of memory. + /// + /// A handle to the source memory manager. + /// The address of the target memory block. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void FreeFunc(NativeReference memory, IntPtr block); + + /// + /// A function used to re-allocate a given block of memory. + /// + /// + /// In case of error, the old block must still be available. + /// + /// A handle to the source memory manager. + /// The block's current size in bytes. + /// The block's requested new size. + /// The block's current address. + /// New block address. 0 in case of memory shortage. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate IntPtr ReallocFunc(NativeReference memory, IntPtr currentSize, IntPtr newSize, IntPtr block); + + /// + /// A structure used to describe a given memory manager to FreeType 2. + /// + public class Memory: NativeObject + { + #region Fields + + private MemoryRec rec; + + #endregion + + #region Constructors + + internal Memory(IntPtr reference): base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets a generic typeless pointer for user data. + /// + public IntPtr User + { + get + { + return rec.user; + } + } + + /// + /// Gets a pointer type to an allocation function. + /// + public AllocFunc Allocate + { + get + { + return rec.alloc; + } + } + + /// + /// Gets a pointer type to an memory freeing function. + /// + public FreeFunc Free + { + get + { + return rec.free; + } + } + + /// + /// Gets a pointer type to a reallocation function. + /// + public ReallocFunc Reallocate + { + get + { + return rec.realloc; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + + #region Methods + + /// + /// Decompress a zipped input buffer into an output buffer. This function is modeled after zlib's ‘uncompress’ + /// function. + /// + /// + /// This function may return if your build of FreeType was not + /// compiled with zlib support. + /// + /// The input buffer. + /// The output buffer. + /// The length of the used data in output. + public unsafe int GzipUncompress(byte[] input, byte[] output) + { + IntPtr len = (IntPtr)output.Length; + + fixed (byte* inPtr = input, outPtr = output) + { + Error err = FT.FT_Gzip_Uncompress(Reference, (IntPtr)outPtr, ref len, (IntPtr)inPtr, (IntPtr)input.Length); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + return (int)len; + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Module.cs b/SharpFont/Source/SharpFontShared/Module.cs new file mode 100644 index 000000000..cd59ec699 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Module.cs @@ -0,0 +1,43 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A handle to a given FreeType module object. Each module can be a font driver, a renderer, or anything else that + /// provides services to the formers. + /// + public sealed class Module : NativeObject + { + #region Constructors + + internal Module(IntPtr reference): base(reference) + { + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/ModuleClass.cs b/SharpFont/Source/SharpFontShared/ModuleClass.cs new file mode 100644 index 000000000..d6a80db57 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/ModuleClass.cs @@ -0,0 +1,194 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// A function used to initialize (not create) a new module object. + /// + /// The module to initialize. + /// FreeType error code. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate Error ModuleConstructor(NativeReference module); + + /// + /// A function used to finalize (not destroy) a given module object. + /// + /// The module to finalize. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void ModuleDestructor(NativeReference module); + + /// + /// A function used to query a given module for a specific interface. + /// + /// The module that contains the interface. + /// The name of the interface in the module. + /// The interface. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate IntPtr ModuleRequester(NativeReference module, [MarshalAs(UnmanagedType.LPStr)] string name); + + /// + /// The module class descriptor. + /// + public class ModuleClass : NativeObject + { + #region Fields + + private ModuleClassRec rec; + + #endregion + + #region Constructors + + internal ModuleClass(IntPtr reference) : base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets bit flags describing the module. + /// + [CLSCompliant(false)] + public uint Flags + { + get + { + return rec.module_flags; + } + } + + /// + /// Gets the size of one module object/instance in bytes. + /// + public int Size + { + get + { + return (int)rec.module_size; + } + } + + /// + /// Gets the name of the module. + /// + public string Name + { + get + { + return rec.module_name; + } + } + + /// + /// Gets the version, as a 16.16 fixed number (major.minor). + /// + public Fixed16Dot16 Version + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.module_version); + } + } + + /// + /// Gets the version of FreeType this module requires, as a 16.16 fixed number (major.minor). Starts at version + /// 2.0, i.e., 0x20000. + /// + public Fixed16Dot16 Requires + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.module_requires); + } + } + + /// + /// Get the module interface. + /// + public IntPtr Interface + { + get + { + return rec.module_interface; + } + } + + /// + /// Gets the initializing function. + /// + public ModuleConstructor Init + { + get + { + return rec.module_init; + } + } + + /// + /// Gets the finalizing function. + /// + public ModuleDestructor Done + { + get + { + return rec.module_done; + } + } + + /// + /// Gets the interface requesting function. + /// + public ModuleRequester GetInterface + { + get + { + return rec.get_interface; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMAxisRec.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMAxisRec.cs new file mode 100644 index 000000000..75188cff1 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMAxisRec.cs @@ -0,0 +1,42 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.MultipleMasters.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct MMAxisRec + { + [MarshalAs(UnmanagedType.LPStr)] + internal string name; + + internal FT_Long minimum; + internal FT_Long maximum; + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMVarRec.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMVarRec.cs new file mode 100644 index 000000000..12ce4b690 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MMVarRec.cs @@ -0,0 +1,39 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct MMVarRec + { + internal uint num_axis; + internal uint num_designs; + internal uint num_namedstyles; + internal IntPtr axis; + internal IntPtr namedstyle; + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MultiMasterRec.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MultiMasterRec.cs new file mode 100644 index 000000000..8c1d66d25 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/MultiMasterRec.cs @@ -0,0 +1,39 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct MultiMasterRec + { + internal uint num_axis; + internal uint num_designs; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + internal MMAxisRec[] axis; + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarAxisRec.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarAxisRec.cs new file mode 100644 index 000000000..9524436d2 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarAxisRec.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.MultipleMasters.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct VarAxisRec + { + [MarshalAs(UnmanagedType.LPStr)] + internal string name; + + internal FT_Long minimum; + internal FT_Long def; + internal FT_Long maximum; + + internal FT_ULong tag; + internal uint strid; + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarNamedStyleRec.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarNamedStyleRec.cs new file mode 100644 index 000000000..c0ee4fcf0 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/Internal/VarNamedStyleRec.cs @@ -0,0 +1,36 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct VarNamedStyleRec + { + internal IntPtr coords; + internal uint strid; + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/MMAxis.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/MMAxis.cs new file mode 100644 index 000000000..9cbed9a5a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/MMAxis.cs @@ -0,0 +1,111 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal; + +namespace SharpFont.MultipleMasters +{ + /// + /// A simple structure used to model a given axis in design space for Multiple Masters fonts. + /// + /// This structure can't be used for GX var fonts. + /// + public class MMAxis + { + #region Fields + + private IntPtr reference; + private MMAxisRec rec; + + #endregion + + #region Constructors + + internal MMAxis(IntPtr reference) + { + Reference = reference; + } + + internal MMAxis(MMAxisRec axisInternal) + { + this.rec = axisInternal; + } + + #endregion + + #region Properties + + /// + /// Gets the axis's name. + /// + public string Name + { + get + { + return rec.name; + } + } + + /// + /// Gets the axis's minimum design coordinate. + /// + public int Minimum + { + get + { + return (int)rec.minimum; + } + } + + /// + /// Gets the axis's maximum design coordinate. + /// + public int Maximum + { + get + { + return (int)rec.maximum; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/MMVar.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/MMVar.cs new file mode 100644 index 000000000..3969583ab --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/MMVar.cs @@ -0,0 +1,134 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal; + +namespace SharpFont.MultipleMasters +{ + /// + /// A structure used to model the axes and space of a Multiple Masters or GX var distortable font. + /// + /// Some fields are specific to one format and not to the other. + /// + public class MMVar + { + #region Fields + + private IntPtr reference; + private MMVarRec rec; + + #endregion + + #region Constructors + + internal MMVar(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the number of axes. The maximum value is 4 for MM; no limit in GX. + /// + [CLSCompliant(false)] + public uint AxisCount + { + get + { + return rec.num_axis; + } + } + + /// + /// Gets the number of designs; should be normally 2^num_axis for MM fonts. Not meaningful for GX (where every + /// glyph could have a different number of designs). + /// + [CLSCompliant(false)] + public uint DesignsCount + { + get + { + return rec.num_designs; + } + } + + /// + /// Gets the number of named styles; only meaningful for GX which allows certain design coordinates to have a + /// string ID (in the ‘name’ table) associated with them. The font can tell the user that, for example, + /// Weight=1.5 is ‘Bold’. + /// + [CLSCompliant(false)] + public uint NamedStylesCount + { + get + { + return rec.num_namedstyles; + } + } + + /// + /// Gets a table of axis descriptors. GX fonts contain slightly more data than MM. + /// + public VarAxis Axis + { + get + { + return new VarAxis(rec.axis); + } + } + + /// + /// Gets a table of named styles. Only meaningful with GX. + /// + public VarNamedStyle NamedStyle + { + get + { + return new VarNamedStyle(rec.namedstyle); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/MultiMaster.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/MultiMaster.cs new file mode 100644 index 000000000..aa0c53200 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/MultiMaster.cs @@ -0,0 +1,114 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal; + +namespace SharpFont.MultipleMasters +{ + /// + /// A structure used to model the axes and space of a Multiple Masters font. + /// + /// This structure can't be used for GX var fonts. + /// + public class MultiMaster + { + #region Fields + + private IntPtr reference; + private MultiMasterRec rec; + + #endregion + + #region Constructors + + internal MultiMaster(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the number of axes. Cannot exceed 4. + /// + [CLSCompliant(false)] + public uint AxisCount + { + get + { + return rec.num_axis; + } + } + + /// + /// Gets the number of designs; should be normally 2^num_axis even though the Type 1 specification strangely + /// allows for intermediate designs to be present. This number cannot exceed 16. + /// + [CLSCompliant(false)] + public uint DesignsCount + { + get + { + return rec.num_designs; + } + } + + /// + /// Gets a table of axis descriptors. + /// + public MMAxis[] Axis + { + get + { + MMAxis[] axis = new MMAxis[rec.num_axis]; + + for (int i = 0; i < rec.num_axis; i++) + axis[i] = new MMAxis(rec.axis[i]); + + return axis; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/VarAxis.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/VarAxis.cs new file mode 100644 index 000000000..8c9b75241 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/VarAxis.cs @@ -0,0 +1,140 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal; + +namespace SharpFont.MultipleMasters +{ + /// + /// A simple structure used to model a given axis in design space for Multiple Masters and GX var fonts. + /// + public class VarAxis + { + #region Fields + + private IntPtr reference; + private VarAxisRec rec; + + #endregion + + #region Constructors + + internal VarAxis(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the axis's name. Not always meaningful for GX. + /// + public string Name + { + get + { + return rec.name; + } + } + + /// + /// Gets the axis's minimum design coordinate. + /// + public int Minimum + { + get + { + return (int)rec.minimum; + } + } + + /// + /// Gets the axis's default design coordinate. FreeType computes meaningful default values for MM; it is then + /// an integer value, not in 16.16 format. + /// + public int Default + { + get + { + return (int)rec.def; + } + } + + /// + /// Gets the axis's maximum design coordinate. + /// + public int Maximum + { + get + { + return (int)rec.maximum; + } + } + + /// + /// Gets the axis's tag (the GX equivalent to ‘name’). FreeType provides default values for MM if possible. + /// + [CLSCompliant(false)] + public uint Tag + { + get + { + return (uint)rec.tag; + } + } + + /// + /// Gets the entry in ‘name’ table (another GX version of ‘name’). Not meaningful for MM. + /// + [CLSCompliant(false)] + public uint StrId + { + get + { + return rec.strid; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/MultipleMasters/VarNamedStyle.cs b/SharpFont/Source/SharpFontShared/MultipleMasters/VarNamedStyle.cs new file mode 100644 index 000000000..c6a5c2234 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/MultipleMasters/VarNamedStyle.cs @@ -0,0 +1,96 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.MultipleMasters.Internal; + +namespace SharpFont.MultipleMasters +{ + /// + /// A simple structure used to model a named style in a GX var font. + /// + /// This structure can't be used for MM fonts. + /// + public class VarNamedStyle + { + #region Fields + + private IntPtr reference; + private VarNamedStyleRec rec; + + #endregion + + #region Constructors + + internal VarNamedStyle(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the design coordinates for this style. This is an array with one entry for each axis. + /// + public IntPtr Coordinates + { + get + { + return rec.coords; + } + } + + /// + /// Gets the entry in ‘name’ table identifying this style. + /// + [CLSCompliant(false)] + public uint StrId + { + get + { + return rec.strid; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/OpenArgs.cs b/SharpFont/Source/SharpFontShared/OpenArgs.cs new file mode 100644 index 000000000..d32ac6d2b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OpenArgs.cs @@ -0,0 +1,204 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A structure used to indicate how to open a new font file or stream. A pointer to such a structure can be used + /// as a parameter for the functions and . + /// + /// + /// The stream type is determined by the contents of which are tested in the following order by + /// : + /// + /// + /// If the bit is set, assume that this is a memory file of + /// bytes, located at . The data are are not copied, and the client is responsible for + /// releasing and destroying them after the corresponding call to . + /// + /// + /// Otherwise, if the bit is set, assume that a custom input stream + /// is used. + /// + /// + /// Otherwise, if the bit is set, assume that this is a normal file and use + /// to open it. + /// + /// + /// If the bit is set, only tries to open the file + /// with the driver whose handler is in . + /// + /// + /// If the bit is set, the parameters given by and + /// is used. They are ignored otherwise. + /// + /// + /// Ideally, both the and fields should be tagged as ‘const’; this is + /// missing for API backwards compatibility. In other words, applications should treat them as read-only. + /// + public sealed class OpenArgs + { + #region Fields + + private IntPtr reference; + private OpenArgsRec rec; + + #endregion + + #region Constructors + + internal OpenArgs(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets a set of bit flags indicating how to use the structure. + /// + public OpenFlags Flags + { + get + { + return rec.flags; + } + } + + /// + /// Gets the first byte of the file in memory. + /// + public IntPtr MemoryBase + { + get + { + return rec.memory_base; + } + } + + /// + /// Gets the size in bytes of the file in memory. + /// + public int MemorySize + { + get + { + return (int)rec.memory_size; + } + } + + /// + /// Gets a pointer to an 8-bit file pathname. + /// + public string PathName + { + get + { + return rec.pathname; + } + } + + /// + /// Gets a handle to a source stream object. + /// + public FTStream Stream + { + get + { + return new FTStream(rec.stream); + } + } + + /// + /// Gets the font driver to use to open the face. If set to 0, FreeType tries to load the face with each one of + /// the drivers in its list. + /// + /// This field is exclusively used by . + public Module Driver + { + get + { + return new Module(rec.driver); + } + } + + /// + /// Gets the number of extra parameters. + /// + public int ParamsCount + { + get + { + return rec.num_params; + } + } + + /// + /// Gets the extra parameters passed to the font driver when opening a new face. + /// + public Parameter[] Params + { + get + { + int count = ParamsCount; + + if (count == 0) + return null; + + Parameter[] parameters = new Parameter[count]; + IntPtr array = rec.@params; + + for (int i = 0; i < count; i++) + { + parameters[i] = new Parameter(new IntPtr(array.ToInt64() + ParameterRec.SizeInBytes * i)); + } + + return parameters; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/OpenFlags.cs b/SharpFont/Source/SharpFontShared/OpenFlags.cs new file mode 100644 index 000000000..84af4fdd7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OpenFlags.cs @@ -0,0 +1,54 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants used within the ‘flags’ field of the structure. + /// + /// + /// The , , and flags + /// are mutually exclusive. + /// + [Flags] + public enum OpenFlags + { + /// This is a memory-based stream. + Memory = 0x01, + + /// Copy the stream from the ‘stream’ field. + Stream = 0x02, + + /// Create a new input stream from a C path name. + PathName = 0x04, + + /// Use the ‘driver’ field. + Driver = 0x08, + + /// Use the ‘num_params’ and ‘params’ fields. + Params = 0x10 + } +} diff --git a/SharpFont/Source/SharpFontShared/OpenTypeValidationFlags.cs b/SharpFont/Source/SharpFontShared/OpenTypeValidationFlags.cs new file mode 100644 index 000000000..559f4d810 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OpenTypeValidationFlags.cs @@ -0,0 +1,58 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants used with to indicate which OpenType tables + /// should be validated. + /// + [Flags] + [CLSCompliant(false)] + public enum OpenTypeValidationFlags : uint + { + /// Validate BASE table. + Base = 0x0100, + + /// Validate GDEF table. + Gdef = 0x0200, + + /// Validate GPOS table. + Gpos = 0x0400, + + /// Validate GSUB table. + Gsub = 0x0800, + + /// Validate JSTF table. + Jstf = 0x1000, + + /// Validate MATH table. + Math = 0x2000, + + /// Validate all OpenType tables. + All = Base | Gdef | Gpos | Gsub | Jstf | Math + } +} diff --git a/SharpFont/Source/SharpFontShared/Orientation.cs b/SharpFont/Source/SharpFontShared/Orientation.cs new file mode 100644 index 000000000..c609c2749 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Orientation.cs @@ -0,0 +1,66 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of values used to describe an outline's contour orientation. + /// + /// The TrueType and PostScript specifications use different conventions to determine whether outline contours + /// should be filled or unfilled. + /// + public enum Orientation + { + /// + /// According to the TrueType specification, clockwise contours must be filled, and counter-clockwise ones must + /// be unfilled. + /// + TrueType = 0, + + /// + /// According to the PostScript specification, counter-clockwise contours must be filled, and clockwise ones + /// must be unfilled. + /// + PostScript = 1, + + /// + /// This is identical to , but is used to remember that in TrueType, everything that is + /// to the right of the drawing direction of a contour must be filled. + /// + FillRight = TrueType, + + /// + /// This is identical to , but is used to remember that in PostScript, everything that + /// is to the left of the drawing direction of a contour must be filled. + /// + FillLeft = PostScript, + + /// + /// The orientation cannot be determined. That is, different parts of the glyph have different orientation. + /// + None + } +} diff --git a/SharpFont/Source/SharpFontShared/Outline.cs b/SharpFont/Source/SharpFontShared/Outline.cs new file mode 100644 index 000000000..6e6dc8463 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Outline.cs @@ -0,0 +1,698 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// This structure is used to describe an outline to the scan-line converter. + /// + /// + /// The B/W rasterizer only checks bit 2 in the ‘tags’ array for the first point of each contour. The drop-out mode + /// as given with , , and + /// in ‘flags’ is then overridden. + /// + public sealed class Outline : IDisposable + { + #region Fields + + private bool disposed; + private bool duplicate; + + private IntPtr reference; + private OutlineRec rec; + + private Library parentLibrary; + private Memory parentMemory; + + #endregion + + #region Constructor + + /// + /// Initializes a new instance of the class. + /// + /// + /// The reason why this function takes a ‘library’ parameter is simply to use the library's memory allocator. + /// + /// + /// A handle to the library object from where the outline is allocated. Note however that the new outline will + /// not necessarily be freed, when destroying the library, by . + /// + /// The maximum number of points within the outline. + /// The maximum number of contours within the outline. + [CLSCompliant(false)] + public Outline(Library library, uint pointsCount, int contoursCount) + { + IntPtr reference; + Error err = FT.FT_Outline_New(library.Reference, pointsCount, contoursCount, out reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + parentLibrary = library; + parentLibrary.AddChildOutline(this); + } + + /// + /// Initializes a new instance of the class. + /// + /// A handle to the memory object from where the outline is allocated. + /// The maximum number of points within the outline. + /// The maximum number of contours within the outline. + [CLSCompliant(false)] + public Outline(Memory memory, uint pointsCount, int contoursCount) + { + IntPtr reference; + Error err = FT.FT_Outline_New_Internal(memory.Reference, pointsCount, contoursCount, out reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + parentMemory = memory; //TODO Should Memory be disposable as well? + } + + internal Outline(IntPtr reference, OutlineRec outlineInt) + { + this.rec = outlineInt; + this.reference = reference; + + duplicate = true; + } + + /// + /// Finalizes an instance of the class. + /// + ~Outline() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + /// + /// Gets the number of contours in the outline. + /// + public short ContoursCount + { + get + { + if (disposed) + throw new ObjectDisposedException("ContoursCount", "Cannot access a disposed object."); + + return rec.n_contours; + } + } + + /// + /// Gets the number of points in the outline. + /// + public short PointsCount + { + get + { + if (disposed) + throw new ObjectDisposedException("PointsCount", "Cannot access a disposed object."); + + return rec.n_points; + } + } + + /// + /// Gets a pointer to an array of ‘PointsCount’ elements, giving the outline's point + /// coordinates. + /// + public FTVector[] Points + { + get + { + if (disposed) + throw new ObjectDisposedException("Points", "Cannot access a disposed object."); + + int count = PointsCount; + + if (count == 0) + return null; + + FTVector[] points = new FTVector[count]; + IntPtr array = rec.points; + + for (int i = 0; i < count; i++) + { + points[i] = new FTVector(new IntPtr(array.ToInt64() + (IntPtr.Size * i * 2))); + } + + return points; + } + } + + /// + /// Gets a pointer to an array of ‘PointsCount’ chars, giving each outline point's type. + /// + /// If bit 0 is unset, the point is ‘off’ the curve, i.e., a Bézier control point, while it is ‘on’ if set. + /// + /// Bit 1 is meaningful for ‘off’ points only. If set, it indicates a third-order Bézier arc control point; and + /// a second-order control point if unset. + /// + /// If bit 2 is set, bits 5-7 contain the drop-out mode (as defined in the OpenType specification; the value is + /// the same as the argument to the SCANMODE instruction). + /// + /// Bits 3 and 4 are reserved for internal purposes. + /// + public byte[] Tags + { + get + { + if (disposed) + throw new ObjectDisposedException("Tags", "Cannot access a disposed object."); + + int count = PointsCount; + + if (count == 0) + return null; + + byte[] tags = new byte[count]; + IntPtr array = rec.tags; + + for (int i = 0; i < count; i++) + { + tags[i] = Marshal.ReadByte(array, sizeof(byte) * i); + } + + return tags; + } + } + + /// + /// Gets an array of ‘ContoursCount’ shorts, giving the end point of each contour within the outline. For + /// example, the first contour is defined by the points ‘0’ to ‘Contours[0]’, the second one is defined by the + /// points ‘Contours[0]+1’ to ‘Contours[1]’, etc. + /// + public short[] Contours + { + get + { + if (disposed) + throw new ObjectDisposedException("Contours", "Cannot access a disposed object."); + + int count = ContoursCount; + + if (count == 0) + return null; + + short[] contours = new short[count]; + IntPtr array = rec.contours; + + for (int i = 0; i < count; i++) + { + contours[i] = Marshal.ReadInt16(array, sizeof(short) * i); + } + + return contours; + } + } + + /// + /// Gets a set of bit flags used to characterize the outline and give hints to the scan-converter and hinter on + /// how to convert/grid-fit it. + /// + /// + public OutlineFlags Flags + { + get + { + if (disposed) + throw new ObjectDisposedException("Flags", "Cannot access a disposed object."); + + return rec.flags; + } + } + + 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(reference); + } + } + + #endregion + + #region Methods + + #region Outline Processing + + /// + /// Copy an outline into another one. Both objects must have the same sizes (number of points & number of + /// contours) when this function is called. + /// + /// A handle to the target outline. + public void Copy(Outline target) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + if (target == null) + throw new ArgumentNullException("target"); + + IntPtr targetRef = target.Reference; + Error err = FT.FT_Outline_Copy(reference, ref targetRef); + target.Reference = reference; + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Apply a simple translation to the points of an outline. + /// + /// The horizontal offset. + /// The vertical offset. + public void Translate(int offsetX, int offsetY) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + FT.FT_Outline_Translate(reference, offsetX, offsetY); + } + + /// + /// Apply a simple 2x2 matrix to all of an outline's points. Useful for applying rotations, slanting, flipping, + /// etc. + /// + /// + /// You can use if you need to translate the outline's points. + /// + /// A pointer to the transformation matrix. + public void Transform(FTMatrix matrix) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + FT.FT_Outline_Transform(reference, ref matrix); + } + + /// + /// Embolden an outline. The new outline will be at most 4 times ‘strength’ pixels wider and higher. You may + /// think of the left and bottom borders as unchanged. + /// + /// Negative ‘strength’ values to reduce the outline thickness are possible also. + /// + /// + /// The used algorithm to increase or decrease the thickness of the glyph doesn't change the number of points; + /// this means that certain situations like acute angles or intersections are sometimes handled incorrectly. + /// + /// If you need ‘better’ metrics values you should call or . + /// + /// + /// FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); + /// if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE ) + /// FT_Outline_Embolden( &face->slot->outline, strength ); + /// + /// How strong the glyph is emboldened. Expressed in 26.6 pixel format. + public void Embolden(Fixed26Dot6 strength) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + Error err = FT.FT_Outline_Embolden(reference, (IntPtr)strength.Value); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Embolden an outline. The new outline will be ‘xstrength’ pixels wider and ‘ystrength’ pixels higher. + /// Otherwise, it is similar to , which uses the same strength in both directions. + /// + /// + /// How strong the glyph is emboldened in the X direction. Expressed in 26.6 pixel format. + /// + /// + /// How strong the glyph is emboldened in the Y direction. Expressed in 26.6 pixel format. + /// + public void EmboldenXY(int strengthX, int strengthY) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + Error err = FT.FT_Outline_EmboldenXY(reference, strengthX, strengthY); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Reverse the drawing direction of an outline. This is used to ensure consistent fill conventions for + /// mirrored glyphs. + /// + /// + /// This function toggles the bit flag in the outline's ‘flags’ field. + /// + /// It shouldn't be used by a normal client application, unless it knows what it is doing. + /// + public void Reverse() + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + FT.FT_Outline_Reverse(reference); + } + + /// + /// Check the contents of an outline descriptor. + /// + public void Check() + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + Error err = FT.FT_Outline_Check(reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Compute the exact bounding box of an outline. This is slower than computing the control box. However, it + /// uses an advanced algorithm which returns very quickly when the two boxes coincide. Otherwise, the outline + /// Bézier arcs are traversed to extract their extrema. + /// + /// + /// If the font is tricky and the glyph has been loaded with , the resulting + /// BBox is meaningless. To get reasonable values for the BBox 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 BBox which can be eventually converted back to font units. + /// + /// The outline's exact bounding box. + public BBox GetBBox() + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + BBox bbox; + Error err = FT.FT_Outline_Get_BBox(reference, out bbox); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + return bbox; + } + + /// + /// Walk over an outline's structure to decompose it into individual segments and Bézier arcs. This function + /// also emits ‘move to’ operations to indicate the start of new contours in the outline. + /// + /// + /// A table of ‘emitters’, i.e., function pointers called during decomposition to indicate path operations. + /// + /// + /// A typeless pointer which is passed to each emitter during the decomposition. It can be used to store the + /// state during the decomposition. + /// + public void Decompose(OutlineFuncs funcInterface, IntPtr user) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + if (funcInterface == null) + throw new ArgumentNullException("funcInterface"); + + OutlineFuncsRec ofRec = funcInterface.Record; + Error err = FT.FT_Outline_Decompose(reference, ref ofRec, user); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Return an outline'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). + /// + /// 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. + /// + /// See for a discussion of tricky fonts. + /// The outline's control box. + public BBox GetCBox() + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + BBox cbox; + FT.FT_Outline_Get_CBox(reference, out cbox); + + return cbox; + } + + /// + /// Render an outline within a bitmap. The outline's image is simply OR-ed to the target bitmap. + /// + /// + /// This function does NOT CREATE the bitmap, it only renders an outline image within the one you pass to it! + /// Consequently, the various fields in ‘abitmap’ should be set accordingly. + /// + /// It will use the raster corresponding to the default glyph format. + /// + /// The value of the ‘num_grays’ field in ‘abitmap’ is ignored. If you select the gray-level rasterizer, and + /// you want less than 256 gray levels, you have to use directly. + /// + /// A pointer to the target bitmap descriptor. + public void GetBitmap(FTBitmap bitmap) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + Error err = FT.FT_Outline_Get_Bitmap(parentLibrary.Reference, reference, bitmap.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Render an outline within a bitmap. The outline's image is simply OR-ed to the target bitmap. + /// + /// + /// This function does NOT CREATE the bitmap, it only renders an outline image within the one you pass to it! + /// Consequently, the various fields in ‘abitmap’ should be set accordingly. + /// + /// It will use the raster corresponding to the default glyph format. + /// + /// The value of the ‘num_grays’ field in ‘abitmap’ is ignored. If you select the gray-level rasterizer, and + /// you want less than 256 gray levels, you have to use directly. + /// + /// A handle to a FreeType library object. + /// A pointer to the target bitmap descriptor. + public void GetBitmap(Library library, FTBitmap bitmap) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + if (library == null) + throw new ArgumentNullException("library"); + + if (bitmap == null) + throw new ArgumentNullException("bitmap"); + + Error err = FT.FT_Outline_Get_Bitmap(library.Reference, reference, bitmap.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Render an outline within a bitmap using the current scan-convert. This function uses an + /// structure as an argument, allowing advanced features like direct composition, + /// translucency, etc. + /// + /// + /// You should know what you are doing and how works to use this function. + /// + /// The field ‘params.source’ will be set to ‘outline’ before the scan converter is called, which means that + /// the value you give to it is actually ignored. + /// + /// The gray-level rasterizer always uses 256 gray levels. If you want less gray levels, you have to provide + /// your own span callback. See the value of the ‘flags’ field in the + /// structure for more details. + /// + /// + /// A pointer to an structure used to describe the rendering operation. + /// + public void Render(RasterParams parameters) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + if (parameters == null) + throw new ArgumentNullException("parameters"); + + Error err = FT.FT_Outline_Render(parentLibrary.Reference, reference, parameters.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Render an outline within a bitmap using the current scan-convert. This function uses an + /// structure as an argument, allowing advanced features like direct composition, + /// translucency, etc. + /// + /// + /// You should know what you are doing and how works to use this function. + /// + /// The field ‘params.source’ will be set to ‘outline’ before the scan converter is called, which means that + /// the value you give to it is actually ignored. + /// + /// The gray-level rasterizer always uses 256 gray levels. If you want less gray levels, you have to provide + /// your own span callback. See the value of the ‘flags’ field in the + /// structure for more details. + /// + /// A handle to a FreeType library object. + /// + /// A pointer to an structure used to describe the rendering operation. + /// + public void Render(Library library, RasterParams parameters) + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + if (library == null) + throw new ArgumentNullException("library"); + + if (parameters == null) + throw new ArgumentNullException("parameters"); + + Error err = FT.FT_Outline_Render(library.Reference, reference, parameters.Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// This function analyzes a glyph outline and tries to compute its fill orientation (see + /// ). This is done by computing the direction of each global horizontal and/or + /// vertical extrema within the outline. + /// + /// Note that this will return for empty outlines. + /// + /// The orientation. + public Orientation GetOrientation() + { + if (disposed) + throw new ObjectDisposedException("Outline", "Cannot access a disposed object."); + + return FT.FT_Outline_Get_Orientation(reference); + } + + #endregion + + #region Glyph Stroker + + /// + /// Retrieve the value corresponding to the ‘inside’ borders of a given outline. + /// + /// The border index. for empty or invalid outlines. + public StrokerBorder GetInsideBorder() + { + return FT.FT_Outline_GetInsideBorder(Reference); + } + + /// + /// Retrieve the value corresponding to the ‘outside’ borders of a given outline. + /// + /// The border index. for empty or invalid outlines. + public StrokerBorder GetOutsideBorder() + { + return FT.FT_Outline_GetOutsideBorder(Reference); + } + + #endregion + + /// + /// Disposes an instance of the class. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + + if (!duplicate) + { + if (parentLibrary != null) + FT.FT_Outline_Done(parentLibrary.Reference, reference); + else + FT.FT_Outline_Done_Internal(parentMemory.Reference, 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.RemoveChildOutline(this); + } + + reference = IntPtr.Zero; + rec = default(OutlineRec); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/OutlineFlags.cs b/SharpFont/Source/SharpFontShared/OutlineFlags.cs new file mode 100644 index 000000000..aad16f2f5 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OutlineFlags.cs @@ -0,0 +1,102 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants use for the flags in an outline's ‘flags’ field. + /// + /// + /// The flags , , and + /// are ignored by the smooth rasterizer. + /// + /// There exists a second mechanism to pass the drop-out mode to the B/W rasterizer; see the ‘tags’ field in + /// . + /// + /// Please refer to the description of the ‘SCANTYPE’ instruction in the OpenType specification (in file + /// ‘ttinst1.doc’) how simple drop-outs, smart drop-outs, and stubs are defined. + /// + [Flags] + public enum OutlineFlags + { + /// + /// Value 0 is reserved. + /// + None = 0x0000, + + /// + /// If set, this flag indicates that the outline's field arrays (i.e., ‘points’, ‘flags’, and ‘contours’) are + /// ‘owned’ by the outline object, and should thus be freed when it is destroyed. + /// + Owner = 0x0001, + + /// + /// By default, outlines are filled using the non-zero winding rule. If set to 1, the outline will be filled + /// using the even-odd fill rule (only works with the smooth rasterizer). + /// + EvenOddFill = 0x0002, + + /// + /// By default, outside contours of an outline are oriented in clock-wise direction, as defined in the TrueType + /// specification. This flag is set if the outline uses the opposite direction (typically for Type 1 fonts). + /// This flag is ignored by the scan converter. + /// + ReverseFill = 0x0004, + + /// + /// By default, the scan converter will try to detect drop-outs in an outline and correct the glyph bitmap to + /// ensure consistent shape continuity. If set, this flag hints the scan-line converter to ignore such cases. + /// See below for more information. + /// + IgnoreDropouts = 0x0008, + + /// + /// Select smart dropout control. If unset, use simple dropout control. Ignored if + /// is set. See below for more information. + /// + SmartDropouts = 0x0010, + + /// + /// If set, turn pixels on for ‘stubs’, otherwise exclude them. Ignored if + /// is set. See below for more information. + /// + IncludeStubs = 0x0020, + + /// + /// This flag indicates that the scan-line converter should try to convert this outline to bitmaps with the + /// highest possible quality. It is typically set for small character sizes. Note that this is only a hint that + /// might be completely ignored by a given scan-converter. + /// + HighPrecision = 0x0100, + + /// + /// This flag is set to force a given scan-converter to only use a single pass over the outline to render a + /// bitmap glyph image. Normally, it is set for very large character sizes. It is only a hint that might be + /// completely ignored by a given scan-converter. + /// + SinglePass = 0x0200 + } +} diff --git a/SharpFont/Source/SharpFontShared/OutlineFuncs.cs b/SharpFont/Source/SharpFontShared/OutlineFuncs.cs new file mode 100644 index 000000000..cedfa99c8 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OutlineFuncs.cs @@ -0,0 +1,404 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 +{ + /// + /// A function pointer type used to describe the signature of a ‘move to’ function during outline + /// walking/decomposition. + /// + /// A ‘move to’ is emitted to start a new contour in an outline. + /// + /// A pointer to the target point of the ‘move to’. + /// A typeless pointer which is passed from the caller of the decomposition function. + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int MoveToFunc(ref FTVector to, IntPtr user); + + /// + /// A function pointer type used to describe the signature of a ‘line to’ function during outline + /// walking/decomposition. + /// + /// A ‘line to’ is emitted to indicate a segment in the outline. + /// + /// A pointer to the target point of the ‘line to’. + /// A typeless pointer which is passed from the caller of the decomposition function. + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int LineToFunc(ref FTVector to, IntPtr user); + + /// + /// A function pointer type used to describe the signature of a ‘conic to’ function during outline walking or + /// decomposition. + /// + /// A ‘conic to’ is emitted to indicate a second-order Bézier arc in the outline. + /// + /// + /// An intermediate control point between the last position and the new target in ‘to’. + /// + /// A pointer to the target end point of the conic arc. + /// A typeless pointer which is passed from the caller of the decomposition function. + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int ConicToFunc(ref FTVector control, ref FTVector to, IntPtr user); + + /// + /// A function pointer type used to describe the signature of a ‘cubic to’ function during outline walking or + /// decomposition. + /// + /// A ‘cubic to’ is emitted to indicate a third-order Bézier arc. + /// + /// A pointer to the first Bézier control point. + /// A pointer to the second Bézier control point. + /// A pointer to the target end point. + /// A typeless pointer which is passed from the caller of the decomposition function. + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int CubicToFunc(ref FTVector control1, ref FTVector control2, ref FTVector to, IntPtr user); + + /// + /// A structure to hold various function pointers used during outline decomposition in order to emit segments, + /// conic, and cubic Béziers. + /// + /// + /// The point coordinates sent to the emitters are the transformed version of the original coordinates (this is + /// important for high accuracy during scan-conversion). The transformation is simple: + /// + /// x' = (x << shift) - delta + /// y' = (x << shift) - delta + /// + /// Set the values of ‘shift’ and ‘delta’ to 0 to get the original point coordinates. + /// + public class OutlineFuncs : IDisposable + { + #region Fields + + private bool isDisposed; + + private MoveToFunc moveToFunc; + private LineToFunc lineToFunc; + private ConicToFunc conicToFunc; + private CubicToFunc cubicToFunc; + + private GCHandle moveToPin; + private GCHandle lineToPin; + private GCHandle conicToPin; + private GCHandle cubicToPin; + + private IntPtr moveToPtr; + private IntPtr lineToPtr; + private IntPtr conicToPtr; + private IntPtr cubicToPtr; + + private int shift; + private IntPtr delta; + + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the OutlineFuncs class. + /// + public OutlineFuncs() + { + } + + /// + /// Initializes a new instance of the OutlineFuncs class. + /// + /// The move to delegate. + /// The line to delegate. + /// The conic to delegate. + /// The cubic to delegate. + /// A value to shift by. + /// A delta to transform by. + /// , , + /// , or is . + public OutlineFuncs(MoveToFunc moveTo, LineToFunc lineTo, ConicToFunc conicTo, CubicToFunc cubicTo, int shift, int delta) + { + if (moveTo == null) + { + throw new ArgumentNullException(nameof(moveTo)); + } + if (lineTo == null) + { + throw new ArgumentNullException(nameof(lineTo)); + } + if (conicTo == null) + { + throw new ArgumentNullException(nameof(conicTo)); + } + if (cubicTo == null) + { + throw new ArgumentNullException(nameof(cubicTo)); + } + + moveToFunc = moveTo; + lineToFunc = lineTo; + conicToFunc = conicTo; + cubicToFunc = cubicTo; + + moveToPtr = Marshal.GetFunctionPointerForDelegate(moveToFunc); + lineToPtr = Marshal.GetFunctionPointerForDelegate(lineToFunc); + conicToPtr = Marshal.GetFunctionPointerForDelegate(conicToFunc); + cubicToPtr = Marshal.GetFunctionPointerForDelegate(cubicToFunc); + + this.shift = shift; + this.delta = (IntPtr) delta; + } + + #endregion + + #region Properties + + /// + /// Gets or sets the ‘move to’ emitter. + /// + public MoveToFunc MoveFunction + { + get + { + ThrowIfDisposed(); + return moveToFunc; + } + set + { + ThrowIfDisposed(); + if (moveToPin.IsAllocated) + { + moveToPin.Free(); + } + moveToFunc = value; + moveToPin = GCHandle.Alloc(moveToFunc); + moveToPtr = Marshal.GetFunctionPointerForDelegate(moveToFunc); + } + } + + /// + /// Gets or sets the segment emitter. + /// + public LineToFunc LineFunction + { + + get + { + ThrowIfDisposed(); + return lineToFunc; + } + set + { + ThrowIfDisposed(); + if (lineToPin.IsAllocated) + { + lineToPin.Free(); + } + lineToFunc = value; + lineToPin = GCHandle.Alloc(lineToFunc); + lineToPtr = Marshal.GetFunctionPointerForDelegate(lineToFunc); + } + } + + /// + /// Gets or sets the second-order Bézier arc emitter. + /// + public ConicToFunc ConicFunction + { + + get + { + ThrowIfDisposed(); + return conicToFunc; + } + set + { + ThrowIfDisposed(); + if (conicToPin.IsAllocated) + { + conicToPin.Free(); + } + conicToFunc = value; + conicToPin = GCHandle.Alloc(conicToFunc); + conicToPtr = Marshal.GetFunctionPointerForDelegate(conicToFunc); + } + } + + /// + /// Gets or sets the third-order Bézier arc emitter. + /// + public CubicToFunc CubicFunction + { + + get + { + ThrowIfDisposed(); + return cubicToFunc; + } + set + { + ThrowIfDisposed(); + if (cubicToPin.IsAllocated) + { + cubicToPin.Free(); + } + cubicToFunc = value; + cubicToPin = GCHandle.Alloc(cubicToFunc); + cubicToPtr = Marshal.GetFunctionPointerForDelegate(cubicToFunc); + } + } + + /// + /// Gets or sets the shift that is applied to coordinates before they are sent to the emitter. + /// + public int Shift + { + get + { + ThrowIfDisposed(); + return shift; + } + + set + { + ThrowIfDisposed(); + shift = value; + } + } + + /// + /// Gets the delta that is applied to coordinates before they are sent to the emitter, but after the + /// shift. + /// + public int Delta + { + get + { + ThrowIfDisposed(); + return (int) delta; + } + + /*set + { + funcsInt.delta = (IntPtr)value; + }*/ + } + + //TODO make a reference parameter instead? + //HACK this copies the struct + internal OutlineFuncsRec Record + { + get + { + ThrowIfDisposed(); + var r = new OutlineFuncsRec(); + r.moveTo = moveToPtr; + r.lineTo = lineToPtr; + r.conicTo = conicToPtr; + r.cubicTo = cubicToPtr; + return r; + } + } + + #endregion + + + #region IDisposable + + /// + /// Helper method to throw an exception if the object is disposed. + /// + /// If the object is already disposed + private void ThrowIfDisposed() + { + if (isDisposed) + { + throw new ObjectDisposedException("OutlineFuncs", "The outline funcs has already been disposed."); + } + } + + /// + /// Finalizer which ensures that the pinned delegates are released. + /// + ~OutlineFuncs() + { + Dispose(false); + } + + /// + /// Disposes this outline funcs, releasing any of the resources held by it. + /// + /// + protected virtual void Dispose(bool disposing) + { + if (isDisposed) + { + return; + } + + if (disposing) + { + // If this class later needs any managed resources, they should be included here. + } + if (moveToPin.IsAllocated) + { + moveToPin.Free(); + } + if (lineToPin.IsAllocated) + { + lineToPin.Free(); + } + if (cubicToPin.IsAllocated) + { + cubicToPin.Free(); + } + if (conicToPin.IsAllocated) + { + conicToPin.Free(); + } + isDisposed = true; + + } + + /// + /// Releases the pinned memory on this object. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + + #endregion + + + + } +} diff --git a/SharpFont/Source/SharpFontShared/OutlineGlyph.cs b/SharpFont/Source/SharpFontShared/OutlineGlyph.cs new file mode 100644 index 000000000..c16978d68 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/OutlineGlyph.cs @@ -0,0 +1,177 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A structure used for outline (vectorial) glyph images. This really is a ‘sub-class’ of . + /// + /// + /// You can typecast an to if you have ‘ + /// == ’. This lets you access the outline's content easily. + /// + /// As the outline is extracted from a glyph slot, its coordinates are expressed normally in 26.6 pixels, unless + /// the flag was used in or + /// . + /// + /// The outline's tables are always owned by the object and are destroyed with it. + /// + public class OutlineGlyph : IDisposable + { + #region Fields + + private Glyph original; + private OutlineGlyphRec rec; + + #endregion + + #region Constructors + + internal OutlineGlyph(Glyph original) + { + this.original = original; + Reference = original.Reference; //sets the rec + } + + /// + /// Finalizes an instance of the class. + /// + ~OutlineGlyph() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the object has been disposed. + /// + public bool IsDisposed + { + get + { + return original.IsDisposed; + } + } + + /// + /// Gets the root fields. + /// + public Glyph Root + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object."); + + return original; + } + } + + /// + /// Gets a descriptor for the outline. + /// + public Outline Outline + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object."); + + return new Outline(PInvokeHelper.AbsoluteOffsetOf(Reference, "outline"), rec.outline); + } + } + + internal IntPtr Reference + { + get + { + if (IsDisposed) + throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object."); + + return original.Reference; + } + + set + { + if (IsDisposed) + throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object."); + + rec = PInvokeHelper.PtrToStructure(original.Reference); + } + } + + #endregion + + #region Operators + + /// + /// Casts a back up to a . The eqivalent of + /// . + /// + /// A . + /// A . + public static implicit operator Glyph(OutlineGlyph g) + { + return g.original; + } + + #endregion + + #region Methods + + /// + /// A CLS-compliant version of the implicit cast to . + /// + /// A . + public Glyph ToGlyph() + { + return (Glyph)this; + } + + /// + /// Disposes an instance of the class. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposing) + original.Dispose(); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/PInvokeHelper.cs b/SharpFont/Source/SharpFontShared/PInvokeHelper.cs new file mode 100644 index 000000000..37255140a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PInvokeHelper.cs @@ -0,0 +1,78 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// Helpful methods to make marshalling simpler. + /// + internal static class PInvokeHelper + { + /// + /// A generic wrapper for . + /// + /// The type to cast to. + /// The pointer that holds the struct. + /// A marshalled struct. + internal static T PtrToStructure(IntPtr reference) + { + return (T)Marshal.PtrToStructure(reference, typeof(T)); + } + + /// + /// A method to copy data from one pointer to another, byte by byte. + /// + /// The source pointer. + /// An offset into the source buffer. + /// The destination pointer. + /// An offset into the destination buffer. + /// The number of bytes to copy. + internal static unsafe void Copy(IntPtr source, int sourceOffset, IntPtr destination, int destinationOffset, int count) + { + byte* src = (byte*)source + sourceOffset; + byte* dst = (byte*)destination + destinationOffset; + byte* end = dst + count; + + while (dst != end) + *dst++ = *src++; + } + + /// + /// A common pattern in SharpFont is to pass a pointer to a memory address inside of a struct. This method + /// works for all cases and provides a generic API. + /// + /// + /// The type of the struct to take an offset from. + /// A pointer to the start of a struct. + /// The name of the field to get an offset to. + /// start + the offset of the fieldName field in T. + internal static IntPtr AbsoluteOffsetOf(IntPtr start, string fieldName) + { + return new IntPtr(start.ToInt64() + Marshal.OffsetOf(typeof(T), fieldName).ToInt64()); + } + } +} diff --git a/SharpFont/Source/SharpFontShared/ParamTag.cs b/SharpFont/Source/SharpFontShared/ParamTag.cs new file mode 100644 index 000000000..01570ed8d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/ParamTag.cs @@ -0,0 +1,62 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// Constants used as the tag of structures. + /// + [CLSCompliant(false)] + public enum ParamTag : uint + { + /// + /// A constant used as the tag of structures to make + /// ignore preferred family subfamily names in ‘name’ table since OpenType version 1.4. For backwards + /// compatibility with legacy systems which has 4-face-per-family restriction. + /// + IgnorePreferredFamily = ('i' << 24 | 'g' << 16 | 'p' << 8 | 'f'), + + /// + /// A constant used as the tag of structures to make + /// ignore preferred subfamily names in ‘name’ table since OpenType version 1.4. For backwards compatibility + /// with legacy systems which has 4-face-per-family restriction. + /// + IgnorePreferredSubfamily = ('i' << 24 | 'g' << 16 | 'p' << 8 | 's'), + + /// + /// A constant used as the tag of structures to indicate an incremental loading object + /// to be used by FreeType. + /// + Incremental = ('i' << 24 | 'n' << 16 | 'c' << 8 | 'r'), + + /// + /// A constant used as the tag of an structure to indicate that unpatented methods only + /// should be used by the TrueType bytecode interpreter for a typeface opened by + /// . + /// + UnpatentedHinting = ('u' << 24 | 'n' << 16 | 'p' << 8 | 'a') + } +} diff --git a/SharpFont/Source/SharpFontShared/Parameter.cs b/SharpFont/Source/SharpFontShared/Parameter.cs new file mode 100644 index 000000000..d6d1b2b11 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Parameter.cs @@ -0,0 +1,106 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A simple structure used to pass more or less generic parameters to . + /// + /// + /// The ID and function of parameters are driver-specific. See the various flags for more + /// information. + /// + public sealed class Parameter + { + #region Fields + + private IntPtr reference; + private ParameterRec rec; + + #endregion + + #region Constructors + + internal Parameter(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets a four-byte identification tag. + /// + [CLSCompliant(false)] + public ParamTag Tag + { + get + { + return (ParamTag)rec.tag; + } + } + + /// + /// Gets a pointer to the parameter data. + /// + public IntPtr Data + { + get + { + return rec.data; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + internal ParameterRec Record + { + get + { + return rec; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/PixelMode.cs b/SharpFont/Source/SharpFontShared/PixelMode.cs new file mode 100644 index 000000000..c53d6c0bd --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PixelMode.cs @@ -0,0 +1,87 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An enumeration type used to describe the format of pixels in a given bitmap. Note that additional formats may + /// be added in the future. + /// + public enum PixelMode : byte + { + /// + /// Value 0 is reserved. + /// + None = 0, + + /// + /// A monochrome bitmap, using 1 bit per pixel. Note that pixels are stored in most-significant order (MSB), + /// which means that the left-most pixel in a byte has value 128. + /// + Mono, + + /// + /// An 8-bit bitmap, generally used to represent anti-aliased glyph images. Each pixel is stored in one byte. + /// Note that the number of ‘gray’ levels is stored in the ‘num_grays’ field of the + /// structure (it generally is 256). + /// + Gray, + + /// + /// A 2-bit per pixel bitmap, used to represent embedded anti-aliased bitmaps in font files according to the + /// OpenType specification. We haven't found a single font using this format, however. + /// + Gray2, + + /// + /// A 4-bit per pixel bitmap, representing embedded anti-aliased bitmaps in font files according to the + /// OpenType specification. We haven't found a single font using this format, however. + /// + Gray4, + + /// + /// An 8-bit bitmap, representing RGB or BGR decimated glyph images used for display on LCD displays; the + /// bitmap is three times wider than the original glyph image. See also . + /// + Lcd, + + /// + /// An 8-bit bitmap, representing RGB or BGR decimated glyph images used for display on rotated LCD displays; + /// the bitmap is three times taller than the original glyph image. See also + /// . + /// + VerticalLcd, + + /// + /// An image with four 8-bit channels per pixel, representing a color image (such as emoticons) with alpha + /// channel. For each pixel, the format is BGRA, which means, the blue channel comes first in memory. The color + /// channels are pre-multiplied and in the sRGB colorspace. For example, full red at half-translucent opacity + /// will be represented as ‘00,00,80,80’, not ‘00,00,FF,80’. + /// + /// + Bgra + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/BlendFlags.cs b/SharpFont/Source/SharpFontShared/PostScript/BlendFlags.cs new file mode 100644 index 000000000..dd7c8b5e7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/BlendFlags.cs @@ -0,0 +1,105 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.PostScript +{ + /// + /// A set of flags used to indicate which fields are present in a given blend dictionary (font info or private). + /// Used to support Multiple Masters fonts. + /// + public enum BlendFlags + { + /// + /// The position of the underline stroke. + /// + UnderlinePosition = 0, + + /// + /// The thickness of the underline stroke. + /// + UnderlineThickness, + + /// + /// The angle of italics. + /// + ItalicAngle, + + /// + /// Set if the font contains BlueValues. + /// + BlueValues, + + /// + /// Set if the font contains OtherBlues. + /// + OtherBlues, + + /// + /// Set if the font contains StandardWidth values. + /// + StandardWidth, + + /// + /// Set if the font contains StandardHeight values. + /// + StandardHeight, + + /// + /// Set if the font contains StemSnapWidths. + /// + StemSnapWidths, + + /// + /// Set if the font contains StemSnapHeights. + /// + StemSnapHeights, + + /// + /// Set if the font contains BlueScale values. + /// + BlueScale, + + /// + /// Set if the font contains BlueShift values. + /// + BlueShift, + + /// + /// Set if the font contains FamilyBlues values. + /// + FamilyBlues, + + /// + /// Set if the font contains FamilyOtherBlues values. + /// + FamilyOtherBlues, + + /// + /// Force bold blending. + /// + ForceBold + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/DictionaryKeys.cs b/SharpFont/Source/SharpFontShared/PostScript/DictionaryKeys.cs new file mode 100644 index 000000000..06b49675f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/DictionaryKeys.cs @@ -0,0 +1,271 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.PostScript +{ + /// + /// An enumeration used in calls to to identify the Type 1 dictionary entry to + /// retrieve. + /// + /// + public enum DictionaryKeys + { + /// + /// The font's type. Type 1 fonts must have a value of 1. + /// + FontType, + + /// + /// The font's matrix. Typically scaled 1000:1. + /// + FontMatrix, + + /// + /// The font's general bounding box. + /// + FontBBox, + + /// + /// The font's method of painting characters. Type 1 only supports fill (0) and outline (2). + /// + PaintType, + + /// + /// The font's name. + /// + FontName, + + /// + /// A unique identifier for popular fonts assigned by Adobe. + /// + UniqueId, + + /// + /// The number of characters the font can draw. + /// + NumCharStrings, + + /// + /// The char string key. + /// + CharStringKey, + + /// + /// The char string entry. + /// + CharString, + + /// + /// The font's encoding type. + /// + EncodingType, + + /// + /// The font's encoding entry. + /// + EncodingEntry, + + /// + /// The number of charstring subroutines in the font. + /// + NumSubrs, + + /// + /// The font's subroutines. + /// + Subr, + + /// + /// An array with only one real number entry expressing the dominant width of horizontal stems (measured + /// vertically in character space units). + /// + StdHW, + + /// + /// An array with only one real number entry expressing the dominant width of vertical stems (measured + /// horizontally in character space units). + /// + StdVW, + + /// + /// The number of BlueValues the font defines. The value must be at least 0 and at most 14. (7 integer pairs). + /// + NumBlueValues, + + /// + /// An array of integer pairs. The first pair must be the base overshoot position and the base-line. + /// + BlueValue, + + /// + /// An optional entry that speciï¬es the number of character space units to extend (in both directions) the + /// effect of an alignment zone on a horizontal stem. The default value is 1. + /// + BlueFuzz, + + /// + /// The number of OtherBlue values. The value must be at least 0 and at most 10 (5 integer pairs). + /// + NumOtherBlues, + + /// + /// An optional array of integer pairs very similar to those in . + /// + OtherBlue, + + /// + /// The number of FamilyBlue values. + /// + NumFamilyBlues, + + /// + /// An array of integer pairs very similar to those in . + /// + FamilyBlue, + + /// + /// The number of FamilyOtherBlue values. + /// + NumFamilyOtherBlues, + + /// + /// An array of integer pairs very similar to those in . + /// + FamilyOtherBlue, + + /// + /// An optional entry that controls the point size at which overshoot suppression ceases. The default value is + /// 0.039625. + /// + BlueScale, + + /// + /// An optional entry that indicates a character space distance beyond the flat position of alignment zones at + /// which overshoot enforcement for character features occurs. The default value is 7. + /// + BlueShift, + + /// + /// The number of StemSnapH values. Cannot exceed 12. + /// + NumStemSnapH, + + /// + /// An array of up to 12 real numbers of the most common widths (including the dominant width given in the + /// StdHW array) for horizontal stems (measured vertically). These widths must be sorted in increasing order. + /// + StemSnapH, + + /// + /// The number of StemSnapV values. Cannot exceed 12. + /// + NumStemSnapV, + + /// + /// An array of up to 12 real numbers of the most common widths (including the dominant width given in the + /// StdVW array) for vertical stems (measured horizontally). These widths must be sorted in increasing order. + /// + StemSnapV, + + /// + /// A boolean value indicating whether to force bold characters when a regular character is drawn 1-pixel wide. + /// + ForceBold, + + /// + /// Compatibility entry. Use only for font programs in language group 1. + /// + RndStemUp, + + /// + /// Obsolete. Set to {16 16}. Required. + /// + MinFeature, + + /// + /// An integer specifying the number of random bytes at the beginning of charstrings for encryption. By default + /// this value is 4. + /// + LenIV, + + /// + /// Compatibility entry. Set to 5839. + /// + Password, + + /// + /// Identifies the language group of the font. A value of 0 indicates a language that uses Latin, Greek, + /// Cyrillic, etc. characters. A value of 1 indicates a language that consists of Chinese ideographs, Jpaanese + /// Kanji, and Korean Hangul. The default value is 0. + /// + LanguageGroup, + + /// + /// The version identifier for this font. + /// + Version, + + /// + /// The copyright notice of the font. + /// + Notice, + + /// + /// The fullname of the font. + /// + FullName, + + /// + /// The family name of the font. + /// + FamilyName, + + /// + /// The name of the weight of the font. + /// + Weight, + + /// + /// Whether the font is fixed pitch. + /// + IsFixedPitch, + + /// + /// The position of the underline stroke. + /// + UnderlinePosition, + + /// + /// What types of embedding and usages are allowed. + /// + FSType, + + /// + /// The italic angle. + /// + ItalicAngle + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/EncodingType.cs b/SharpFont/Source/SharpFontShared/PostScript/EncodingType.cs new file mode 100644 index 000000000..900e72f37 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/EncodingType.cs @@ -0,0 +1,55 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.PostScript +{ + /// + /// An enumeration describing the ‘Encoding’ entry in a Type 1 dictionary. + /// + public enum EncodingType + { + /// + /// Not encoded. + /// + None = 0, + /// + /// Array encoding. + /// + Array, + /// + /// Standard encoding. + /// + Standard, + /// + /// ISO Latin 1 encoding. + /// + IsoLatin1, + /// + /// Expert encoding. + /// + Expert + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/FaceDict.cs b/SharpFont/Source/SharpFontShared/PostScript/FaceDict.cs new file mode 100644 index 000000000..4f965b663 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/FaceDict.cs @@ -0,0 +1,209 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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.PostScript.Internal; + +namespace SharpFont.PostScript +{ + /// + /// A structure used to represent data in a CID top-level dictionary. + /// + public class FaceDict + { + #region Fields + + private IntPtr reference; + private FaceDictRec rec; + + #endregion + + #region Constructors + + internal FaceDict(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the Private structure containing more information. + /// + public Private PrivateDictionary + { + get + { + return new Private(rec.private_dict); + } + } + + /// + /// Gets the length of the BuildChar entry. + /// + [CLSCompliant(false)] + public uint BuildCharLength + { + get + { + return rec.len_buildchar; + } + } + + /// + /// Gets whether to force bold characters when a regular character has + /// strokes drawn 1-pixel wide. + /// + public int ForceBoldThreshold + { + get + { + return (int)rec.forcebold_threshold; + } + } + + /// + /// Gets the width of stroke. + /// + public int StrokeWidth + { + get + { + return (int)rec.stroke_width; + } + } + + /// + /// Gets hinting useful for rendering glyphs such as barcodes and logos that + /// have many counters. + /// + public int ExpansionFactor + { + get + { + return (int)rec.expansion_factor; + } + } + + /// + /// Gets the method for painting strokes (fill or outline). + /// + public byte PaintType + { + get + { + return rec.paint_type; + } + } + + /// + /// Gets the type of font. Must be set to 1 for all Type 1 fonts. + /// + public byte FontType + { + get + { + return rec.font_type; + } + } + + /// + /// Gets the matrix that indicates scaling of space units. + /// + public FTMatrix FontMatrix + { + get + { + return rec.font_matrix; + } + } + + /// + /// Gets the offset of the font. + /// + public FTVector FontOffset + { + get + { + return rec.font_offset; + } + } + + /// + /// Gets the number of subroutines. + /// + [CLSCompliant(false)] + public uint SubrsCount + { + get + { + return rec.num_subrs; + } + } + + /// + /// Gets the offset in bytes, from the start of the + /// data section of the CIDFont to the beginning of the SubrMap. + /// + [CLSCompliant(false)] + public uint SubrmapOffset + { + get + { + return (uint)rec.subrmap_offset; + } + } + + /// + /// Gets the number of bytes needed to store the SD value. + /// + public int SDBytes + { + get + { + return rec.sd_bytes; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/FaceInfo.cs b/SharpFont/Source/SharpFontShared/PostScript/FaceInfo.cs new file mode 100644 index 000000000..731a4b775 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/FaceInfo.cs @@ -0,0 +1,267 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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 System.Runtime.InteropServices; + +using SharpFont.PostScript.Internal; + +namespace SharpFont.PostScript +{ + /// + /// A structure used to represent CID Face information. + /// + public class FaceInfo + { + #region Fields + + private IntPtr reference; + private FaceInfoRec rec; + + #endregion + + #region Constructors + + internal FaceInfo(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// The name of the font, usually condensed from FullName. + /// + public string CidFontName + { + get + { + return rec.cid_font_name; + } + } + + /// + /// The version number of the font. + /// + public int CidVersion + { + get + { + return (int)rec.cid_version; + } + } + + /// + /// Gets the string identifying the font's manufacturer. + /// + public string Registry + { + get + { + return rec.registry; + } + } + + /// + /// Gets the unique identifier for the character collection. + /// + public string Ordering + { + get + { + return rec.ordering; + } + } + + /// + /// Gets the identifier (supplement number) of the character collection. + /// + public int Supplement + { + get + { + return rec.supplement; + } + } + + /// + /// Gets the dictionary of font info that is not used by the PostScript interpreter. + /// + public FontInfo FontInfo + { + get + { + return new FontInfo(rec.font_info); + } + } + + /// + /// Gets the coordinates of the corners of the bounding box. + /// + public BBox FontBBox + { + get + { + return rec.font_bbox; + } + } + + /// + /// Gets the value to form UniqueID entries for base fonts within a composite font. + /// + [CLSCompliant(false)] + public uint UidBase + { + get + { + return (uint)rec.uid_base; + } + } + + /// + /// Gets the number of entries in the XUID array. + /// + public int XuidCount + { + get + { + return rec.num_xuid; + } + } + + /// + /// Gets the extended unique IDS that identify the form, which allows + /// the PostScript interpreter to cache the output for reuse. + /// + [CLSCompliant(false)] + public uint[] Xuid + { + get + { + return rec.xuid.Select(x => (uint)x).ToArray(); + } + } + + /// + /// Gets the offset in bytes to the charstring offset table. + /// + [CLSCompliant(false)] + public uint CidMapOffset + { + get + { + return (uint)rec.cidmap_offset; + } + } + + /// + /// Gets the length in bytes of the FDArray index. + /// A value of 0 indicates that the charstring offset table doesn't contain + /// any FDArray indexes. + /// + public int FDBytes + { + get + { + return rec.fd_bytes; + } + } + + /// + /// Gets the length of the offset to the charstring for each CID in the CID font. + /// + public int GDBytes + { + get + { + return rec.gd_bytes; + } + } + + /// + /// Gets the number of valid CIDs in the CIDFont. + /// + [CLSCompliant(false)] + public uint CidCount + { + get + { + return (uint)rec.cid_count; + } + } + + /// + /// Gets the number of entries in the FontDicts array. + /// + public int DictsCount + { + get + { + return rec.num_dicts; + } + } + + /// + /// Gets the set of font dictionaries for this font. + /// + public FaceDict FontDicts + { + get + { + return new FaceDict(PInvokeHelper.AbsoluteOffsetOf(Reference, "font_dicts")); + } + } + + /// + /// The offset of the data. + /// + [CLSCompliant(false)] + public uint DataOffset + { + get + { + return (uint)rec.data_offset; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/FontInfo.cs b/SharpFont/Source/SharpFontShared/PostScript/FontInfo.cs new file mode 100644 index 000000000..7fd879281 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/FontInfo.cs @@ -0,0 +1,157 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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.PostScript.Internal; + +namespace SharpFont.PostScript +{ + /// + /// A structure used to model a Type 1 or Type 2 FontInfo dictionary. Note that for Multiple Master fonts, each + /// instance has its own FontInfo dictionary. + /// + public class FontInfo + { + #region Fields + + private FontInfoRec rec; + + #endregion + + #region Constructors + + internal FontInfo(FontInfoRec rec) + { + this.rec = rec; + } + + #endregion + + #region Properties + + /// + /// The version of the font. + /// + public string Version + { + get + { + return rec.version; + } + } + + /// + /// The copyright notice for the font. + /// + public string Notice + { + get + { + return rec.notice; + } + } + + /// + /// Gets the font's full name. + /// + public string FullName + { + get + { + return rec.full_name; + } + } + + /// + /// Gets the font's family name. + /// + public string FamilyName + { + get + { + return rec.family_name; + } + } + + /// + /// Gets the weight description of the font + /// + public string Weight + { + get + { + return rec.weight; + } + } + + /// + /// Gets italic angle of the font. + /// + public int ItalicAngle + { + get + { + return (int)rec.italic_angle; + } + } + + /// + /// Gets whether the font is fixed pitch. + /// + public bool IsFixedPitch + { + get + { + return rec.is_fixed_pitch == 1; + } + } + + /// + /// Gets the position of the underline. + /// + public short UnderlinePosition + { + get + { + return rec.underline_position; + } + } + + /// + /// Gets the thickness of the underline stroke. + /// + [CLSCompliant(false)] + public ushort UnderlineThickness + { + get + { + return rec.underline_thickness; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceDictRec.cs b/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceDictRec.cs new file mode 100644 index 000000000..482083cb4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceDictRec.cs @@ -0,0 +1,54 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 FT_Long = System.IntPtr; +using FT_ULong = System.UIntPtr; + +namespace SharpFont.PostScript.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct FaceDictRec + { + internal PrivateRec private_dict; + + internal uint len_buildchar; + internal FT_Long forcebold_threshold; + internal FT_Long stroke_width; + internal FT_Long expansion_factor; + + internal byte paint_type; + internal byte font_type; + internal FTMatrix font_matrix; + internal FTVector font_offset; + + internal uint num_subrs; + internal FT_ULong subrmap_offset; + internal int sd_bytes; + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceInfoRec.cs b/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceInfoRec.cs new file mode 100644 index 000000000..c55d0ca76 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/Internal/FaceInfoRec.cs @@ -0,0 +1,69 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 FT_Long = System.IntPtr; +using FT_ULong = System.UIntPtr; + +namespace SharpFont.PostScript.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct FaceInfoRec + { + [MarshalAs(UnmanagedType.LPStr)] + internal string cid_font_name; + internal FT_Long cid_version; + internal int cid_font_type; + + [MarshalAs(UnmanagedType.LPStr)] + internal string registry; + + [MarshalAs(UnmanagedType.LPStr)] + internal string ordering; + internal int supplement; + + internal FontInfoRec font_info; + internal BBox font_bbox; + internal FT_ULong uid_base; + + internal int num_xuid; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + internal FT_ULong[] xuid; + + internal FT_ULong cidmap_offset; + internal int fd_bytes; + internal int gd_bytes; + internal FT_ULong cid_count; + + internal int num_dicts; + internal IntPtr font_dicts; + + internal FT_ULong data_offset; + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/Internal/FontInfoRec.cs b/SharpFont/Source/SharpFontShared/PostScript/Internal/FontInfoRec.cs new file mode 100644 index 000000000..cd06fb2d7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/Internal/FontInfoRec.cs @@ -0,0 +1,56 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.PostScript.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct FontInfoRec + { + [MarshalAs(UnmanagedType.LPStr)] + internal string version; + + [MarshalAs(UnmanagedType.LPStr)] + internal string notice; + + [MarshalAs(UnmanagedType.LPStr)] + internal string full_name; + + [MarshalAs(UnmanagedType.LPStr)] + internal string family_name; + + [MarshalAs(UnmanagedType.LPStr)] + internal string weight; + + internal FT_Long italic_angle; + internal byte is_fixed_pitch; + internal short underline_position; + internal ushort underline_thickness; + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/Internal/PrivateRec.cs b/SharpFont/Source/SharpFontShared/PostScript/Internal/PrivateRec.cs new file mode 100644 index 000000000..52067e914 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/Internal/PrivateRec.cs @@ -0,0 +1,82 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.PostScript.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct PrivateRec + { + internal int unique_id; + internal int lenIV; + + internal byte num_blue_values; + internal byte num_other_blues; + internal byte num_family_blues; + internal byte num_family_other_blues; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)] + internal short[] blue_values; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] + internal short[] other_blues; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)] + internal short[] family_blues; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] + internal short[] family_other_blues; + + internal FT_Long blue_scale; + internal int blue_shift; + internal int blue_fuzz; + + internal ushort standard_width; + internal ushort standard_height; + + internal byte num_snap_widths; + internal byte num_snap_heights; + internal byte force_bold; + internal byte round_stem_up; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)] + internal short[] snap_widths; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)] + internal short[] snap_heights; + + internal FT_Long expansion_factor; + + internal FT_Long language_group; + internal FT_Long password; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + internal short[] min_feature; + } +} diff --git a/SharpFont/Source/SharpFontShared/PostScript/Private.cs b/SharpFont/Source/SharpFontShared/PostScript/Private.cs new file mode 100644 index 000000000..a846d5831 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/PostScript/Private.cs @@ -0,0 +1,346 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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.PostScript.Internal; + +namespace SharpFont.PostScript +{ + /// + /// A structure used to model a Type 1 or Type 2 private dictionary. Note that for Multiple Master fonts, each + /// instance has its own Private dictionary. + /// + public class Private + { + #region Fields + + private PrivateRec rec; + + #endregion + + #region Constructors + + internal Private(PrivateRec rec) + { + this.rec = rec; + } + + #endregion + + #region Properties + + /// + /// Gets the ID unique to the Type 1 font. + /// + public int UniqueId + { + get + { + return rec.unique_id; + } + } + + /// + /// Gets the number of random bytes at the beginning of charstrings (for encryption). + /// + public int LenIV + { + get + { + return rec.lenIV; + } + } + + /// + /// Gets the number of values (pairs) in the Blues array. + /// + public byte BlueValuesCount + { + get + { + return rec.num_blue_values; + } + } + + /// + /// Gets the number of values (pairs) in the OtherBlues array. + /// + public byte OtherBluesCount + { + get + { + return rec.num_other_blues; + } + } + + /// + /// Gets the number of values (pairs) in the FamilyBlues array. + /// + public byte FamilyBluesCount + { + get + { + return rec.num_family_blues; + } + } + + /// + /// Gets the number of values (pairs) in the FamilyOtherBlues array. + /// + public byte FamilyOtherBluesCount + { + get + { + return rec.num_family_other_blues; + } + } + + /// + /// Gets the pairs of blue values. + /// + public short[] BlueValues + { + get + { + return rec.blue_values; + } + } + + /// + /// Gets the pairs of blue values. + /// + public short[] OtherBlues + { + get + { + return rec.other_blues; + } + } + + /// + /// Gets the pairs of blue values. + /// + public short[] FamilyBlues + { + get + { + return rec.family_blues; + } + } + + /// + /// Gets the pairs of blue values. + /// + public short[] FamilyOtherBlues + { + get + { + return rec.family_other_blues; + } + } + + /// + /// Gets the point size at which overshoot suppression ceases. + /// + public int BlueScale + { + get + { + return (int)rec.blue_scale; + } + } + + /// + /// Gets whether characters smaller than the size given by BlueScale + /// should have overshoots suppressed. + /// + public int BlueShift + { + get + { + return rec.blue_shift; + } + } + + /// + /// Gets the number of character space units to extend the effect of an + /// alignment zone on a horizontal stem. Setting this to 0 is recommended + /// because it is unreliable. + /// + public int BlueFuzz + { + get + { + return rec.blue_fuzz; + } + } + + /// + /// Indicates the standard stroke width of vertical stems. + /// + [CLSCompliant(false)] + public ushort StandardWidth + { + get + { + return rec.standard_width; + } + } + + /// + /// Indicates the standard stroke width of horizontal stems. + /// + [CLSCompliant(false)] + public ushort StandardHeight + { + get + { + return rec.standard_height; + } + } + + /// + /// Indicates the number of values in the SnapWidths array. + /// + public byte SnapWidthsCount + { + get + { + return rec.num_snap_widths; + } + } + + /// + /// Indicates the number of values in the SnapHeights array. + /// + public byte SnapHeightsCount + { + get + { + return rec.num_snap_heights; + } + } + + /// + /// Gets whether bold characters should appear thicker than non-bold characters + /// at very small point sizes, where otherwise bold characters might appear the + /// same as non-bold characters. + /// + public bool ForceBold + { + get + { + return rec.force_bold == 1; + } + } + + /// + /// Superseded by the LanguageGroup entry. + /// + public bool RoundStemUp + { + get + { + return rec.round_stem_up == 1; + } + } + + /// + /// StemSnapH is an array of up to 12 values of the most common stroke widths for horizontal stems + /// (measured vertically). + /// + public short[] SnapWidths + { + get + { + return rec.snap_widths; + } + } + + /// + /// StemSnapV is an array of up to 12 values of the most common stroke widths for vertical stems + /// (measured horizontally). + /// + public short[] SnapHeights + { + get + { + return rec.snap_heights; + } + } + + /// + /// The Expansion Factor provides a limit for changing character bounding boxes during + /// processing that adjusts the size of fonts of Language Group 1. + /// + public int ExpansionFactor + { + get + { + return (int)rec.expansion_factor; + } + } + + /// + /// Indicates the aesthetic characteristics of the font. Currently, only LanguageGroup 0 + /// (e.g. Latin, Greek, Cyrillic, etc.) and LanguageGroup 1 (e.g. Chinese ideographs, Japanese + /// Kanji, etc) are recognized. + /// + public int LanguageGroup + { + get + { + return (int)rec.language_group; + } + } + + /// + /// The Password value is required for the Type 1 BuildChar to operate. + /// It must be set to 5839. + /// + public int Password + { + get + { + return (int)rec.password; + } + } + + /// + /// The MinFeature value is required for the Type 1 BuildChar to operate, but is obsolete. + /// It must be set to {16,16}. + /// + public short[] MinFeature + { + get + { + return rec.min_feature; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Properties/AssemblyInfo.cs b/SharpFont/Source/SharpFontShared/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..05fe76079 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Properties/AssemblyInfo.cs @@ -0,0 +1,67 @@ +#region MIT License +/*Copyright (c) 2012-2016, Robert Rouhani + +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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: CLSCompliant(true)] +[assembly: InternalsVisibleTo("SharpFont.HarfBuzz, PublicKey=0024000004800000940000000602000000240000525341310004000001000100bfa6d85b0d27c914bc0fe0b18b7f05e0b2ac082c9e154b1739325f4e5537a3dc24712151df168ff0b28699c42cfc39f5f604c6321615d0dc1cd295422d2d244a172d24de1b01d1ced6854ed8d0cc82dd20409a1555f355160612869002de0bc9a9e50eaaa762ec4ebb46943adc18e829a0eb2ee45f47a2d9d46e808c736c77e9")] + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharpFont")] +[assembly: AssemblyDescription("Cross-platform FreeType bindings for C#")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Robmaister")] +[assembly: AssemblyProduct("SharpFont")] +[assembly: AssemblyCopyright("Copyright (c) Robert Rouhani 2012-2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("baf287e3-cfcc-4183-ba83-f23a7ecb8373")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("4.0.1.200")] +[assembly: AssemblyFileVersion("1.0.0.0")] + +//The SemVer version +[assembly: AssemblyInformationalVersion("4.0.1")] diff --git a/SharpFont/Source/SharpFontShared/Raster.cs b/SharpFont/Source/SharpFontShared/Raster.cs new file mode 100644 index 000000000..9bb2824c2 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Raster.cs @@ -0,0 +1,44 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A handle (pointer) to a raster object. Each object can be used independently to convert an outline into a + /// bitmap or pixmap. + /// + public class Raster : NativeObject + { + #region Constructors + + internal Raster(IntPtr reference) : base(reference) + { + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/RasterFlags.cs b/SharpFont/Source/SharpFontShared/RasterFlags.cs new file mode 100644 index 000000000..5b5ef8f2a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/RasterFlags.cs @@ -0,0 +1,64 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of bit flag constants as used in the ‘flags’ field of a structure. + /// + [Flags] + public enum RasterFlags + { + /// + /// This value is 0. + /// + Default = 0x0, + + /// + /// This flag is set to indicate that an anti-aliased glyph image should be generated. Otherwise, it will be + /// monochrome (1-bit). + /// + AntiAlias = 0x1, + + /// + /// This flag is set to indicate direct rendering. In this mode, client applications must provide their own + /// span callback. This lets them directly draw or compose over an existing bitmap. If this bit is not set, the + /// target pixmap's buffer must be zeroed before rendering. + /// + /// Note that for now, direct rendering is only possible with anti-aliased glyphs. + /// + Direct = 0x2, + + /// + /// This flag is only used in direct rendering mode. If set, the output will be clipped to a box specified in + /// the ‘clip_box’ field of the structure. + /// + /// Note that by default, the glyph bitmap is clipped to the target pixmap, except in direct rendering mode + /// where all spans are generated if no clipping box is set. + /// + Clip = 0x4 + } +} diff --git a/SharpFont/Source/SharpFontShared/RasterFuncs.cs b/SharpFont/Source/SharpFontShared/RasterFuncs.cs new file mode 100644 index 000000000..58fd14098 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/RasterFuncs.cs @@ -0,0 +1,210 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A function used to create a new raster object. + /// + /// + /// The ‘memory’ parameter is a typeless pointer in order to avoid un-wanted dependencies on the rest of the + /// FreeType code. In practice, it is an object, i.e., a handle to the standard FreeType + /// memory allocator. However, this field can be completely ignored by a given raster implementation. + /// + /// A handle to the memory allocator. + /// A handle to the new raster object. + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate Error RasterNewFunc(IntPtr memory, NativeReference raster); + + /// + /// A function used to destroy a given raster object. + /// + /// A handle to the raster object. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void RasterDoneFunc(NativeReference raster); + + /// + /// FreeType provides an area of memory called the ‘render pool’, available to all registered rasters. This pool + /// can be freely used during a given scan-conversion but is shared by all rasters. Its content is thus transient. + /// + /// This function is called each time the render pool changes, or just after a new raster object is created. + /// + /// + /// Rasters can ignore the render pool and rely on dynamic memory allocation if they want to (a handle to the + /// memory allocator is passed to the raster constructor). However, this is not recommended for efficiency + /// purposes. + /// + /// A handle to the new raster object. + /// The address in memory of the render pool. + /// The size in bytes of the render pool. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void RasterResetFunc(NativeReference raster, IntPtr pool_base, int pool_size); + + /// + /// This function is a generic facility to change modes or attributes in a given raster. This can be used for + /// debugging purposes, or simply to allow implementation-specific ‘features’ in a given raster module. + /// + /// A handle to the new raster object. + /// A 4-byte tag used to name the mode or property. + /// A pointer to the new mode/property to use. + [CLSCompliant(false)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void RasterSetModeFunc(NativeReference raster, uint mode, IntPtr args); + + /// + /// Invoke a given raster to scan-convert a given glyph image into a target + /// bitmap. + /// + /// + /// The exact format of the source image depends on the raster's glyph format defined in its + /// structure. It can be an or anything else in order to support a + /// large array of glyph formats. + /// + /// Note also that the render function can fail and return a error code if + /// the raster used does not support direct composition. + /// + /// XXX: For now, the standard raster doesn't support direct composition but this should change for the final + /// release (see the files ‘demos/src/ftgrays.c’ and ‘demos/src/ftgrays2.c’ for examples of distinct + /// implementations which support direct composition). + /// + /// A handle to the raster object. + /// + /// A pointer to an structure used to store the rendering parameters. + /// + /// Error code. 0 means success. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate Error RasterRenderFunc(NativeReference raster, NativeReference @params); + + /// + /// A structure used to describe a given raster class to the library. + /// + public class RasterFuncs: NativeObject + { + #region Fields + + private RasterFuncsRec rec; + + #endregion + + #region Constructors + + internal RasterFuncs(IntPtr reference) : base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets the supported glyph format for this raster. + /// + [CLSCompliant(false)] + public GlyphFormat Format + { + get + { + return rec.glyph_format; + } + } + + /// + /// Gets the raster constructor. + /// + public RasterNewFunc New + { + get + { + return rec.raster_new; + } + } + + /// + /// Gets a function used to reset the render pool within the raster. + /// + public RasterResetFunc Reset + { + get + { + return rec.raster_reset; + } + } + + /// + /// Gets a function to set or change modes. + /// + [CLSCompliant(false)] + public RasterSetModeFunc SetMode + { + get + { + return rec.raster_set_mode; + } + } + + /// + /// Gets a function to render a glyph into a given bitmap. + /// + public RasterRenderFunc Render + { + get + { + return rec.raster_render; + } + } + + /// + /// Gets the raster destructor. + /// + public RasterDoneFunc Done + { + get + { + return rec.raster_done; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/RasterParams.cs b/SharpFont/Source/SharpFontShared/RasterParams.cs new file mode 100644 index 000000000..2673bea92 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/RasterParams.cs @@ -0,0 +1,237 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// A function used as a call-back by the anti-aliased renderer in order to let client applications draw themselves + /// the gray pixel spans on each scan line. + /// + /// + /// This callback allows client applications to directly render the gray spans of the anti-aliased bitmap to any + /// kind of surfaces. + /// + /// This can be used to write anti-aliased outlines directly to a given background bitmap, and even perform + /// translucency. + /// + /// Note that the ‘count’ field cannot be greater than a fixed value defined by the ‘FT_MAX_GRAY_SPANS’ + /// configuration macro in ‘ftoption.h’. By default, this value is set to 32, which means that if there are more + /// than 32 spans on a given scanline, the callback is called several times with the same ‘y’ parameter in order to + /// draw all callbacks. + /// + /// Otherwise, the callback is only called once per scan-line, and only for those scanlines that do have ‘gray’ + /// pixels on them. + /// + /// The scanline's y coordinate. + /// The number of spans to draw on this scanline. + /// A table of ‘count’ spans to draw on the scanline. + /// User-supplied data that is passed to the callback. + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void RasterSpanFunc(int y, int count, NativeReference spans, IntPtr user); + + /// + /// THIS TYPE IS DEPRECATED. DO NOT USE IT. + /// + /// A function used as a call-back by the monochrome scan-converter to test whether a given target pixel is already + /// set to the drawing ‘color’. These tests are crucial to implement drop-out control per-se the TrueType spec. + /// + /// The pixel's y coordinate. + /// The pixel's x coordinate. + /// User-supplied data that is passed to the callback. + /// 1 if the pixel is ‘set’, 0 otherwise. + [Obsolete("This type is deprecated. Do not use it. See FreeType docuementation.")] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int RasterBitTestFunc(int y, int x, IntPtr user); + + /// + /// THIS TYPE IS DEPRECATED. DO NOT USE IT. + /// + /// A function used as a call-back by the monochrome scan-converter to set an individual target pixel. This is + /// crucial to implement drop-out control according to the TrueType specification. + /// + /// The pixel's y coordinate. + /// The pixel's x coordinate. + /// User-supplied data that is passed to the callback. + [Obsolete("This type is deprecated. Do not use it. See FreeType docuementation.")] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void RasterBitSetFunc(int y, int x, IntPtr user); + + /// + /// A structure to hold the arguments used by a raster's render function. + /// + /// + /// An anti-aliased glyph bitmap is drawn if the bit flag is set in the ‘flags’ + /// field, otherwise a monochrome bitmap is generated. + /// + /// If the bit flag is set in ‘flags’, the raster will call the ‘gray_spans’ + /// callback to draw gray pixel spans, in the case of an aa glyph bitmap, it will call ‘black_spans’, and + /// ‘bit_test’ and ‘bit_set’ in the case of a monochrome bitmap. This allows direct composition over a pre-existing + /// bitmap through user-provided callbacks to perform the span drawing/composition. + /// + /// Note that the ‘bit_test’ and ‘bit_set’ callbacks are required when rendering a monochrome bitmap, as they are + /// crucial to implement correct drop-out control as defined in the TrueType specification. + /// + public class RasterParams : NativeObject + { + #region Fields + + private RasterParamsRec rec; + + #endregion + + #region Constructors + + internal RasterParams(IntPtr reference) : base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets the target bitmap. + /// + public FTBitmap Target + { + get + { + return new FTBitmap(rec.target, null); + } + } + + /// + /// Gets a pointer to the source glyph image (e.g., an ). + /// + public IntPtr Source + { + get + { + return rec.source; + } + } + + /// + /// Gets the rendering flags. + /// + public RasterFlags Flags + { + get + { + return rec.flags; + } + } + + /// + /// Gets the gray span drawing callback. + /// + public RasterSpanFunc GraySpans + { + get + { + return rec.gray_spans; + } + } + + /// + /// Gets the black span drawing callback. UNIMPLEMENTED! + /// + [Obsolete] + public RasterSpanFunc BlackSpans + { + get + { + return rec.black_spans; + } + } + + /// + /// Gets the bit test callback. UNIMPLEMENTED! + /// + [Obsolete] + public RasterBitTestFunc BitTest + { + get + { + return rec.bit_test; + } + } + + /// + /// Gets the bit set callback. UNIMPLEMENTED! + /// + [Obsolete] + public RasterBitSetFunc BitSet + { + get + { + return rec.bit_set; + } + } + + /// + /// Gets the user-supplied data that is passed to each drawing callback. + /// + public IntPtr User + { + get + { + return rec.user; + } + } + + /// + /// Gets an optional clipping box. It is only used in direct rendering mode. Note that coordinates here should + /// be expressed in integer pixels (and not in 26.6 fixed-point units). + /// + public BBox ClipBox + { + get + { + return rec.clip_box; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/RenderMode.cs b/SharpFont/Source/SharpFontShared/RenderMode.cs new file mode 100644 index 000000000..046c9de22 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/RenderMode.cs @@ -0,0 +1,80 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An enumeration type that lists the render modes supported by FreeType 2. Each mode corresponds to a specific + /// type of scanline conversion performed on the outline. + /// + /// For bitmap fonts and embedded bitmaps the field in the + /// structure gives the format of the returned bitmap. + /// + /// All modes except use 256 levels of opacity. + /// + /// + /// The LCD-optimized glyph bitmaps produced by can be filtered to reduce + /// color-fringes by using (not active in the default builds). It is up to the + /// caller to either call (if available) or do the filtering itself. + /// + /// The selected render mode only affects vector glyphs of a font. Embedded bitmaps often have a different pixel + /// mode like . You can use to transform them into 8-bit + /// pixmaps. + /// + public enum RenderMode + { + /// + /// This is the default render mode; it corresponds to 8-bit anti-aliased bitmaps. + /// + Normal = 0, + + /// + /// This is equivalent to . It is only defined as a separate value because + /// render modes are also used indirectly to define hinting algorithm selectors. + /// + /// + Light, + + /// + /// This mode corresponds to 1-bit bitmaps (with 2 levels of opacity). + /// + Mono, + + /// + /// This mode corresponds to horizontal RGB and BGR sub-pixel displays like LCD screens. It produces 8-bit + /// bitmaps that are 3 times the width of the original glyph outline in pixels, and which use the + /// mode. + /// + Lcd, + + /// + /// This mode corresponds to vertical RGB and BGR sub-pixel displays (like PDA screens, rotated LCD displays, + /// etc.). It produces 8-bit bitmaps that are 3 times the height of the original glyph outline in pixels and + /// use the mode. + /// + VerticalLcd, + } +} diff --git a/SharpFont/Source/SharpFontShared/Renderer.cs b/SharpFont/Source/SharpFontShared/Renderer.cs new file mode 100644 index 000000000..fc93a1a6a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Renderer.cs @@ -0,0 +1,69 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A handle to a given FreeType renderer. A renderer is a special module in charge of converting a glyph image to + /// a bitmap, when necessary. Each renderer supports a given glyph image format, and one or more target surface + /// depths. + /// + public class Renderer + { + #region Fields + + private IntPtr reference; + + #endregion + + #region Constructors + + internal Renderer(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/RendererClass.cs b/SharpFont/Source/SharpFontShared/RendererClass.cs new file mode 100644 index 000000000..4f36342d7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/RendererClass.cs @@ -0,0 +1,150 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The renderer module class descriptor. + /// + public class RendererClass + { + #region Fields + + private IntPtr reference; + private RendererClassRec rec; + + #endregion + + #region Constructors + + internal RendererClass(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the root fields. + /// + public ModuleClass Root + { + get + { + return new ModuleClass(reference); + } + } + + /// + /// Gets the glyph image format this renderer handles. + /// + [CLSCompliant(false)] + public GlyphFormat Format + { + get + { + return rec.glyph_format; + } + } + + /// + /// Gets a method used to render the image that is in a given glyph slot into a bitmap. + /// + public IntPtr RenderGlyph + { + get + { + return rec.render_glyph; + } + } + + /// + /// Gets a method used to transform the image that is in a given glyph slot. + /// + public IntPtr TransformGlyph + { + get + { + return rec.transform_glyph; + } + } + + /// + /// Gets a method used to access the glyph's cbox. + /// + public IntPtr GetGlyphCBox + { + get + { + return rec.get_glyph_cbox; + } + } + + /// + /// Gets a method used to pass additional parameters. + /// + public IntPtr SetMode + { + get + { + return rec.set_mode; + } + } + + /// + /// Gets a pointer to its raster's class. + /// + /// For renderers only. + public RasterFuncs RasterClass + { + get + { + return new RasterFuncs(PInvokeHelper.AbsoluteOffsetOf(Reference, "raster_class")); + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Settings.StyleCop b/SharpFont/Source/SharpFontShared/Settings.StyleCop new file mode 100644 index 000000000..2c2aa1c55 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Settings.StyleCop @@ -0,0 +1,97 @@ + + + + + + Rec\.cs$ + Marhsaler\.cs$ + + + + + + + + + + False + + + + + + + + + + False + + + + + + + + + + False + + + + + False + + + + + + + + + + False + + + + + + + + + + False + + + + + False + + + + + True + True + + + + + + + False + + + + + + + + + + False + + + + + + + \ No newline at end of file diff --git a/SharpFont/Source/SharpFontShared/SharpFontShared.projitems b/SharpFont/Source/SharpFontShared/SharpFontShared.projitems new file mode 100644 index 000000000..545a9af4b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SharpFontShared.projitems @@ -0,0 +1,187 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 2e4773b7-961a-4328-9d77-9749f9071ca2 + + + SharpFont + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SharpFont/Source/SharpFontShared/SharpFontShared.shproj b/SharpFont/Source/SharpFontShared/SharpFontShared.shproj new file mode 100644 index 000000000..3aa2efe8c --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SharpFontShared.shproj @@ -0,0 +1,12 @@ + + + + 2e4773b7-961a-4328-9d77-9749f9071ca2 + + + + + + + + diff --git a/SharpFont/Source/SharpFontShared/SizeMetrics.cs b/SharpFont/Source/SharpFontShared/SizeMetrics.cs new file mode 100644 index 000000000..43de64525 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SizeMetrics.cs @@ -0,0 +1,167 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// The size metrics structure gives the metrics of a size object. + /// + /// + /// The scaling values, if relevant, are determined first during a size changing operation. The remaining fields + /// are then set by the driver. For scalable formats, they are usually set to scaled values of the corresponding + /// fields in . + /// + /// Note that due to glyph hinting, these values might not be exact for certain fonts. Thus they must be treated as + /// unreliable with an error margin of at least one pixel! + /// + /// Indeed, the only way to get the exact metrics is to render all glyphs. As this would be a definite performance + /// hit, it is up to client applications to perform such computations. + /// + /// The structure is valid for bitmap fonts also. + /// + public sealed class SizeMetrics + { + #region Fields + + private SizeMetricsRec rec; + + #endregion + + #region Constructors + + internal SizeMetrics(SizeMetricsRec metricsInternal) + { + rec = metricsInternal; + } + + #endregion + + #region Properties + + /// + /// Gets the width of the scaled EM square in pixels, hence the term ‘ppem’ (pixels per EM). It is also referred to + /// as ‘nominal width’. + /// + [CLSCompliant(false)] + public ushort NominalWidth + { + get + { + return rec.x_ppem; + } + } + + /// + /// Gets the height of the scaled EM square in pixels, hence the term ‘ppem’ (pixels per EM). It is also referred to + /// as ‘nominal height’. + /// + [CLSCompliant(false)] + public ushort NominalHeight + { + get + { + return rec.y_ppem; + } + } + + /// + /// Gets a 16.16 fractional scaling value used to convert horizontal metrics from font units to 26.6 fractional + /// pixels. Only relevant for scalable font formats. + /// + public Fixed16Dot16 ScaleX + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.x_scale); + } + } + + /// + /// Gets a 16.16 fractional scaling value used to convert vertical metrics from font units to 26.6 fractional + /// pixels. Only relevant for scalable font formats. + /// + public Fixed16Dot16 ScaleY + { + get + { + return Fixed16Dot16.FromRawValue((int)rec.y_scale); + } + } + + /// + /// Gets the ascender in 26.6 fractional pixels. + /// + /// + public Fixed26Dot6 Ascender + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.ascender); + } + } + + /// + /// Gets the descender in 26.6 fractional pixels. + /// + /// + public Fixed26Dot6 Descender + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.descender); + } + } + + /// + /// Gets the height in 26.6 fractional pixels. + /// + /// + public Fixed26Dot6 Height + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.height); + } + } + + /// + /// Gets the maximal advance width in 26.6 fractional pixels. + /// + /// + public Fixed26Dot6 MaxAdvance + { + get + { + return Fixed26Dot6.FromRawValue((int)rec.max_advance); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/SizeRequest.cs b/SharpFont/Source/SharpFontShared/SizeRequest.cs new file mode 100644 index 000000000..c2b14ee5a --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SizeRequest.cs @@ -0,0 +1,205 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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 FT_Long = System.IntPtr; +using FT_ULong = System.UIntPtr; + +namespace SharpFont +{ + /// + /// A structure used to model a size request. + /// + /// + /// If is zero, then the horizontal scaling value is set equal to the vertical scaling value, + /// and vice versa. + /// + [StructLayout(LayoutKind.Sequential)] + public struct SizeRequest : IEquatable + { + #region Fields + + private SizeRequestType requestType; + private FT_Long width; + private FT_Long height; + private uint horiResolution; + private uint vertResolution; + + #endregion + + #region Properties + + /// + /// Gets the type of request. See . + /// + public SizeRequestType RequestType + { + get + { + return requestType; + } + + set + { + requestType = value; + } + } + + /// + /// Gets or sets the desired width. + /// + public int Width + { + get + { + return (int)width; + } + + set + { + width = (FT_Long)value; + } + } + + /// + /// Gets or sets the desired height. + /// + public int Height + { + get + { + return (int)height; + } + + set + { + height = (FT_Long)value; + } + } + + /// + /// Gets or sets the horizontal resolution. If set to zero, is treated as a 26.6 fractional pixel + /// value. + /// + [CLSCompliant(false)] + public uint HorizontalResolution + { + get + { + return horiResolution; + } + + set + { + horiResolution = value; + } + } + + /// + /// Gets or sets the horizontal resolution. If set to zero, is treated as a 26.6 fractional pixel + /// value. + /// + [CLSCompliant(false)] + public uint VerticalResolution + { + get + { + return vertResolution; + } + + set + { + vertResolution = value; + } + } + + #endregion + + #region Methods + + /// + /// Compares two s for equality. + /// + /// A . + /// Another . + /// A value indicating equality. + public static bool operator ==(SizeRequest left, SizeRequest right) + { + return left.Equals(right); + } + + /// + /// Compares two s for inequality. + /// + /// A . + /// Another . + /// A value indicating inequality. + public static bool operator !=(SizeRequest left, SizeRequest right) + { + return !left.Equals(right); + } + + /// + /// Compares this instance of to another for equality. + /// + /// A . + /// A value indicating equality. + public bool Equals(SizeRequest other) + { + return requestType == other.requestType && + width == other.width && + height == other.height && + horiResolution == other.horiResolution && + vertResolution == other.vertResolution; + } + + /// + /// Compares this instance of to another object for equality. + /// + /// An object. + /// A value indicating equality. + public override bool Equals(object obj) + { + if (obj is SizeRequest) + return this.Equals((SizeRequest)obj); + else + return false; + } + + /// + /// Gets a unique hash code for this instance. + /// + /// A unique hash code. + public override int GetHashCode() + { + return requestType.GetHashCode() ^ width.GetHashCode() ^ height.GetHashCode() ^ horiResolution.GetHashCode() ^ vertResolution.GetHashCode(); + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/SizeRequestType.cs b/SharpFont/Source/SharpFontShared/SizeRequestType.cs new file mode 100644 index 000000000..76e90d671 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SizeRequestType.cs @@ -0,0 +1,70 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// An enumeration type that lists the supported size request types. + /// + /// + /// The above descriptions only apply to scalable formats. For bitmap formats, the behaviour is up to the driver. + /// + /// See the note section of if you wonder how size + /// requesting relates to scaling values. + /// + public enum SizeRequestType + { + /// + /// The nominal size. The ‘units_per_EM’ field of is used to determine both scaling values. + /// + Normal, + + /// + /// The real dimension. The sum of the the ‘ascender’ and (minus of) the ‘descender’ fields of + /// are used to determine both scaling values. + /// + RealDimensions, + + /// + /// The font bounding box. The width and height of the ‘bbox’ field of are used to determine + /// the horizontal and vertical scaling value, respectively. + /// + BoundingBox, + + /// + /// The ‘max_advance_width’ field of is used to determine the horizontal scaling value; the + /// vertical scaling value is determined the same way as does. + /// Finally, both scaling values are set to the smaller one. This type is useful if you want to specify the + /// font size for, say, a window of a given dimension and 80x24 cells. + /// + Cell, + + /// + /// Specify the scaling values directly. + /// + Scales + } +} diff --git a/SharpFont/Source/SharpFontShared/Span.cs b/SharpFont/Source/SharpFontShared/Span.cs new file mode 100644 index 000000000..f154955c5 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Span.cs @@ -0,0 +1,112 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A structure used to model a single span of gray (or black) pixels when rendering a monochrome or anti-aliased + /// bitmap. + /// + /// + /// This structure is used by the span drawing callback type named which takes the y + /// coordinate of the span as a a parameter. + /// + /// The coverage value is always between 0 and 255. If you want less gray values, the callback function has to + /// reduce them. + /// + public class Span : NativeObject + { + #region Fields + + private SpanRec rec; + + #endregion + + #region Constructors + + internal Span(IntPtr reference) : base(reference) + { + } + + #endregion + + #region Properties + + /// + /// Gets the span's horizontal start position. + /// + public short X + { + get + { + return rec.x; + } + } + + /// + /// Gets the span's length in pixels. + /// + [CLSCompliant(false)] + public ushort Length + { + get + { + return rec.len; + } + } + + /// + /// Gets the span color/coverage, ranging from 0 (background) to 255 (foreground). Only used for anti-aliased + /// rendering. + /// + public byte Coverage + { + get + { + return rec.coverage; + } + } + + internal override IntPtr Reference + { + get + { + return base.Reference; + } + + set + { + base.Reference = value; + rec = PInvokeHelper.PtrToStructure(value); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/StreamDesc.cs b/SharpFont/Source/SharpFontShared/StreamDesc.cs new file mode 100644 index 000000000..0962ad697 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/StreamDesc.cs @@ -0,0 +1,94 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A union type used to store either a long or a pointer. This is used to store a file descriptor or a ‘FILE*’ in + /// an input stream. + /// + public class StreamDesc + { + #region Fields + + private IntPtr reference; + private StreamDescRec rec; + + #endregion + + #region Constructors + + internal StreamDesc(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the as a file descriptor. + /// + public int Value + { + get + { + return (int)rec.value; + } + } + + /// + /// Gets the as an input stream (FILE*). + /// + public IntPtr Pointer + { + get + { + return rec.pointer; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/Stroker.cs b/SharpFont/Source/SharpFontShared/Stroker.cs new file mode 100644 index 000000000..9ae79b4ea --- /dev/null +++ b/SharpFont/Source/SharpFontShared/Stroker.cs @@ -0,0 +1,392 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2015 Robert Rouhani + +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 +{ + /// + /// Opaque handler to a path stroker object. + /// + public class Stroker : IDisposable + { + #region Fields + + private IntPtr reference; + private bool disposed; + + private Library parentLibrary; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// FreeType library handle. + public Stroker(Library library) + { + IntPtr strokerRef; + Error err = FT.FT_Stroker_New(library.Reference, out strokerRef); + + if (err != Error.Ok) + throw new FreeTypeException(err); + + Reference = strokerRef; + library.AddChildStroker(this); + parentLibrary = library; + } + + /// + /// Finalizes an instance of the class. + /// + ~Stroker() + { + Dispose(false); + } + + #endregion + + #region Properties + + /// + /// Gets a value indicating whether the has been disposed. + /// + public bool IsDisposed + { + get + { + return disposed; + } + } + + internal IntPtr Reference + { + get + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + return reference; + } + + set + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + reference = value; + } + } + + #endregion + + #region Methods + + /// + /// Reset a stroker object's attributes. + /// + /// + /// The radius is expressed in the same units as the outline coordinates. + /// + /// The border radius. + /// The line cap style. + /// The line join style. + /// + /// The miter limit for the and + /// line join styles, expressed as 16.16 fixed point value. + /// + public void Set(int radius, StrokerLineCap lineCap, StrokerLineJoin lineJoin, Fixed16Dot16 miterLimit) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + FT.FT_Stroker_Set(Reference, radius, lineCap, lineJoin, (IntPtr)miterLimit.Value); + } + + /// + /// Reset a stroker object without changing its attributes. You should call this function before beginning a + /// new series of calls to or . + /// + public void Rewind() + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + FT.FT_Stroker_Rewind(Reference); + } + + /// + /// A convenience function used to parse a whole outline with the stroker. The resulting outline(s) can be + /// retrieved later by functions like and . + /// + /// + /// If ‘opened’ is 0 (the default), the outline is treated as a closed path, and the stroker generates two + /// distinct ‘border’ outlines. + /// + /// If ‘opened’ is 1, the outline is processed as an open path, and the stroker generates a single ‘stroke’ + /// outline. + /// + /// This function calls automatically. + /// + /// The source outline. + /// + /// A boolean. If 1, the outline is treated as an open path instead of a closed one. + /// + public void ParseOutline(Outline outline, bool opened) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + if (outline == null) + throw new ArgumentNullException("outline"); + + Error err = FT.FT_Stroker_ParseOutline(Reference, outline.Reference, opened); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Start a new sub-path in the stroker. + /// + /// + /// This function is useful when you need to stroke a path that is not stored as an + /// object. + /// + /// A pointer to the start vector. + /// A boolean. If 1, the sub-path is treated as an open one. + public void BeginSubPath(FTVector to, bool open) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_BeginSubPath(Reference, ref to, open); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Close the current sub-path in the stroker. + /// + /// + /// You should call this function after . If the subpath was not ‘opened’, this + /// function ‘draws’ a single line segment to the start position when needed. + /// + public void EndSubPath() + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_EndSubPath(Reference); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// ‘Draw’ a single line segment in the stroker's current sub-path, from the last position. + /// + /// + /// You should call this function between and . + /// + /// A pointer to the destination point. + public void LineTo(FTVector to) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_LineTo(Reference, ref to); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// ‘Draw’ a single quadratic Bézier in the stroker's current sub-path, from the last position. + /// + /// + /// You should call this function between and . + /// + /// A pointer to a Bézier control point. + /// A pointer to the destination point. + public void ConicTo(FTVector control, FTVector to) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_ConicTo(Reference, ref control, ref to); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// ‘Draw’ a single cubic Bézier in the stroker's current sub-path, from the last position. + /// + /// + /// You should call this function between and . + /// + /// A pointer to the first Bézier control point. + /// A pointer to second Bézier control point. + /// A pointer to the destination point. + public void CubicTo(FTVector control1, FTVector control2, FTVector to) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_CubicTo(Reference, ref control1, ref control2, ref to); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Call this function once you have finished parsing your paths with the stroker. It returns the number of + /// points and contours necessary to export one of the ‘border’ or ‘stroke’ outlines generated by the stroker. + /// + /// + /// When an outline, or a sub-path, is ‘closed’, the stroker generates two independent ‘border’ outlines, named + /// ‘left’ and ‘right’. + /// + /// When the outline, or a sub-path, is ‘opened’, the stroker merges the ‘border’ outlines with caps. The + /// ‘left’ border receives all points, while the ‘right’ border becomes empty. + /// + /// Use the function instead if you want to retrieve the counts associated to both + /// borders. + /// + /// The border index. + /// The number of points. + /// The number of contours. + [CLSCompliant(false)] + public void GetBorderCounts(StrokerBorder border, out uint pointsCount, out uint contoursCount) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_GetBorderCounts(Reference, border, out pointsCount, out contoursCount); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Call this function after to export the corresponding border to your own + /// structure. + /// + /// Note that this function appends the border points and contours to your outline, but does not try to resize + /// its arrays. + /// + /// + /// Always call this function after to get sure that there is enough room in your + /// object to receive all new data. + /// + /// When an outline, or a sub-path, is ‘closed’, the stroker generates two independent ‘border’ outlines, named + /// ‘left’ and ‘right’. + /// + /// When the outline, or a sub-path, is ‘opened’, the stroker merges the ‘border’ outlines with caps. The + /// ‘left’ border receives all points, while the ‘right’ border becomes empty. + /// + /// Use the function instead if you want to retrieve all borders at once. + /// + /// The border index. + /// The target outline handle. + public void ExportBorder(StrokerBorder border, Outline outline) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + if (outline == null) + throw new ArgumentNullException("outline"); + + FT.FT_Stroker_ExportBorder(Reference, border, outline.Reference); + } + + /// + /// Call this function once you have finished parsing your paths with the stroker. It returns the number of + /// points and contours necessary to export all points/borders from the stroked outline/path. + /// + /// The number of points. + /// The number of contours. + [CLSCompliant(false)] + public void GetCounts(out uint pointsCount, out uint contoursCount) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + Error err = FT.FT_Stroker_GetCounts(Reference, out pointsCount, out contoursCount); + + if (err != Error.Ok) + throw new FreeTypeException(err); + } + + /// + /// Call this function after to export all borders to your own + /// structure. + /// + /// Note that this function appends the border points and contours to your outline, but does not try to resize + /// its arrays. + /// + /// The target outline handle. + public void Export(Outline outline) + { + if (disposed) + throw new ObjectDisposedException("Stroker", "Cannot access a disposed object."); + + if (outline == null) + throw new ArgumentNullException("outline"); + + FT.FT_Stroker_Export(Reference, outline.Reference); + } + + /// + /// Disposes an instance of the class. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (!disposed) + { + disposed = true; + + FT.FT_Stroker_Done(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.RemoveChildStroker(this); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/StrokerBorder.cs b/SharpFont/Source/SharpFontShared/StrokerBorder.cs new file mode 100644 index 000000000..2a08bb3b3 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/StrokerBorder.cs @@ -0,0 +1,53 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// These values are used to select a given stroke border in and + /// . + /// + /// + /// Applications are generally interested in the ‘inside’ and ‘outside’ borders. However, there is no direct + /// mapping between these and the ‘left’ and ‘right’ ones, since this really depends on the glyph's drawing + /// orientation, which varies between font formats. + /// + /// You can however use and to get + /// these. + /// + public enum StrokerBorder + { + /// + /// Select the left border, relative to the drawing direction. + /// + Left = 0, + + /// + /// Select the right border, relative to the drawing direction. + /// + Right + } +} diff --git a/SharpFont/Source/SharpFontShared/StrokerLineCap.cs b/SharpFont/Source/SharpFontShared/StrokerLineCap.cs new file mode 100644 index 000000000..7f43084e2 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/StrokerLineCap.cs @@ -0,0 +1,49 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// These values determine how the end of opened sub-paths are rendered in a stroke. + /// + public enum StrokerLineCap + { + /// + /// The end of lines is rendered as a full stop on the last point itself. + /// + Butt = 0, + + /// + /// The end of lines is rendered as a half-circle around the last point. + /// + Round, + + /// + /// The end of lines is rendered as a square around the last point. + /// + Square + } +} diff --git a/SharpFont/Source/SharpFontShared/StrokerLineJoin.cs b/SharpFont/Source/SharpFontShared/StrokerLineJoin.cs new file mode 100644 index 000000000..770cb2a24 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/StrokerLineJoin.cs @@ -0,0 +1,69 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// These values determine how two joining lines are rendered in a stroker. + /// + public enum StrokerLineJoin + { + /// + /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly. + /// + Round = 0, + + /// + /// Used to render beveled line joins. The outer corner of the joined lines is filled by enclosing the + /// triangular region of the corner with a straight line between the outer corners of each stroke. + /// + Bevel = 1, + + /// + /// Used to render mitered line joins, with fixed bevels if the miter limit is exceeded. The outer edges of the + /// strokes for the two segments are extended until they meet at an angle. If the segments meet at too sharp an + /// angle (such that the miter would extend from the intersection of the segments a distance greater than the + /// product of the miter limit value and the border radius), then a bevel join (see above) is used instead. + /// This prevents long spikes being created. generates a miter line join as used in + /// PostScript and PDF. + /// + MiterVariable = 2, + + /// + /// An alias for , retained for backwards compatibility. + /// + Miter = MiterVariable, + + /// + /// Used to render mitered line joins, with variable bevels if the miter limit is exceeded. The intersection of + /// the strokes is clipped at a line perpendicular to the bisector of the angle between the strokes, at the + /// distance from the intersection of the segments equal to the product of the miter limit value and the border + /// radius. This prevents long spikes being created. generates a mitered line join + /// as used in XPS. + /// + MiterFixed = 3 + } +} diff --git a/SharpFont/Source/SharpFontShared/StyleFlags.cs b/SharpFont/Source/SharpFontShared/StyleFlags.cs new file mode 100644 index 000000000..1951520e3 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/StyleFlags.cs @@ -0,0 +1,49 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 +{ + /// + /// A list of bit-flags used to indicate the style of a given face. These are used in the ‘style_flags’ field of + /// . + /// + /// + /// The style information as provided by FreeType is very basic. More details are beyond the scope and should be + /// done on a higher level (for example, by analyzing various fields of the ‘OS/2’ table in SFNT based fonts). + /// + [Flags] + public enum StyleFlags + { + /// No style flags. + None = 0x00, + + /// Indicates that a given face style is italic or oblique. + Italic = 0x01, + + /// Indicates that a given face is bold. + Bold = 0x02 + } +} diff --git a/SharpFont/Source/SharpFontShared/SubGlyph.cs b/SharpFont/Source/SharpFontShared/SubGlyph.cs new file mode 100644 index 000000000..0db46f1ca --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SubGlyph.cs @@ -0,0 +1,73 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// The subglyph structure is an internal object used to describe subglyphs (for example, in the case of + /// composites). + /// + /// + /// The subglyph implementation is not part of the high-level API, hence the forward structure declaration. + /// + /// You can however retrieve subglyph information with . + /// + public sealed class SubGlyph + { + #region Fields + + private IntPtr reference; + + #endregion + + #region Constructors + + internal SubGlyph(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/SubGlyphFlags.cs b/SharpFont/Source/SharpFontShared/SubGlyphFlags.cs new file mode 100644 index 000000000..8cc64027f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/SubGlyphFlags.cs @@ -0,0 +1,71 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of constants used to describe subglyphs. Please refer to the TrueType specification for the meaning of + /// the various flags. + /// + [Flags] + public enum SubGlyphFlags + { + /// + /// Set this to indicate arguments are word size; otherwise, they are byte size. + /// + ArgsAreWords = 0x0001, + + /// + /// Set this to indicate arguments are X and Y values; otherwise, X and Y indicate point coordinates. + /// + ArgsAreXYValues = 0x0002, + + /// + /// Set this to round XY values to the grid. + /// + RoundXYToGrid = 0x0004, + + /// + /// Set this to indicate the component has a simple scale; otherwise, the scale is 1.0. + /// + Scale = 0x0008, + + /// + /// Set this to indicate that X and Y are scaled independently. + /// + XYScale = 0x0040, + + /// + /// Set this to indicate there is a 2 by 2 transformation used to scale the component. + /// + TwoByTwo = 0x0080, + + /// + /// Set this to forse aw, lsb and rsb for the composite to be equal to those from the original glyph. + /// + UseMyMetrics = 0x0200 + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/EncodingId.cs b/SharpFont/Source/SharpFontShared/TrueType/EncodingId.cs new file mode 100644 index 000000000..ba850c7bc --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/EncodingId.cs @@ -0,0 +1,230 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.TrueType +{ + /// + /// A list of valid values for the ‘encoding_id’ for TT_PLATFORM_APPLE_UNICODE charmaps and name entries. + /// + [CLSCompliant(false)] + public enum AppleEncodingId : ushort + { + /// Unicode version 1.0. + Default = 0, + + /// Unicode 1.1; specifies Hangul characters starting at U+34xx. + Unicode11, + + /// Deprecated (identical to preceding). + Iso10646, + + /// Unicode 2.0 and beyond (UTF-16 BMP only). + Unicode20, + + /// Unicode 3.1 and beyond, using UTF-32. + Unicode32, + + /// From Adobe, not Apple. Not a normal cmap. Specifies variations on a real cmap. + VariantSelector, + } + + /// + /// A list of valid values for the ‘encoding_id’ for TT_PLATFORM_MACINTOSH charmaps and name entries. + /// + [CLSCompliant(false)] + public enum MacEncodingId : ushort + { + /// Roman encoding. + Roman = 0, + + /// Japanese encoding. + Japanese = 1, + + /// Traditional Chinese encoding. + TraditionalChinese = 2, + + /// Korean encoding. + Korean = 3, + + /// Arabic encoding. + Arabic = 4, + + /// Hebrew encoding. + Hebrew = 5, + + /// Greek encoding. + Greek = 6, + + /// Russian encoding. + Russian = 7, + + /// RSymbol encoding. + RSymbol = 8, + + /// Devanagari encoding. + Devanagari = 9, + + /// Gurmukhi encoding. + Gurmukhi = 10, + + /// Gujarati encoding. + Gujarati = 11, + + /// Oriya encoding. + Oriya = 12, + + /// Bengali encoding. + Bengali = 13, + + /// Tamil encoding. + Tamil = 14, + + /// Telugu encoding. + Telugu = 15, + + /// Kannada encoding. + Kannada = 16, + + /// Malayalam encoding. + Malayalam = 17, + + /// Sinhalese encoding. + Sinhalese = 18, + + /// Burmese encoding. + Burmese = 19, + + /// Khmer encoding. + Khmer = 20, + + /// Thai encoding. + Thai = 21, + + /// Laotian encoding. + Laotian = 22, + + /// Georgian encoding. + Georgian = 23, + + /// Amernian encoding. + Armenian = 24, + + /// Maldivian encoding. + Maldivian = 25, + + /// Simplified Chinese encoding. + SimplifiedChinese = 25, + + /// Tibetan encoding. + Tibetan = 26, + + /// Mongolian encoding. + Mongolian = 27, + + /// Geez encoding. + Geez = 28, + + /// Slavic encoding. + Slavic = 29, + + /// Vietnamese encoding. + Vietnamese = 30, + + /// Sindhi encoding. + Sindhi = 31, + + /// No encoding specified. + Uninterpreted = 32, + } + + /// + /// A list of valid values for the ‘encoding_id’ for TT_PLATFORM_MICROSOFT charmaps and name entries. + /// + [CLSCompliant(false)] + public enum MicrosoftEncodingId : ushort + { + /// + /// Corresponds to Microsoft symbol encoding. See FT_ENCODING_MS_SYMBOL. + /// + Symbol = 0, + + /// + /// Corresponds to a Microsoft WGL4 charmap, matching Unicode. See FT_ENCODING_UNICODE. + /// + Unicode = 1, + + /// + /// Corresponds to SJIS Japanese encoding. See FT_ENCODING_SJIS. + /// + Sjis = 2, + + /// + /// Corresponds to Simplified Chinese as used in Mainland China. See FT_ENCODING_GB2312. + /// + GB2312 = 3, + + /// + /// Corresponds to Traditional Chinese as used in Taiwan and Hong Kong. See FT_ENCODING_BIG5. + /// + Big5 = 4, + + /// + /// Corresponds to Korean Wansung encoding. See FT_ENCODING_WANSUNG. + /// + Wansung = 5, + + /// + /// Corresponds to Johab encoding. See FT_ENCODING_JOHAB. + /// + Johab = 6, + + /// + /// Corresponds to UCS-4 or UTF-32 charmaps. This has been added to the OpenType specification version 1.4 + /// (mid-2001.) + /// + Ucs4 = 10, + } + + /// + /// A list of valid values for the ‘encoding_id’ for TT_PLATFORM_ADOBE charmaps. This is a FreeType-specific + /// extension! + /// + [CLSCompliant(false)] + public enum AdobeEncodingId : ushort + { + /// Adobe standard encoding. + Standard = 0, + + /// Adobe expert encoding. + Expert = 1, + + /// Adobe custom encoding. + Custom = 2, + + /// Adobe Latin 1 encoding. + Latin1 = 3 + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/EngineType.cs b/SharpFont/Source/SharpFontShared/TrueType/EngineType.cs new file mode 100644 index 000000000..8b4c88d9e --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/EngineType.cs @@ -0,0 +1,55 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.TrueType +{ + /// + /// A list of values describing which kind of TrueType bytecode engine is implemented in a given + /// instance. It is used by the function. + /// + public enum EngineType + { + /// + /// The library doesn't implement any kind of bytecode interpreter. + /// + None = 0, + + /// + /// The library implements a bytecode interpreter that doesn't support the patented operations of the TrueType + /// virtual machine. + /// + /// Its main use is to load certain Asian fonts which position and scale glyph components with bytecode + /// instructions. It produces bad output for most other fonts. + /// + Unpatented, + + /// + /// The library implements a bytecode interpreter that covers the full instruction set of the TrueType virtual + /// machine (this was governed by patents until May 2010, hence the name). + /// + Patented + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Header.cs b/SharpFont/Source/SharpFontShared/TrueType/Header.cs new file mode 100644 index 000000000..664ab3c2d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Header.cs @@ -0,0 +1,396 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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 System.Runtime.InteropServices; + +using SharpFont.TrueType.Internal; + +namespace SharpFont.TrueType +{ + /// + /// Provides Mac style flags for the header table. + /// + [Flags] + [CLSCompliant(false)] + public enum HeaderMacStyles : ushort + { + /// + /// Bold style. + /// + Bold = 1 << 0, + + /// + /// Italic style. + /// + Italic = 1 << 2, + + /// + /// Underline style. + /// + Underline = 1 << 3, + + /// + /// Outline style. + /// + Outline = 1 << 4, + + /// + /// Shadow style. + /// + Shadow = 1 << 5, + + /// + /// Condensed style. + /// + Condensed = 1 << 6, + + /// + /// Extended style. + /// + Extended = 1 << 7, + + // bits 7-15 are reserved + } + + /// + /// Provides flags for the header table. + /// + [Flags] + [CLSCompliant(false)] + public enum HeaderFLags : ushort + { + /// + /// The baseline for this font is at the y-origin. + /// + BaselineAtOrigin = 1 << 0, + + /// + /// The left side bearing is at the x-origin. + /// + LeftSidebearingAtOrigin = 1 << 1, + + /// + /// The instructions in this font depend on the point size. + /// + InstructionsDependOnPointSize = 1 << 2, + + /// + /// Use integer values only (no fractional ppem sizes) for internal scaler math. + /// + ForcePpemToIntegers = 1 << 3, + + /// + /// Instructions may alter the advance width and therefore, advance widths might not scale linearly. + /// + InstructionsMayAlterAdvance = 1 << 4, + + // Bits 5-10 are not implemented in TrueType, but should be set according to Apple's specification + + /// + /// The font is designed to be laid out vertically, using the x-origin as the vertical baseline. + /// + FontIsVertical = 1 << 5, + + /// + /// This bit is reserved and must be set to zero. + /// + Reserved6 = 1 << 6, + + /// + /// The font requires layout for linguistic rendering, such as in Arabic fonts. + /// + RequiresLayout = 1 << 7, + + /// + /// The font is an AAT font having metamorphosis effects. + /// + HasMetamorphosisEffects = 1 << 8, + + /// + /// The font contains strong right-to-left glyphs. + /// + RightToLeft = 1 << 9, + + /// + /// The font contains Indic effects. + /// + IsIndic = 1 << 10, + + /// + /// The font data has been compressed and decompressed, making the data lossless. + /// + FontDataIsLossless = 1 << 11, + + /// + /// The font has been converted. + /// + FontIsConverted = 1 << 12, + + /// + /// The font is optimized for ClearType display. + /// + FontIsClearTypeOptimized = 1 << 13, + + /// + /// The glyphs in the cmap subtables are generic representations of code points. + /// If unset, those glyphs represent proper support for those code points. + /// + FontIsLastResort = 1 << 14, + + // Bit 15: reserved + } + + /// + /// A structure used to model a TrueType font header table. All fields follow the TrueType specification. + /// + public class Header + { + #region Fields + + private IntPtr reference; + private HeaderRec rec; + + #endregion + + #region Constructors + + internal Header(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// The version number of this table definition. + /// + public int TableVersion + { + get + { + return (int)rec.Table_Version; + } + } + + /// + /// The version number of the font, provided by the font manufacturer. + /// + public int FontRevision + { + get + { + return (int)rec.Font_Revision; + } + } + + /// + /// Provides a checksum of the font. + /// + public int ChecksumAdjust + { + get + { + return (int)rec.Checksum_Adjust; + } + } + + /// + /// Gets the constant 0x5F0F3CF5. + /// + public int MagicNumber + { + get + { + return (int)rec.Magic_Number; + } + } + + /// + /// Gets font flags for miscellaneous information. + /// + [CLSCompliant(false)] + public HeaderFLags Flags + { + get + { + return (HeaderFLags)rec.Flags; + } + } + + /// + /// Gets the designed number of units per em, also referred to as FUnits. + /// + [CLSCompliant(false)] + public ushort UnitsPerEM + { + get + { + return rec.Units_Per_EM; + } + } + + /// + /// Gets the date and time created. + /// + public int[] Created + { + get + { + return rec.Created.Select(x => (int)x).ToArray(); + } + } + + /// + /// Gets the last time modified. + /// + public int[] Modified + { + get + { + return rec.Modified.Select(x => (int)x).ToArray(); + } + } + + /// + /// Get the minimum X value of all glyph bounding boxes. + /// + public short MinimumX + { + get + { + return rec.xMin; + } + } + + /// + /// Get the minimum Y value of all glyph bounding boxes. + /// + public short MinimumY + { + get + { + return rec.yMin; + } + } + + /// + /// Get the maximum X value of all glyph bounding boxes. + /// + public short MaximumX + { + get + { + return rec.xMax; + } + } + + /// + /// Get the maximum Y value of all glyph bounding boxes. + /// + public short MaximumY + { + get + { + return rec.yMax; + } + } + + /// + /// Gets the basic style of the font (bold, etc.). + /// + [CLSCompliant(false)] + public HeaderMacStyles MacStyle + { + get + { + return (HeaderMacStyles)rec.Mac_Style; + } + } + + /// + /// Gets the smallest readable size, in pixels. + /// + [CLSCompliant(false)] + public ushort LowestRecPpem + { + get + { + return rec.Lowest_Rec_PPEM; + } + } + + /// + /// Gets the direction of glyhps (deprecated). + /// + public short FontDirection + { + get + { + return rec.Font_Direction; + } + } + + /// + /// Gets the length of index: 0 for short, 1 for long. + /// + public short IndexToLocFormat + { + get + { + return rec.Index_To_Loc_Format; + } + } + + /// + /// Gets the format of glyph data. + /// + public short GlyphDataFormat + { + get + { + return rec.Glyph_Data_Format; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/HoriHeader.cs b/SharpFont/Source/SharpFontShared/TrueType/HoriHeader.cs new file mode 100644 index 000000000..621db055c --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/HoriHeader.cs @@ -0,0 +1,274 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model a TrueType horizontal header, the ‘hhea’ table, as well as the corresponding + /// horizontal metrics table, i.e., the ‘hmtx’ table. + /// + /// + /// IMPORTANT: The and structures should be identical except for + /// the names of their fields which are different. + /// + /// This ensures that a single function in the ‘ttload’ module is able to read both the horizontal and vertical + /// headers. + /// + public class HoriHeader + { + #region Fields + + private IntPtr reference; + private HoriHeaderRec rec; + + #endregion + + #region Constructors + + internal HoriHeader(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the table version. + /// + public int Version + { + get + { + return (int)rec.Version; + } + } + + /// + /// Gets the font's ascender, i.e., the distance from the baseline to the top-most of all glyph points found in + /// the font. + /// + /// This value is invalid in many fonts, as it is usually set by the font designer, and often reflects only a + /// portion of the glyphs found in the font (maybe ASCII). + /// + /// You should use the ‘sTypoAscender’ field of the OS/2 table instead if you want the correct one. + /// + public short Ascender + { + get + { + return rec.Ascender; + } + } + + /// + /// Gets the font's descender, i.e., the distance from the baseline to the bottom-most of all glyph points + /// found in the font. It is negative. + /// + /// This value is invalid in many fonts, as it is usually set by the font designer, and often reflects only a + /// portion of the glyphs found in the font (maybe ASCII). + /// + /// You should use the ‘sTypoDescender’ field of the OS/2 table instead if you want the correct one. + /// + public short Descender + { + get + { + return rec.Descender; + } + } + + /// + /// Gets the font's line gap, i.e., the distance to add to the ascender and descender to get the BTB, i.e., the + /// baseline-to-baseline distance for the font. + /// + public short LineGap + { + get + { + return rec.Line_Gap; + } + } + + /// + /// Gets the maximum of all advance widths found in the font. It can be used to compute the maximum width of an + /// arbitrary string of text. + /// + [CLSCompliant(false)] + public ushort AdvanceWidthMax + { + get + { + return rec.advance_Width_Max; + } + } + + /// + /// Gets the minimum left side bearing of all glyphs within the font. + /// + public short MinimumLeftSideBearing + { + get + { + return rec.min_Left_Side_Bearing; + } + } + + /// + /// Gets the minimum right side bearing of all glyphs within the font. + /// + public short MinimumRightSideBearing + { + get + { + return rec.min_Right_Side_Bearing; + } + } + + /// + /// Gets the maximum horizontal extent (i.e., the ‘width’ of a glyph's bounding box) for all glyphs in the + /// font. + /// + public short MaximumExtentX + { + get + { + return rec.xMax_Extent; + } + } + + /// + /// Gets the rise coefficient of the cursor's slope of the cursor (slope=rise/run). + /// + public short CaretSlopeRise + { + get + { + return rec.caret_Slope_Rise; + } + } + + /// + /// Gets the run coefficient of the cursor's slope. + /// + public short CaretSlopeRun + { + get + { + return rec.caret_Slope_Run; + } + } + + /// + /// Gets the amount of offset needed to provide best appearance with slanted fonts. + /// Set to 0 for non-slanted fonts. + /// + public short CaretOffset + { + get + { + return rec.caret_Offset; + } + } + + /// + /// Gets the 8 reserved bytes. + /// + public short[] Reserved + { + get + { + return rec.Reserved; + } + } + + /// + /// Gets 0, always. + /// + public short MetricDataFormat + { + get + { + return rec.metric_Data_Format; + } + } + + /// + /// Gets the number of HMetrics entries in the ‘hmtx’ table -- this value can be smaller than the total number + /// of glyphs in the font. + /// + [CLSCompliant(false)] + public ushort HMetricsCount + { + get + { + return rec.number_Of_HMetrics; + } + } + + /// + /// Gets a pointer into the ‘hmtx’ table. + /// + public IntPtr LongMetrics + { + get + { + return rec.long_metrics; + } + } + + /// + /// Gets a pointer into the ‘hmtx’ table. + /// + public IntPtr ShortMetrics + { + get + { + return rec.short_metrics; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/HeaderRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/HeaderRec.cs new file mode 100644 index 000000000..c216ac539 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/HeaderRec.cs @@ -0,0 +1,65 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct HeaderRec + { + internal FT_Long Table_Version; + internal FT_Long Font_Revision; + + internal FT_Long Checksum_Adjust; + internal FT_Long Magic_Number; + + internal ushort Flags; + internal ushort Units_Per_EM; + + private FT_Long created1; + private FT_Long created2; + internal FT_Long[] Created { get { return new[] {created1, created2}; } } + + private FT_Long modified1; + private FT_Long modified2; + internal FT_Long[] Modified { get { return new[] { modified1, modified2 }; } } + + internal short xMin; + internal short yMin; + internal short xMax; + internal short yMax; + + internal ushort Mac_Style; + internal ushort Lowest_Rec_PPEM; + + internal short Font_Direction; + internal short Index_To_Loc_Format; + internal short Glyph_Data_Format; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/HoriHeaderRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/HoriHeaderRec.cs new file mode 100644 index 000000000..19bffee0b --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/HoriHeaderRec.cs @@ -0,0 +1,73 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct HoriHeaderRec + { + internal FT_Long Version; + internal short Ascender; + internal short Descender; + internal short Line_Gap; + + internal ushort advance_Width_Max; + + internal short min_Left_Side_Bearing; + internal short min_Right_Side_Bearing; + internal short xMax_Extent; + internal short caret_Slope_Rise; + internal short caret_Slope_Run; + internal short caret_Offset; + + private fixed short reserved[4]; + internal short[] Reserved + { + get + { + var array = new short[4]; + + fixed (short* p = reserved) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + + return array; + } + } + + internal short metric_Data_Format; + internal ushort number_Of_HMetrics; + + internal IntPtr long_metrics; + internal IntPtr short_metrics; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/MaxProfileRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/MaxProfileRec.cs new file mode 100644 index 000000000..504f48bd4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/MaxProfileRec.cs @@ -0,0 +1,52 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct MaxProfileRec + { + internal FT_Long version; + internal ushort numGlyphs; + internal ushort maxPoints; + internal ushort maxContours; + internal ushort maxCompositePoints; + internal ushort maxCompositeContours; + internal ushort maxZones; + internal ushort maxTwilightPoints; + internal ushort maxStorage; + internal ushort maxFunctionDefs; + internal ushort maxInstructionDefs; + internal ushort maxStackElements; + internal ushort maxSizeOfInstructions; + internal ushort maxComponentElements; + internal ushort maxComponentDepth; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/OS2Rec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/OS2Rec.cs new file mode 100644 index 000000000..d54c52a05 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/OS2Rec.cs @@ -0,0 +1,113 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct OS2Rec + { + internal ushort version; + internal short xAvgCharWidth; + internal ushort usWeightClass; + internal ushort usWidthClass; + internal EmbeddingTypes fsType; + internal short ySubscriptXSize; + internal short ySubscriptYSize; + internal short ySubscriptXOffset; + internal short ySubscriptYOffset; + internal short ySuperscriptXSize; + internal short ySuperscriptYSize; + internal short ySuperscriptXOffset; + internal short ySuperscriptYOffset; + internal short yStrikeoutSize; + internal short yStrikeoutPosition; + internal short sFamilyClass; + + private fixed byte _panose[10]; + internal byte[] panose + { + get + { + var array = new byte[10]; + + fixed (byte* p = _panose) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + + return array; + } + } + + internal FT_ULong ulUnicodeRange1; + internal FT_ULong ulUnicodeRange2; + internal FT_ULong ulUnicodeRange3; + internal FT_ULong ulUnicodeRange4; + + private fixed byte _achVendID[4]; + internal byte[] achVendID + { + get + { + var array = new byte[4]; + + fixed (byte* p = _achVendID) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + + return array; + } + } + + internal ushort fsSelection; + internal ushort usFirstCharIndex; + internal ushort usLastCharIndex; + internal short sTypoAscender; + internal short sTypoDescender; + internal short sTypoLineGap; + internal ushort usWinAscent; + internal ushort usWinDescent; + + internal FT_ULong ulCodePageRange1; + internal FT_ULong ulCodePageRange2; + + internal short sxHeight; + internal short sCapHeight; + internal ushort usDefaultChar; + internal ushort usBreakChar; + internal ushort usMaxContext; + + internal ushort usLowerOpticalPointSize; + internal ushort usUpperOpticalPointSize; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/PCLTRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/PCLTRec.cs new file mode 100644 index 000000000..8638bb49f --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/PCLTRec.cs @@ -0,0 +1,85 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + internal unsafe struct PCLTRec + { + internal FT_Long Version; + internal FT_ULong FontNumber; + internal ushort Pitch; + internal ushort xHeight; + internal ushort Style; + internal ushort TypeFamily; + internal ushort CapHeight; + internal ushort SymbolSet; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] + internal string TypeFace; + + private fixed byte characterComplement[8]; + internal byte[] CharacterComplement + { + get + { + var array = new byte[8]; + fixed (byte* p = characterComplement) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + return array; + } + } + + private fixed byte fileName[6]; + internal byte[] FileName + { + get + { + var array = new byte[6]; + + fixed (byte* p = fileName) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + + return array; + } + } + + internal byte StrokeWeight; + internal byte WidthType; + internal byte SerifStyle; + internal byte Reserved; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/PostscriptRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/PostscriptRec.cs new file mode 100644 index 000000000..c20668ed4 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/PostscriptRec.cs @@ -0,0 +1,46 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct PostscriptRec + { + internal FT_Long FormatType; + internal FT_Long italicAngle; + internal short underlinePosition; + internal short underlineThickness; + internal FT_ULong isFixedPitch; + internal FT_ULong minMemType42; + internal FT_ULong maxMemType42; + internal FT_ULong minMemType1; + internal FT_ULong maxMemType1; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/SfntNameRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/SfntNameRec.cs new file mode 100644 index 000000000..6f21c4977 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/SfntNameRec.cs @@ -0,0 +1,41 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal struct SfntNameRec + { + internal PlatformId platform_id; + internal ushort encoding_id; + internal ushort language_id; + internal ushort name_id; + + internal IntPtr @string; + internal uint string_len; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Internal/VertHeaderRec.cs b/SharpFont/Source/SharpFontShared/TrueType/Internal/VertHeaderRec.cs new file mode 100644 index 000000000..332e8ad01 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Internal/VertHeaderRec.cs @@ -0,0 +1,73 @@ +#region MIT License +/*Copyright (c) 2012-2015 Robert Rouhani + +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.TrueType.Internal +{ + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct VertHeaderRec + { + internal FT_Long Version; + internal short Ascender; + internal short Descender; + internal short Line_Gap; + + internal ushort advance_Height_Max; + + internal short min_Top_Side_Bearing; + internal short min_Bottom_Side_Bearing; + internal short yMax_Extent; + internal short caret_Slope_Rise; + internal short caret_Slope_Run; + internal short caret_Offset; + + private fixed short reserved[4]; + internal short[] Reserved + { + get + { + var array = new short[4]; + + fixed (short* p = reserved) + { + for (int i = 0; i < array.Length; i++) + array[i] = p[i]; + } + + return array; + } + } + + internal short metric_Data_Format; + internal ushort number_Of_VMetrics; + + internal IntPtr long_metrics; + internal IntPtr short_metrics; + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/MaxProfile.cs b/SharpFont/Source/SharpFontShared/TrueType/MaxProfile.cs new file mode 100644 index 000000000..8162c824c --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/MaxProfile.cs @@ -0,0 +1,258 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// The maximum profile is a table containing many max values which can be used to pre-allocate arrays. This + /// ensures that no memory allocation occurs during a glyph load. + /// + /// + /// This structure is only used during font loading. + /// + public class MaxProfile + { + #region Fields + + private IntPtr reference; + private MaxProfileRec rec; + + #endregion + + #region Constructors + + internal MaxProfile(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the version number. + /// + public int Version + { + get + { + return (int)rec.version; + } + } + + /// + /// Gets the number of glyphs in this TrueType font. + /// + [CLSCompliant(false)] + public ushort GlyphCount + { + get + { + return rec.numGlyphs; + } + } + + /// + /// Gets the maximum number of points in a non-composite TrueType glyph. See also the structure element + /// ‘maxCompositePoints’. + /// + [CLSCompliant(false)] + public ushort MaxPoints + { + get + { + return rec.maxPoints; + } + } + + /// + /// Gets the maximum number of contours in a non-composite TrueType glyph. See also the structure element + /// ‘maxCompositeContours’. + /// + [CLSCompliant(false)] + public ushort MaxContours + { + get + { + return rec.maxContours; + } + } + + /// + /// Gets the maximum number of points in a composite TrueType glyph. See also the structure element + /// ‘maxPoints’. + /// + [CLSCompliant(false)] + public ushort MaxCompositePoints + { + get + { + return rec.maxCompositePoints; + } + } + + /// + /// Gets the maximum number of contours in a composite TrueType glyph. See also the structure element + /// ‘maxContours’. + /// + [CLSCompliant(false)] + public ushort MaxCompositeContours + { + get + { + return rec.maxCompositeContours; + } + } + + /// + /// Gets the maximum number of zones used for glyph hinting. + /// + [CLSCompliant(false)] + public ushort MaxZones + { + get + { + return rec.maxZones; + } + } + + /// + /// Gets the maximum number of points in the twilight zone used for glyph hinting. + /// + [CLSCompliant(false)] + public ushort MaxTwilightPoints + { + get + { + return rec.maxTwilightPoints; + } + } + + /// + /// Gets the maximum number of elements in the storage area used for glyph hinting. + /// + [CLSCompliant(false)] + public ushort MaxStorage + { + get + { + return rec.maxStorage; + } + } + + /// + /// Gets the maximum number of function definitions in the TrueType bytecode for this font. + /// + [CLSCompliant(false)] + public ushort MaxFunctionDefs + { + get + { + return rec.maxFunctionDefs; + } + } + + /// + /// Gets the maximum number of instruction definitions in the TrueType bytecode for this font. + /// + [CLSCompliant(false)] + public ushort MaxInstructionDefs + { + get + { + return rec.maxInstructionDefs; + } + } + + /// + /// Gets the maximum number of stack elements used during bytecode interpretation. + /// + [CLSCompliant(false)] + public ushort MaxStackElements + { + get + { + return rec.maxStackElements; + } + } + + /// + /// Gets the maximum number of TrueType opcodes used for glyph hinting. + /// + [CLSCompliant(false)] + public ushort MaxSizeOfInstructions + { + get + { + return rec.maxSizeOfInstructions; + } + } + + /// + /// Gets the maximum number of simple (i.e., non- composite) glyphs in a composite glyph. + /// + [CLSCompliant(false)] + public ushort MaxComponentElements + { + get + { + return rec.maxComponentElements; + } + } + + /// + /// Gets the maximum nesting depth of composite glyphs. + /// + [CLSCompliant(false)] + public ushort MaxComponentDepth + { + get + { + return rec.maxComponentDepth; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/OS2.cs b/SharpFont/Source/SharpFontShared/TrueType/OS2.cs new file mode 100644 index 000000000..cf40219b2 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/OS2.cs @@ -0,0 +1,532 @@ +#region MIT License +/*Copyright (c) 2012-2014 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model a TrueType OS/2 table. This is the long table version. All fields comply to the + /// TrueType specification. + /// + /// Note that we now support old Mac fonts which do not include an OS/2 table. In this case, the ‘version’ field is + /// always set to 0xFFFF. + /// + public class OS2 + { + #region Fields + + private IntPtr reference; + private OS2Rec rec; + + #endregion + + #region Constructors + + internal OS2(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// The version of this table. + /// + [CLSCompliant(false)] + public ushort Version + { + get + { + return rec.version; + } + } + + /// + /// The average glyph width, computed by averaging ALL non-zero width glyphs in the font, in pels/em. + /// + public short AverageCharWidth + { + get + { + return rec.xAvgCharWidth; + } + } + + /// + /// The visual weight of the font. + /// + [CLSCompliant(false)] + public ushort WeightClass + { + get + { + return rec.usWeightClass; + } + } + + /// + /// The relative change in width from the normal aspect ratio. + /// + [CLSCompliant(false)] + public ushort WidthClass + { + get + { + return rec.usWidthClass; + } + } + + /// + /// Font embedding and subsetting licensing rights as determined by the font author. + /// + [CLSCompliant(false)] + public EmbeddingTypes EmbeddingType + { + get + { + return rec.fsType; + } + } + + /// + /// The font author's recommendation for sizing glyphs (em square) to create subscripts when a glyph doesn't exist for a subscript. + /// + public short SubscriptSizeX + { + get + { + return rec.ySubscriptXSize; + } + } + + /// + /// The font author's recommendation for sizing glyphs (em height) to create subscripts when a glyph doesn't exist for a subscript. + /// + public short SubscriptSizeY + { + get + { + return rec.ySubscriptYSize; + } + } + + /// + /// The font author's recommendation for vertically positioning subscripts that are created when a glyph doesn't exist for a subscript. + /// + public short SubscriptOffsetX + { + get + { + return rec.ySubscriptXOffset; + } + } + + /// + /// The font author's recommendation for horizontally positioning subscripts that are created when a glyph doesn't exist for a subscript. + /// + public short SubscriptOffsetY + { + get + { + return rec.ySubscriptYOffset; + } + } + + /// + /// The font author's recommendation for sizing glyphs (em square) to create superscripts when a glyph doesn't exist for a subscript. + /// + public short SuperscriptSizeX + { + get + { + return rec.ySuperscriptXSize; + } + } + + /// + /// The font author's recommendation for sizing glyphs (em height) to create superscripts when a glyph doesn't exist for a subscript. + /// + public short SuperscriptSizeY + { + get + { + return rec.ySuperscriptYSize; + } + } + + /// + /// The font author's recommendation for vertically positioning superscripts that are created when a glyph doesn't exist for a subscript. + /// + public short SuperscriptOffsetX + { + get + { + return rec.ySuperscriptXOffset; + } + } + + /// + /// The font author's recommendation for horizontally positioning superscripts that are created when a glyph doesn't exist for a subscript. + /// + public short SuperscriptOffsetY + { + get + { + return rec.ySuperscriptYOffset; + } + } + + /// + /// The thickness of the strikeout stroke. + /// + public short StrikeoutSize + { + get + { + return rec.yStrikeoutSize; + } + } + + /// + /// The position of the top of the strikeout line relative to the baseline. + /// + public short StrikeoutPosition + { + get + { + return rec.yStrikeoutPosition; + } + } + + /// + /// The IBM font family class and subclass, useful for choosing visually similar fonts. + /// + /// Refer to https://www.microsoft.com/typography/otspec160/ibmfc.htm. + public short FamilyClass + { + get + { + return rec.sFamilyClass; + } + } + + //TODO write a PANOSE class from TrueType spec? + /// + /// The Panose values describe visual characteristics of the font. + /// Similar fonts can then be selected based on their Panose values. + /// + public byte[] Panose + { + get + { + return rec.panose; + } + } + + /// + /// Unicode character range, bits 0-31. + /// + [CLSCompliant(false)] + public uint UnicodeRange1 + { + get + { + return (uint)rec.ulUnicodeRange1; + } + } + + /// + /// Unicode character range, bits 32-63. + /// + [CLSCompliant(false)] + public uint UnicodeRange2 + { + get + { + return (uint)rec.ulUnicodeRange2; + } + } + + /// + /// Unicode character range, bits 64-95. + /// + [CLSCompliant(false)] + public uint UnicodeRange3 + { + get + { + return (uint)rec.ulUnicodeRange3; + } + } + + /// + /// Unicode character range, bits 96-127. + /// + [CLSCompliant(false)] + public uint UnicodeRange4 + { + get + { + return (uint)rec.ulUnicodeRange4; + } + } + + /// + /// The vendor's identifier. + /// + public byte[] VendorId + { + get + { + return rec.achVendID; + } + } + + /// + /// Describes variations in the font. + /// + [CLSCompliant(false)] + public ushort SelectionFlags + { + get + { + return rec.fsSelection; + } + } + + /// + /// The minimum Unicode index (character code) in this font. + /// Since this value is limited to 0xFFFF, applications should not use this field. + /// + [CLSCompliant(false)] + public ushort FirstCharIndex + { + get + { + return rec.usFirstCharIndex; + } + } + + /// + /// The maximum Unicode index (character code) in this font. + /// Since this value is limited to 0xFFFF, applications should not use this field. + /// + [CLSCompliant(false)] + public ushort LastCharIndex + { + get + { + return rec.usLastCharIndex; + } + } + + /// + /// The ascender value, useful for computing a default line spacing in conjunction with unitsPerEm. + /// + public short TypographicAscender + { + get + { + return rec.sTypoAscender; + } + } + + /// + /// The descender value, useful for computing a default line spacing in conjunction with unitsPerEm. + /// + public short TypographicDescender + { + get + { + return rec.sTypoDescender; + } + } + + /// + /// The line gap value, useful for computing a default line spacing in conjunction with unitsPerEm. + /// + public short TypographicLineGap + { + get + { + return rec.sTypoLineGap; + } + } + + /// + /// The ascender metric for Windows, usually set to yMax. Windows will clip glyphs that go above this value. + /// + [CLSCompliant(false)] + public ushort WindowsAscent + { + get + { + return rec.usWinAscent; + } + } + + /// + /// The descender metric for Windows, usually set to yMin. Windows will clip glyphs that go below this value. + /// + [CLSCompliant(false)] + public ushort WindowsDescent + { + get + { + return rec.usWinDescent; + } + } + + /// + /// Specifies the code pages encompassed by this font. + /// + [CLSCompliant(false)] + public uint CodePageRange1 + { + get + { + return (uint)rec.ulCodePageRange1; + } + } + + /// + /// Specifies the code pages encompassed by this font. + /// + [CLSCompliant(false)] + public uint CodePageRange2 + { + get + { + return (uint)rec.ulUnicodeRange1; + } + } + + /// + /// The approximate height of non-ascending lowercase letters relative to the baseline. + /// + public short Height + { + get + { + return rec.sxHeight; + } + } + + /// + /// The approximate height of uppercase letters relative to the baseline. + /// + public short CapHeight + { + get + { + return rec.sCapHeight; + } + } + + /// + /// The Unicode index (character code) of the glyph to use when a glyph doesn't exist for the requested character. + /// Since this value is limited to 0xFFFF, applications should not use this field. + /// + [CLSCompliant(false)] + public ushort DefaultChar + { + get + { + return rec.usDefaultChar; + } + } + + /// + /// The Unicode index (character code) of the glyph to use as the break character. + /// The 'space' character is normally the break character. + /// Since this value is limited to 0xFFFF, applications should not use this field. + /// + [CLSCompliant(false)] + public ushort BreakChar + { + get + { + return rec.usBreakChar; + } + } + + /// + /// The maximum number of characters needed to determine glyph context when applying features such as ligatures. + /// + [CLSCompliant(false)] + public ushort MaxContext + { + get + { + return rec.usMaxContext; + } + } + + /// + /// The lowest point size at which the font starts to be used, in twips. + /// + [CLSCompliant(false)] + public ushort LowerOpticalPointSize + { + get + { + return rec.usLowerOpticalPointSize; + } + } + + /// + /// The highest point size at which the font is no longer used, in twips. + /// + [CLSCompliant(false)] + public ushort UpperOpticalPointSize + { + get + { + return rec.usUpperOpticalPointSize; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Pclt.cs b/SharpFont/Source/SharpFontShared/TrueType/Pclt.cs new file mode 100644 index 000000000..6f9bdd1d7 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Pclt.cs @@ -0,0 +1,251 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model a TrueType PCLT table. All fields comply to the TrueType specification. + /// + public class Pclt + { + #region Fields + + private IntPtr reference; + private PCLTRec rec; + + #endregion + + #region Constructors + + internal Pclt(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// The version number of this table. Version 1.0 is represented as 0x00010000. + /// + public int Version + { + get + { + return (int)rec.Version; + } + } + + /// + /// A unique identifier for the font. Refer to the specification for the meaning of various bits. + /// + [CLSCompliant(false)] + public uint FontNumber + { + get + { + return (uint)rec.FontNumber; + } + } + + /// + /// The width of the space character, in FUnits (see UnitsPerEm in the head table). + /// + [CLSCompliant(false)] + public ushort Pitch + { + get + { + return rec.Pitch; + } + } + + /// + /// The height of the optical height of the lowercase 'x' in FUnits. + /// This is a separate value from its height measurement. + /// + [CLSCompliant(false)] + public ushort Height + { + get + { + return rec.xHeight; + } + } + + /// + /// Describes structural appearance and effects of letterforms. + /// + [CLSCompliant(false)] + public ushort Style + { + get + { + return rec.Style; + } + } + + /// + /// Encodes the font vendor code and font family code into 16 bits. + /// Refer to the spec for details. + /// + [CLSCompliant(false)] + public ushort TypeFamily + { + get + { + return rec.TypeFamily; + } + } + + /// + /// The height of the optical height of the uppercase 'H' in FUnits. + /// This is a separate value from its height measurement. + /// + [CLSCompliant(false)] + public ushort CapHeight + { + get + { + return rec.CapHeight; + } + } + + /// + /// Encodes the symbol set's number field and ID field. + /// Refer to the spec for details. + /// + [CLSCompliant(false)] + public ushort SymbolSet + { + get + { + return rec.SymbolSet; + } + } + + /// + /// The name and style of the font. The names of fonts within a family should be identical and the + /// style identifiers should be standardized: e.g., Bd, It, BdIt. Length is 16 bytes. + /// + public string Typeface + { + get + { + return rec.TypeFace; + } + } + + /// + /// Identifies the symbol collections provided by the font. Length is 8 bytes. + /// Refer to the spec for details. + /// + public byte[] CharacterComplement + { + get + { + return rec.CharacterComplement; + } + } + + /// + /// A standardized filename of the font. Length is 6 bytes. + /// Refer to the spec for details. + /// + public byte[] FileName + { + get + { + return rec.FileName; + } + } + + /// + /// Indicates the stroke weight. Valid values are in the range -7 to 7. Length is 1 byte. + /// + public byte StrokeWeight + { + get + { + return rec.StrokeWeight; + } + } + + /// + /// Indicates the stroke weight. Valid values are in the range -5 to 5. Length is 1 byte. + /// + public byte WidthType + { + get + { + return rec.WidthType; + } + } + + /// + /// Encodes the serif style. The top two bits indicate sans serif/monoline or serif/contrasting. + /// Valid values for the lower 6 bits are in the range 0 to 12. Length is 1 byte. + /// + public byte SerifStyle + { + get + { + return rec.SerifStyle; + } + } + + /// + /// Reserved. Set to 0. + /// + public byte Reserved + { + get + { + return rec.Reserved; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/PlatformId.cs b/SharpFont/Source/SharpFontShared/TrueType/PlatformId.cs new file mode 100644 index 000000000..cb0b52845 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/PlatformId.cs @@ -0,0 +1,74 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.TrueType +{ + /// + /// A list of valid values for the ‘platform_id’ identifier code in and + /// structures. + /// + [CLSCompliant(false)] + public enum PlatformId : ushort + { + /// + /// Used by Apple to indicate a Unicode character map and/or name entry. See TT_APPLE_ID_XXX for corresponding + /// ‘encoding_id’ values. Note that name entries in this format are coded as big-endian UCS-2 character codes + /// only. + /// + AppleUnicode = 0, + + /// + /// Used by Apple to indicate a MacOS-specific charmap and/or name entry. See TT_MAC_ID_XXX for corresponding + /// ‘encoding_id’ values. Note that most TrueType fonts contain an Apple roman charmap to be usable on MacOS + /// systems (even if they contain a Microsoft charmap as well). + /// + Macintosh = 1, + + /// + /// This value was used to specify ISO/IEC 10646 charmaps. It is however now deprecated. See TT_ISO_ID_XXX for + /// a list of corresponding ‘encoding_id’ values. + /// + Iso = 2, + + /// + /// Used by Microsoft to indicate Windows-specific charmaps. See TT_MS_ID_XXX for a list of corresponding + /// ‘encoding_id’ values. Note that most fonts contain a Unicode charmap using (TT_PLATFORM_MICROSOFT, + /// TT_MS_ID_UNICODE_CS). + /// + Microsoft = 3, + + /// + /// Used to indicate application-specific charmaps. + /// + Custom = 4, + + /// + /// This value isn't part of any font format specification, but is used by FreeType to report Adobe-specific + /// charmaps in an structure. See TT_ADOBE_ID_XXX. + /// + Adobe = 7 + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/Postscript.cs b/SharpFont/Source/SharpFontShared/TrueType/Postscript.cs new file mode 100644 index 000000000..da95afe4d --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/Postscript.cs @@ -0,0 +1,179 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model a TrueType PostScript table. All fields comply to the TrueType specification. This + /// structure does not reference the PostScript glyph names, which can be nevertheless accessed with the ‘ttpost’ + /// module. + /// + public class Postscript + { + #region Fields + + private IntPtr reference; + private PostscriptRec rec; + + #endregion + + #region Constructors + + internal Postscript(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the version of the table information. + /// + public int FormatType + { + get + { + return (int)rec.FormatType; + } + } + + /// + /// Gets the angle of italics, in degrees, counter-clockwise from vertical. + /// + public int ItalicAngle + { + get + { + return (int)rec.italicAngle; + } + } + + /// + /// Gets the recommended position of the underline. + /// + public short UnderlinePosition + { + get + { + return rec.underlinePosition; + } + } + + /// + /// Gets the recommended thickness of the underline. + /// + public short UnderlineThickness + { + get + { + return rec.underlineThickness; + } + } + + /// + /// + /// + [CLSCompliant(false)] + public uint IsFixedPitch + { + get + { + return (uint)rec.isFixedPitch; + } + } + + /// + /// Gets the minimum amount of memory used by the font when an OpenType font is loaded. + /// + [CLSCompliant(false)] + public uint MinimumMemoryType42 + { + get + { + return (uint)rec.minMemType42; + } + } + + /// + /// Gets the maximum amount of memory used by the font when an OpenType font is loaded. + /// + [CLSCompliant(false)] + public uint MaximumMemoryType42 + { + get + { + return (uint)rec.maxMemType42; + } + } + + /// + /// Gets the minimum amount of memory used by the font when an OpenType font is loaded as + /// a Type 1 font. + /// + [CLSCompliant(false)] + public uint MinimumMemoryType1 + { + get + { + return (uint)rec.minMemType1; + } + } + + /// + /// Gets the maximum amount of memory used by the font when an OpenType font is loaded as + /// a Type 1 font. + /// + [CLSCompliant(false)] + public uint MaximumMemoryType1 + { + get + { + return (uint)rec.maxMemType1; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/SfntName.cs b/SharpFont/Source/SharpFontShared/TrueType/SfntName.cs new file mode 100644 index 000000000..1f4b10c14 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/SfntName.cs @@ -0,0 +1,152 @@ +#region MIT License +/*Copyright (c) 2012-2013, 2016 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model an SFNT ‘name’ table entry. + /// + /// + /// Possible values for ‘platform_id’, ‘encoding_id’, ‘language_id’, and ‘name_id’ are given in the file + /// ‘ttnameid.h’. For details please refer to the TrueType or OpenType specification. + /// + /// + /// + /// + /// + public class SfntName + { + #region Fields + + private SfntNameRec rec; + + #endregion + + #region Constructors + + internal SfntName(SfntNameRec rec) + { + this.rec = rec; + } + + #endregion + + #region Properties + + /// + /// Gets the platform ID for ‘string’. + /// + [CLSCompliant(false)] + public PlatformId PlatformId + { + get + { + return rec.platform_id; + } + } + + /// + /// Gets the encoding ID for ‘string’. + /// + [CLSCompliant(false)] + public ushort EncodingId + { + get + { + return rec.encoding_id; + } + } + + /// + /// Gets the language ID for ‘string’. + /// + [CLSCompliant(false)] + public ushort LanguageId + { + get + { + return rec.language_id; + } + } + + /// + /// Gets an identifier for ‘string’. + /// + [CLSCompliant(false)] + public ushort NameId + { + get + { + return rec.name_id; + } + } + + /// + /// This property returns interpreted as UTF-16. + /// + public string String + { + get + { + //TODO it may be possible to consolidate all of these properties + //if the strings follow some sane structure. Otherwise, leave + //them or add more overloads for common encodings like UTF-8. + return Marshal.PtrToStringUni(rec.@string, (int)rec.string_len); + } + } + + /// + /// This property returns interpreted as ANSI. + /// + public string StringAnsi + { + get + { + return Marshal.PtrToStringAnsi(rec.@string, (int)rec.string_len); + } + } + + /// + /// Gets the ‘name’ string. Note that its format differs depending on the (platform,encoding) pair. It can be a + /// Pascal String, a UTF-16 one, etc. + /// + /// Generally speaking, the string is not zero-terminated. Please refer to the TrueType specification for + /// details. + /// + public IntPtr StringPtr + { + get + { + return rec.@string; + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/SfntTag.cs b/SharpFont/Source/SharpFontShared/TrueType/SfntTag.cs new file mode 100644 index 000000000..c13a69726 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/SfntTag.cs @@ -0,0 +1,70 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.TrueType +{ + /// + /// An enumeration used to specify the index of an SFNT table. Used in the API + /// function. + /// + public enum SfntTag + { + /// + /// The 'head' (header) table. + /// + Header = 0, + + /// + /// The 'maxp' (maximum profile) table. + /// + MaxProfile = 1, + + /// + /// The 'os/2' (OS/2 and Windows) table. + /// + OS2 = 2, + + /// + /// The 'hhea' (horizontal metrics header) table. + /// + HorizontalHeader = 3, + + /// + /// The 'vhea' (vertical metrics header) table. + /// + VertHeader = 4, + + /// + /// The 'post' (PostScript) table. + /// + Postscript = 5, + + /// + /// The 'pclt' (PCL5 data) table. + /// + Pclt = 6 + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueType/VertHeader.cs b/SharpFont/Source/SharpFontShared/TrueType/VertHeader.cs new file mode 100644 index 000000000..238ff98fd --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueType/VertHeader.cs @@ -0,0 +1,273 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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.Internal; + +namespace SharpFont.TrueType +{ + /// + /// A structure used to model a TrueType vertical header, the ‘vhea’ table, as well as the corresponding vertical + /// metrics table, i.e., the ‘vmtx’ table. + /// + /// + /// IMPORTANT: The and structures should be identical except for + /// the names of their fields which are different. + /// + /// This ensures that a single function in the ‘ttload’ module is able to read both the horizontal and vertical + /// headers. + /// + public class VertHeader + { + #region Fields + + private IntPtr reference; + private VertHeaderRec rec; + + #endregion + + #region Constructors + + internal VertHeader(IntPtr reference) + { + Reference = reference; + } + + #endregion + + #region Properties + + /// + /// Gets the table version. + /// + public int Version + { + get + { + return (int)rec.Version; + } + } + + /// + /// Gets the font's ascender, i.e., the distance from the baseline to the top-most of all glyph points found in + /// the font. + /// + /// This value is invalid in many fonts, as it is usually set by the font designer, and often reflects only a + /// portion of the glyphs found in the font (maybe ASCII). + /// + /// You should use the ‘sTypoAscender’ field of the OS/2 table instead if you want the correct one. + /// + public short Ascender + { + get + { + return rec.Ascender; + } + } + + /// + /// Gets the font's descender, i.e., the distance from the baseline to the bottom-most of all glyph points + /// found in the font. It is negative. + /// + /// This value is invalid in many fonts, as it is usually set by the font designer, and often reflects only a + /// portion of the glyphs found in the font (maybe ASCII). + /// + /// You should use the ‘sTypoDescender’ field of the OS/2 table instead if you want the correct one. + /// + public short Descender + { + get + { + return rec.Descender; + } + } + + /// + /// Gets the font's line gap, i.e., the distance to add to the ascender and descender to get the BTB, i.e., the + /// baseline-to-baseline distance for the font. + /// + public short LineGap + { + get + { + return rec.Line_Gap; + } + } + + /// + /// Gets the maximum of all advance heights found in the font. It can be used to compute the maximum height of + /// an arbitrary string of text. + /// + [CLSCompliant(false)] + public ushort AdvanceHeightMax + { + get + { + return rec.advance_Height_Max; + } + } + + /// + /// Gets the minimum top side bearing of all glyphs within the font. + /// + public short MinimumTopSideBearing + { + get + { + return rec.min_Top_Side_Bearing; + } + } + + /// + /// Gets the minimum bottom side bearing of all glyphs within the font. + /// + public short MinimumBottomSideBearing + { + get + { + return rec.min_Bottom_Side_Bearing; + } + } + + /// + /// Gets the maximum vertical extent (i.e., the ‘height’ of a glyph's bounding box) for all glyphs in the font. + /// + public short MaximumExtentY + { + get + { + return rec.yMax_Extent; + } + } + + /// + /// Gets the rise coefficient of the cursor's slope of the cursor (slope=rise/run). + /// + public short CaretSlopeRise + { + get + { + return rec.caret_Slope_Rise; + } + } + + /// + /// Gets the run coefficient of the cursor's slope. + /// + public short CaretSlopeRun + { + get + { + return rec.caret_Slope_Run; + } + } + + /// + /// Gets the amount of space needed to offset the caret for best appearance. Applies to slanted fonts. + /// For non-slanted fonts, set this to 0. + /// + public short CaretOffset + { + get + { + return rec.caret_Offset; + } + } + + /// + /// Gets the 8 reserved bytes. + /// + public short[] Reserved + { + get + { + return rec.Reserved; + } + } + + /// + /// Gets 0, always. + /// + public short MetricDataFormat + { + get + { + return rec.metric_Data_Format; + } + } + + /// + /// Gets the number of VMetrics entries in the ‘vmtx’ table -- this value can be smaller than the total number + /// of glyphs in the font. + /// + [CLSCompliant(false)] + public ushort VMetricsCount + { + get + { + return rec.number_Of_VMetrics; + } + } + + /// + /// Gets a pointer into the ‘vmtx’ table. + /// + public IntPtr LongMetrics + { + get + { + return rec.long_metrics; + } + } + + /// + /// Gets a pointer into the ‘vmtx’ table. + /// + public IntPtr ShortMetrics + { + get + { + return rec.short_metrics; + } + } + + internal IntPtr Reference + { + get + { + return reference; + } + + set + { + reference = value; + rec = PInvokeHelper.PtrToStructure(reference); + } + } + + #endregion + } +} diff --git a/SharpFont/Source/SharpFontShared/TrueTypeValidationFlags.cs b/SharpFont/Source/SharpFontShared/TrueTypeValidationFlags.cs new file mode 100644 index 000000000..6a74ea2b8 --- /dev/null +++ b/SharpFont/Source/SharpFontShared/TrueTypeValidationFlags.cs @@ -0,0 +1,70 @@ +#region MIT License +/*Copyright (c) 2012-2013 Robert Rouhani + +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 +{ + /// + /// A list of bit-field constants used with to indicate which TrueTypeGX/AAT + /// Type tables should be validated. + /// + [Flags] + [CLSCompliant(false)] + public enum TrueTypeValidationFlags : uint + { + /// Validate ‘feat’ table. + Feat = 0x4000 << 0, + + /// Validate ‘mort’ table. + Mort = 0x4000 << 1, + + /// Validate ‘morx’ table. + Morx = 0x4000 << 2, + + /// Validate ‘bsln’ table. + Bsln = 0x4000 << 3, + + /// Validate ‘just’ table. + Just = 0x4000 << 4, + + /// Validate ‘kern’ table. + Kern = 0x4000 << 5, + + /// Validate ‘opbd’ table. + Opbd = 0x4000 << 6, + + /// Validate ‘trak’ table. + Trak = 0x4000 << 7, + + /// Validate ‘prop’ table. + Prop = 0x4000 << 8, + + /// Validate ‘lcar’ table. + Lcar = 0x4000 << 9, + + /// Validate all TrueTypeGX tables. + All = Feat | Mort | Morx | Bsln | Just | Kern | Opbd | Trak | Prop | Lcar + } +} diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index c6c62a760..2f49a034a 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -110,6 +110,7 @@ + @@ -1042,6 +1043,9 @@ PreserveNewest Designer + + PreserveNewest + PreserveNewest @@ -1217,6 +1221,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -1226,6 +1233,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -1676,6 +1689,10 @@ {49ba1c69-6104-41ac-a5d8-b54fa9f696e8} Lidgren.Network + + {c293db32-fa42-486d-b128-5a12522fae4e} + SharpFont +