diff --git a/Launcher2/LauncherMain.cs b/Launcher2/LauncherMain.cs index d7be4e78c..491e3d6c2 100644 --- a/Launcher2/LauncherMain.cs +++ b/Launcher2/LauncherMain.cs @@ -93,12 +93,13 @@ namespace Launcher2 TextureLoader.Init(GraphicsDevice); + GUI.GraphicsDevice = GraphicsDevice; GUI.Init(Content); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); - GUI.LoadContent(GraphicsDevice, false); + GUI.LoadContent(false); backgroundTexture = TextureLoader.FromFile("Content/UI/titleBackground.png"); titleTexture = TextureLoader.FromFile("Content/UI/titleText.png"); 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 058e5ecea..6d2a0a9cd 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -111,6 +111,7 @@ + @@ -176,6 +177,7 @@ + @@ -1061,6 +1063,9 @@ PreserveNewest Designer + + PreserveNewest + PreserveNewest @@ -1236,6 +1241,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -1245,6 +1253,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -1359,15 +1373,9 @@ PreserveNewest - - PreserveNewest - PreserveNewest - - PreserveNewest - PreserveNewest @@ -1641,9 +1649,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -1680,6 +1685,10 @@ {49ba1c69-6104-41ac-a5d8-b54fa9f696e8} Lidgren.Network + + {c293db32-fa42-486d-b128-5a12522fae4e} + SharpFont + - - - - Code Pro Bold - - 16 - - 0 - - true - - - - _ - - - - - - Ұ - - - - À - ə - - - - diff --git a/Subsurface/Content/LargeFont.xnb b/Subsurface/Content/LargeFont.xnb deleted file mode 100644 index c7acfd769..000000000 Binary files a/Subsurface/Content/LargeFont.xnb and /dev/null differ diff --git a/Subsurface/Content/SmallFont.spritefont b/Subsurface/Content/SmallFont.spritefont deleted file mode 100644 index d28c47076..000000000 --- a/Subsurface/Content/SmallFont.spritefont +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - Exo Light - - 9 - - 0 - - true - - - - _ - - - - - - Ұ - - - - À - ə - - - - diff --git a/Subsurface/Content/SmallFont.xnb b/Subsurface/Content/SmallFont.xnb deleted file mode 100644 index d796cb96f..000000000 Binary files a/Subsurface/Content/SmallFont.xnb and /dev/null differ diff --git a/Subsurface/Content/SpriteFont1.spritefont b/Subsurface/Content/SpriteFont1.spritefont deleted file mode 100644 index 5e812c263..000000000 --- a/Subsurface/Content/SpriteFont1.spritefont +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - Exo Medium - - - 10 - - - 0 - - - true - - - - - - _ - - - - - - Ұ - - - - À - ə - - - - diff --git a/Subsurface/Content/SpriteFont1.xnb b/Subsurface/Content/SpriteFont1.xnb deleted file mode 100644 index 9f5a8945a..000000000 Binary files a/Subsurface/Content/SpriteFont1.xnb and /dev/null differ diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 1b904e3a7..2a98249ce 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -529,7 +529,7 @@ namespace Barotrauma GUI.DrawRectangle(spriteBatch, ConvertUnits.ToDisplayUnits(new Vector2(wallAttackPos.X, -wallAttackPos.Y)) - new Vector2(10.0f, 10.0f), new Vector2(20.0f, 20.0f), Color.Red, false); } - spriteBatch.DrawString(GUI.Font, targetValue.ToString(), pos - Vector2.UnitY*20.0f, Color.Red); + GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY*20.0f, Color.Red); } if (selectedAiTarget != null) @@ -539,10 +539,10 @@ namespace Barotrauma new Vector2(selectedAiTarget.WorldPosition.X, -selectedAiTarget.WorldPosition.Y), Color.Red); } - spriteBatch.DrawString(GUI.Font, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, Color.Red); + GUI.Font.DrawString(spriteBatch, targetValue.ToString(), pos - Vector2.UnitY * 80.0f, Color.Red); - spriteBatch.DrawString(GUI.Font, "updatetargets: "+updateTargetsTimer, pos - Vector2.UnitY * 100.0f, Color.Red); - spriteBatch.DrawString(GUI.Font, "cooldown: " + coolDownTimer, pos - Vector2.UnitY * 120.0f, Color.Red); + GUI.Font.DrawString(spriteBatch, "updatetargets: "+updateTargetsTimer, pos - Vector2.UnitY * 100.0f, Color.Red); + GUI.Font.DrawString(spriteBatch, "cooldown: " + coolDownTimer, pos - Vector2.UnitY * 120.0f, Color.Red); IndoorsSteeringManager pathSteering = steeringManager as IndoorsSteeringManager; @@ -561,7 +561,7 @@ namespace Barotrauma new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y), Color.LightGreen); - spriteBatch.DrawString(GUI.SmallFont, + GUI.SmallFont.DrawString(spriteBatch, pathSteering.CurrentPath.Nodes[i].ID.ToString(), new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10), Color.LightGreen); diff --git a/Subsurface/Source/Characters/AI/HumanAIController.cs b/Subsurface/Source/Characters/AI/HumanAIController.cs index fe25a7bb6..ed63eb9eb 100644 --- a/Subsurface/Source/Characters/AI/HumanAIController.cs +++ b/Subsurface/Source/Characters/AI/HumanAIController.cs @@ -186,7 +186,7 @@ namespace Barotrauma new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y), Color.LightGreen); - spriteBatch.DrawString(GUI.SmallFont, + GUI.SmallFont.DrawString(spriteBatch, pathSteering.CurrentPath.Nodes[i].ID.ToString(), new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10), Color.LightGreen); diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 34086d3bc..d80ce16dc 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -571,7 +571,7 @@ namespace Barotrauma } Collider.DebugDraw(spriteBatch, frozen ? Color.Red : (inWater ? Color.SkyBlue : Color.Gray)); - spriteBatch.DrawString(GUI.Font, Collider.LinearVelocity.X.ToString(), new Vector2(Collider.DrawPosition.X, -Collider.DrawPosition.Y), Color.Orange); + GUI.Font.DrawString(spriteBatch, Collider.LinearVelocity.X.ToString(), new Vector2(Collider.DrawPosition.X, -Collider.DrawPosition.Y), Color.Orange); foreach (RevoluteJoint joint in limbJoints) { diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs index d6ff2000c..f9c42db9d 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs @@ -13,13 +13,13 @@ namespace Barotrauma class BackgroundSprite { public readonly BackgroundSpritePrefab Prefab; - public Vector2 Position; + public Vector3 Position; public float Scale; public float Rotation; - public BackgroundSprite(BackgroundSpritePrefab prefab, Vector2 position, float scale, float rotation = 0.0f) + public BackgroundSprite(BackgroundSpritePrefab prefab, Vector3 position, float scale, float rotation = 0.0f) { this.Prefab = prefab; this.Position = position; @@ -99,15 +99,26 @@ namespace Barotrauma rotation += Rand.Range(prefab.RandomRotation.X, prefab.RandomRotation.Y, false); - var newSprite = new BackgroundSprite(prefab, - (Vector2)pos, Rand.Range(prefab.Scale.X, prefab.Scale.Y, false), rotation); + var newSprite = new BackgroundSprite(prefab, + new Vector3((Vector2)pos, Rand.Range(prefab.DepthRange.X, prefab.DepthRange.Y, false)), Rand.Range(prefab.Scale.X, prefab.Scale.Y, false), rotation); - int x = (int)Math.Floor(((Vector2)pos).X / GridSize); - if (x < 0 || x >= sprites.GetLength(0)) continue; - int y = (int)Math.Floor(((Vector2)pos).Y / GridSize); - if (y < 0 || y >= sprites.GetLength(1)) continue; + Vector2 spriteSize = newSprite.Prefab.Sprite.size * newSprite.Scale; - sprites[x,y].Add(newSprite); + int minX = (int)Math.Floor((newSprite.Position.X - spriteSize.X / 2 - newSprite.Position.Z) / GridSize); + int maxX = (int)Math.Floor((newSprite.Position.X + spriteSize.X / 2 + newSprite.Position.Z) / GridSize); + if (minX < 0 || maxX >= sprites.GetLength(0)) continue; + + int minY = (int)Math.Floor((newSprite.Position.Y - spriteSize.Y / 2 - newSprite.Position.Z) / GridSize); + int maxY = (int)Math.Floor((newSprite.Position.Y + spriteSize.Y / 2 + newSprite.Position.Z) / GridSize); + if (minY < 0 || maxY >= sprites.GetLength(1)) continue; + + for (int x = minX; x <= maxX; x++) + { + for (int y = minY; y <= maxY; y++) + { + sprites[x, y].Add(newSprite); + } + } } } @@ -120,6 +131,8 @@ namespace Barotrauma Rand.Range(0.0f, level.Size.X, false), Rand.Range(0.0f, level.Size.Y, false)); + if (!prefab.SpawnOnWalls) return randomPos; + var cells = level.GetCells(randomPos); if (!cells.Any()) return null; @@ -178,49 +191,80 @@ namespace Barotrauma public void DrawSprites(SpriteBatch spriteBatch, Camera cam) { Rectangle indices = Rectangle.Empty; - indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize) - 2; + indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize); if (indices.X >= sprites.GetLength(0)) return; - - indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height) / (float)GridSize) - 2; + indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height) / (float)GridSize); if (indices.Y >= sprites.GetLength(1)) return; - indices.Width = (int)Math.Ceiling(cam.WorldView.Right / (float)GridSize) + 2; + indices.Width = (int)Math.Floor(cam.WorldView.Right / (float)GridSize)+1; if (indices.Width < 0) return; - indices.Height = (int)Math.Ceiling(cam.WorldView.Y / (float)GridSize) + 2; + indices.Height = (int)Math.Floor(cam.WorldView.Y / (float)GridSize)+1; if (indices.Height < 0) return; indices.X = Math.Max(indices.X, 0); indices.Y = Math.Max(indices.Y, 0); - indices.Width = Math.Min(indices.Width, sprites.GetLength(0)); - indices.Height = Math.Min(indices.Height, sprites.GetLength(1)); + indices.Width = Math.Min(indices.Width, sprites.GetLength(0)-1); + indices.Height = Math.Min(indices.Height, sprites.GetLength(1)-1); float swingState = (float)Math.Sin(swingTimer * 0.1f); + List visibleSprites = new List(); + float z = 0.0f; - for (int x = indices.X; x < indices.Width; x++) + for (int x = indices.X; x <= indices.Width; x++) { - for (int y = indices.Y; y < indices.Height; y++) + for (int y = indices.Y; y <= indices.Height; y++) { foreach (BackgroundSprite sprite in sprites[x, y]) { - sprite.Prefab.Sprite.Draw( - spriteBatch, - new Vector2(sprite.Position.X, -sprite.Position.Y), - Color.White, - sprite.Rotation + swingState*sprite.Prefab.SwingAmount, - sprite.Scale, - SpriteEffects.None, - z); - - if (GameMain.DebugDraw) + int drawOrderIndex = 0; + for (int i = 0; i < visibleSprites.Count; i++) { - GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true); + if (visibleSprites[i] == sprite) + { + drawOrderIndex = -1; + break; + } + + if (visibleSprites[i].Position.Z > sprite.Position.Z) + { + break; + } + else + { + drawOrderIndex = i + 1; + } } - z += 0.0001f; + if (drawOrderIndex >= 0) + { + visibleSprites.Insert(drawOrderIndex, sprite); + } } } } + + foreach (BackgroundSprite sprite in visibleSprites) + { + Vector2 camDiff = new Vector2(sprite.Position.X, sprite.Position.Y) - cam.WorldViewCenter; + camDiff.Y = -camDiff.Y; + + sprite.Prefab.Sprite.Draw( + spriteBatch, + new Vector2(sprite.Position.X, -sprite.Position.Y) - camDiff * sprite.Position.Z / 10000.0f, + Color.Lerp(Color.White, Level.Loaded.BackgroundColor, sprite.Position.Z / 5000.0f), + sprite.Rotation + swingState * sprite.Prefab.SwingAmount, + sprite.Scale, + SpriteEffects.None, + z); + + if (GameMain.DebugDraw) + { + GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true); + } + + z += 0.0001f; + } } private BackgroundSpritePrefab GetRandomPrefab(string levelType) diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs index 3f98f6206..1568b2caf 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs @@ -13,10 +13,14 @@ namespace Barotrauma public readonly Vector2 Scale; + public bool SpawnOnWalls; + public readonly bool AlignWithSurface; public readonly Vector2 RandomRotation; + public readonly Vector2 DepthRange; + public readonly float SwingAmount; public readonly int Commonness; @@ -34,9 +38,13 @@ namespace Barotrauma Commonness = ToolBox.GetAttributeInt(element, "commonness", 1); + SpawnOnWalls = ToolBox.GetAttributeBool(element, "spawnonwalls", true); + Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f); Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f); + DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", Vector2.Zero); + AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false); RandomRotation = ToolBox.GetAttributeVector2(element, "randomrotation", Vector2.Zero); diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index ede70bb04..2bb2d0302 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -41,7 +41,7 @@ namespace Barotrauma } public List SpawnItems = new List(); - + private bool enabled; public bool Enabled { @@ -51,12 +51,14 @@ namespace Barotrauma } set { + if (value == enabled) return; enabled = value; foreach (Limb limb in AnimController.Limbs) { limb.body.Enabled = enabled; } + AnimController.Collider.Enabled = value; } } @@ -1617,12 +1619,12 @@ namespace Barotrauma { nameColor = Color.Red; } - spriteBatch.DrawString(GUI.Font, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f); - spriteBatch.DrawString(GUI.Font, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f); + GUI.Font.DrawString(spriteBatch, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f); + GUI.Font.DrawString(spriteBatch, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f); if (GameMain.DebugDraw) { - spriteBatch.DrawString(GUI.Font, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White); + GUI.Font.DrawString(spriteBatch, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White); } } diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index 4eada1df1..b29e93b75 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -223,7 +223,7 @@ namespace Barotrauma { new GUIImage(new Rectangle(0,0,30,30), HeadSprite, Alignment.TopLeft, frame); - SpriteFont font = frame.Rect.Width<280 ? GUI.SmallFont : GUI.Font; + ScalableFont font = frame.Rect.Width<280 ? GUI.SmallFont : GUI.Font; int x = 0, y = 0; new GUITextBlock(new Rectangle(x+60, y, 200, 20), Name, GUI.Style, frame, font); diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 96b064fac..2320a6661 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -54,14 +54,14 @@ namespace Barotrauma { int x = 20, y = 20; int width = 800, height = 500; - + frame = new GUIFrame(new Rectangle(x, y, width, height), new Color(0.4f, 0.4f, 0.4f, 0.5f)); frame.Color = Color.White * 0.4f; frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); listBox = new GUIListBox(new Rectangle(0, 0, 0, frame.Rect.Height - 40), Color.Black, GUI.Style, frame); listBox.Color = Color.Black * 0.7f; - + textBox = new GUITextBox(new Rectangle(0,0,0,20), Color.Black, Color.White, Alignment.BottomLeft, Alignment.Left, GUI.Style, frame); textBox.Color = Color.Black * 0.7f; diff --git a/Subsurface/Source/Fonts/ScalableFont.cs b/Subsurface/Source/Fonts/ScalableFont.cs new file mode 100644 index 000000000..525621b99 --- /dev/null +++ b/Subsurface/Source/Fonts/ScalableFont.cs @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SharpFont; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Barotrauma +{ + public class ScalableFont + { + private static List FontList = new List(); + private static Library Lib = null; + + private string filename; + private Face face; + private uint size; + private int baseHeight; + //private int lineHeight; + private Dictionary texCoords; + private List textures; + private GraphicsDevice graphicsDevice; + + public uint Size + { + get + { + return size; + } + set + { + size = value; + if (graphicsDevice!=null) RenderAtlas(graphicsDevice, charRanges, texDims, baseChar); + } + } + + private uint[] charRanges; + private int texDims; + private uint baseChar; + + private struct GlyphData + { + public int texIndex; + public Vector2 drawOffset; + public float advance; + public Rectangle texCoords; + } + + public ScalableFont(string filename, uint size, GraphicsDevice gd=null) + { + if (Lib == null) Lib = new Library(); + this.filename = filename; + this.face = null; + foreach (ScalableFont font in FontList) + { + if (font.filename == filename) + { + this.face = font.face; + break; + } + } + if (this.face == null) + { + this.face = new Face(Lib, filename); + } + this.size = size; + + this.textures = new List(); + + this.texCoords = new Dictionary(); + + if (gd != null) RenderAtlas(gd); + + FontList.Add(this); + } + + /// + /// Renders the font into at least one texture atlas, which is simply a collection of all glyphs in the ranges defined by charRanges. + /// Don't call this too often or with very large sizes. + /// + /// Graphics device, required to create textures. + /// Character ranges between each even element with their corresponding odd element. Default is 0x20 to 0xFFFF. + /// Texture dimensions. Default is 512x512. + /// Base character used to shift all other characters downwards when rendering. Defaults to T. + public void RenderAtlas(GraphicsDevice gd, uint[] charRanges = null, int texDims = 512, uint baseChar = 0x54) + { + if (charRanges == null) + { + charRanges = new uint[] { 0x20, 0xFFFF }; + } + this.charRanges = charRanges; + this.texDims = texDims; + this.baseChar = baseChar; + + face.SetPixelSizes(0, size); + textures.ForEach(t => t.Dispose()); + textures.Clear(); + texCoords.Clear(); + + uint[] pixelBuffer = new uint[texDims * texDims]; + for (int i = 0; i < texDims * texDims; i++) + { + pixelBuffer[i] = 0; + } + + textures.Add(new Texture2D(gd, texDims, texDims, false, SurfaceFormat.Color)); + int texIndex = 0; + + Vector2 currentCoords = Vector2.Zero; + int nextY = 0; + + face.LoadGlyph(face.GetCharIndex(baseChar), LoadFlags.Default, LoadTarget.Normal); + baseHeight = face.Glyph.Metrics.Height.ToInt32(); + //lineHeight = baseHeight; + for (int i = 0; i < charRanges.Count(); i += 2) + { + uint start = charRanges[i]; + uint end = charRanges[i + 1]; + for (uint j = start; j <= end; j++) + { + uint glyphIndex = face.GetCharIndex(j); + if (glyphIndex == 0) continue; + face.LoadGlyph(glyphIndex, LoadFlags.Default, LoadTarget.Normal); + if (face.Glyph.Metrics.Width == 0 || face.Glyph.Metrics.Height == 0) + { + if (face.Glyph.Metrics.HorizontalAdvance > 0) + { + //glyph is empty, but char still applies advance + GlyphData blankData = new GlyphData(); + blankData.advance = (float)face.Glyph.Metrics.HorizontalAdvance; + blankData.texIndex = -1; //indicates no texture because the glyph is empty + texCoords.Add(j, blankData); + } + continue; + } + //stacktrace doesn't really work that well when RenderGlyph throws an exception + face.Glyph.RenderGlyph(RenderMode.Normal); + byte[] bitmap = face.Glyph.Bitmap.BufferData; + int glyphWidth = face.Glyph.Bitmap.Width; + int glyphHeight = bitmap.Count() / glyphWidth; + + //if (glyphHeight>lineHeight) lineHeight=glyphHeight; + + if (glyphWidth > texDims - 1 || glyphHeight > texDims - 1) + { + throw new Exception(filename + ", " + size.ToString() + ", "+ (char)j + "; Glyph dimensions exceed texture atlas dimensions"); + } + + nextY = Math.Max(nextY, glyphHeight + 2); + + if (currentCoords.X + glyphWidth + 2 > texDims - 1) + { + currentCoords.X = 0; + currentCoords.Y += nextY; + nextY = 0; + } + if (currentCoords.Y + glyphHeight + 2 > texDims - 1) + { + currentCoords.X = 0; + currentCoords.Y = 0; + textures[texIndex].SetData(pixelBuffer); + textures.Add(new Texture2D(gd, texDims, texDims, false, SurfaceFormat.Color)); + texIndex++; + for (int k = 0; k < texDims * texDims; k++) + { + pixelBuffer[k] = 0; + } + } + + GlyphData newData = new GlyphData(); + newData.advance = (float)face.Glyph.Metrics.HorizontalAdvance; + newData.texIndex = texIndex; + newData.texCoords = new Rectangle((int)currentCoords.X, (int)currentCoords.Y, glyphWidth, glyphHeight); + newData.drawOffset = new Vector2(face.Glyph.BitmapLeft, baseHeight*14/10 - face.Glyph.BitmapTop); + texCoords.Add(j, newData); + + for (int y = 0; y < glyphHeight; y++) + { + for (int x = 0; x < glyphWidth; x++) + { + byte byteColor = bitmap[x + y * glyphWidth]; + pixelBuffer[((int)currentCoords.X + x) + ((int)currentCoords.Y + y) * texDims] = (uint)(byteColor << 24 | byteColor << 16 | byteColor << 8 | byteColor); + } + } + + currentCoords.X += glyphWidth + 2; + } + textures[texIndex].SetData(pixelBuffer); + } + + graphicsDevice = gd; + } + + public void DrawString(SpriteBatch sb, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects se, float layerDepth) + { + if (textures.Count == 0) return; + + int lineNum = 0; + Vector2 currentPos = position; + Vector2 advanceUnit = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); + for (int i = 0; i < text.Length; i++) + { + if (text[i]=='\n') + { + lineNum++; + currentPos = position; + currentPos.X += baseHeight * 18 / 10 * lineNum * advanceUnit.Y * scale.Y; + currentPos.Y += baseHeight * 18 / 10 * lineNum * advanceUnit.X * scale.Y; + continue; + } + uint charIndex = text[i]; + GlyphData gd; + if (texCoords.TryGetValue(charIndex, out gd)) + { + if (gd.texIndex >= 0) + { + Texture2D tex = textures[gd.texIndex]; + Vector2 drawOffset; + drawOffset.X = gd.drawOffset.X * advanceUnit.X - gd.drawOffset.Y * advanceUnit.Y; + drawOffset.Y = gd.drawOffset.X * advanceUnit.Y + gd.drawOffset.Y * advanceUnit.X; + + sb.Draw(tex, currentPos + drawOffset, null, gd.texCoords, origin, rotation, scale, color, se, layerDepth); + } + currentPos += gd.advance * advanceUnit * scale.X; + } + } + } + + public void DrawString(SpriteBatch sb, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects se, float layerDepth) + { + DrawString(sb, text, position, color, rotation, origin, new Vector2(scale), se, layerDepth); + } + + public void DrawString(SpriteBatch sb, string text, Vector2 position, Color color) + { + if (textures.Count == 0) return; + + Vector2 currentPos = position; + for (int i = 0; i < text.Length; i++) + { + if (text[i] == '\n') + { + currentPos.X = position.X; + currentPos.Y += baseHeight * 18 / 10; + continue; + } + uint charIndex = text[i]; + GlyphData gd; + if (texCoords.TryGetValue(charIndex, out gd)) + { + if (gd.texIndex >= 0) + { + Texture2D tex = textures[gd.texIndex]; + sb.Draw(tex, currentPos + gd.drawOffset, gd.texCoords, color); + } + currentPos.X += gd.advance; + } + } + } + + public Vector2 MeasureString(string text) + { + float currentLineX = 0.0f; + Vector2 retVal = Vector2.Zero; + retVal.Y = baseHeight*18/10; + for (int i = 0; i < text.Length; i++) + { + if (text[i] == '\n') + { + currentLineX = 0.0f; + retVal.Y += baseHeight*18/10; + continue; + } + uint charIndex = text[i]; + GlyphData gd; + if (texCoords.TryGetValue(charIndex, out gd)) + { + currentLineX += gd.advance; + } + retVal.X = Math.Max(retVal.X,currentLineX); + } + return retVal; + } + } +} diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index 5ecf2827c..665a6d153 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -31,11 +31,22 @@ namespace Barotrauma public static GUIStyle Style; private static Texture2D t; - public static SpriteFont Font, SmallFont, LargeFont; + public static ScalableFont Font, SmallFont, LargeFont; private static Sprite cursor; private static GraphicsDevice graphicsDevice; + public static GraphicsDevice GraphicsDevice + { + get + { + return graphicsDevice; + } + set + { + graphicsDevice = value; + } + } private static List messages = new List(); @@ -68,9 +79,9 @@ namespace Barotrauma public static void Init(ContentManager content) { - Font = ToolBox.TryLoadFont("SpriteFont1", content); - SmallFont = ToolBox.TryLoadFont("SmallFont", content); - LargeFont = ToolBox.TryLoadFont("LargeFont", content); + Font = new ScalableFont("Content/Exo2-Medium.otf", 14, graphicsDevice); + SmallFont = new ScalableFont("Content/Exo2-Light.otf", 12, graphicsDevice); + LargeFont = new ScalableFont("Content/Code Pro Bold.otf", 22, graphicsDevice); cursor = new Sprite("Content/UI/cursor.png", Vector2.Zero); @@ -87,10 +98,8 @@ namespace Barotrauma get { return settingsMenuOpen; } } - public static void LoadContent(GraphicsDevice graphics, bool loadSounds = true) + public static void LoadContent(bool loadSounds = true) { - graphicsDevice = graphics; - if (loadSounds) { sounds = new Sound[Enum.GetValues(typeof(GUISoundType)).Length]; @@ -232,7 +241,7 @@ namespace Barotrauma depth); } - public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color? backgroundColor=null, int backgroundPadding=0, SpriteFont font = null) + public static void DrawString(SpriteBatch sb, Vector2 pos, string text, Color color, Color? backgroundColor=null, int backgroundPadding=0, ScalableFont font = null) { if (font == null) font = Font; @@ -242,7 +251,7 @@ namespace Barotrauma DrawRectangle(sb, pos - Vector2.One * backgroundPadding, textSize + Vector2.One * 2.0f * backgroundPadding, (Color)backgroundColor, true); } - sb.DrawString(font, text, pos, color); + font.DrawString(sb, text, pos, color); } public static void DrawRectangle(SpriteBatch sb, Vector2 start, Vector2 size, Color clr, bool isFilled = false, float depth = 0.0f, int thickness = 1) @@ -405,7 +414,7 @@ namespace Barotrauma origin = Vector2.Zero; } - sb.DrawString(Font, text, new Vector2(rect.Center.X, rect.Center.Y) , Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f); + Font.DrawString(sb, text, new Vector2(rect.Center.X, rect.Center.Y) , Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f); return clicked; } @@ -582,12 +591,12 @@ namespace Barotrauma msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime*20.0f); - spriteBatch.DrawString(Font, msg.Text, + Font.DrawString(spriteBatch, msg.Text, new Vector2((int)msg.Pos.X - 1, (int)msg.Pos.Y - 1), Color.Black * alpha*0.5f, 0.0f, new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f); - spriteBatch.DrawString(Font, msg.Text, + Font.DrawString(spriteBatch, msg.Text, new Vector2((int)msg.Pos.X, (int)msg.Pos.Y), msg.Color * alpha, 0.0f, new Vector2((int)(0.5f * msg.Size.X), (int)(0.5f * msg.Size.Y)), 1.0f, SpriteEffects.None, 0.0f); diff --git a/Subsurface/Source/GUI/GUIButton.cs b/Subsurface/Source/GUI/GUIButton.cs index 3095700b9..7955d5def 100644 --- a/Subsurface/Source/GUI/GUIButton.cs +++ b/Subsurface/Source/GUI/GUIButton.cs @@ -84,7 +84,7 @@ namespace Barotrauma set { textBlock.TextColor = value; } } - public override SpriteFont Font + public override ScalableFont Font { get { diff --git a/Subsurface/Source/GUI/GUIComponent.cs b/Subsurface/Source/GUI/GUIComponent.cs index f48325221..94e4b3d54 100644 --- a/Subsurface/Source/GUI/GUIComponent.cs +++ b/Subsurface/Source/GUI/GUIComponent.cs @@ -28,7 +28,20 @@ namespace Barotrauma if (!Visible) return; if (ComponentsToUpdate.Contains(this)) return; ComponentsToUpdate.Add(this); - children.ForEach(c => c.AddToGUIUpdateList()); + + try + { + List fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) + { + c.AddToGUIUpdateList(); + } + } + catch (Exception e) + { + DebugConsole.NewMessage("Error in AddToGUIUPdateList! GUIComponent runtime type: "+this.GetType().ToString()+"; children count: "+children.Count.ToString(),Color.Red); + throw e; + } } public static void ClearUpdateList() @@ -86,7 +99,7 @@ namespace Barotrauma protected Color flashColor; protected float flashTimer; - public virtual SpriteFont Font + public virtual ScalableFont Font { get; set; @@ -367,13 +380,21 @@ namespace Barotrauma }*/ - //use a fixed list since children can change their order in the main children list - //TODO: maybe find a more efficient way of handling changes in list order - List fixedChildren = new List(children); - foreach (GUIComponent c in fixedChildren) + try { - if (!c.Visible) continue; - c.Update(deltaTime); + //use a fixed list since children can change their order in the main children list + //TODO: maybe find a more efficient way of handling changes in list order + List fixedChildren = new List(children); + foreach (GUIComponent c in fixedChildren) + { + if (!c.Visible) continue; + c.Update(deltaTime); + } + } + catch (Exception e) + { + DebugConsole.NewMessage("Error in Update! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red); + throw e; } } @@ -440,6 +461,23 @@ namespace Barotrauma public virtual void AddChild(GUIComponent child) { + if (child == null) return; + if (child.IsParentOf(this)) + { + DebugConsole.ThrowError("Tried to add the parent of a GUIComponent as a child.\n" + Environment.StackTrace); + return; + } + if (child == this) + { + DebugConsole.ThrowError("Tried to add a GUIComponent as its own child\n" + Environment.StackTrace); + return; + } + if (children.Contains(child)) + { + DebugConsole.ThrowError("Tried to add a the same child twice to a GUIComponent" + Environment.StackTrace); + return; + } + child.parent = this; child.UpdateDimensions(this); diff --git a/Subsurface/Source/GUI/GUIImage.cs b/Subsurface/Source/GUI/GUIImage.cs index 16dab4c83..becc471c2 100644 --- a/Subsurface/Source/GUI/GUIImage.cs +++ b/Subsurface/Source/GUI/GUIImage.cs @@ -6,9 +6,11 @@ namespace Barotrauma { public class GUIImage : GUIComponent { - Sprite sprite; + public float Rotation; - Rectangle sourceRect; + private Sprite sprite; + + private Rectangle sourceRect; bool crop; @@ -85,7 +87,7 @@ namespace Barotrauma if (sprite != null && sprite.Texture != null) { - spriteBatch.Draw(sprite.Texture, new Vector2(rect.X, rect.Y), sourceRect, currColor * (currColor.A / 255.0f), 0.0f, Vector2.Zero, + spriteBatch.Draw(sprite.Texture, new Vector2(rect.X, rect.Y), sourceRect, currColor * (currColor.A / 255.0f), Rotation, Vector2.Zero, Scale, SpriteEffects.None, 0.0f); } diff --git a/Subsurface/Source/GUI/GUIMessageBox.cs b/Subsurface/Source/GUI/GUIMessageBox.cs index 64eae3a3a..cafbb0be3 100644 --- a/Subsurface/Source/GUI/GUIMessageBox.cs +++ b/Subsurface/Source/GUI/GUIMessageBox.cs @@ -42,6 +42,17 @@ namespace Barotrauma : base(new Rectangle(0,0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black*0.5f, Alignment.TopLeft, null, parent) { + if (height == 0) + { + string wrappedText = ToolBox.WrapText(text, width, GUI.Font); + string[] lines = wrappedText.Split('\n'); + foreach (string line in lines) + { + height += (int)GUI.Font.MeasureString(line).Y; + } + height += 220; + } + var frame = new GUIFrame(new Rectangle(0,0,width,height), null, Alignment.Center, GUI.Style, this); new GUITextBlock(new Rectangle(0, 0, 0, 30), header, Color.Transparent, Color.White, textAlignment, GUI.Style, frame, true); diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 36e58fb40..cf5611473 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -103,8 +103,8 @@ namespace Barotrauma { get { return caretPos; } } - - public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, SpriteFont font) + + public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, ScalableFont font) : this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, false, font) { } @@ -142,7 +142,7 @@ namespace Barotrauma if (textColor != null) this.textColor = (Color)textColor; } - public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, SpriteFont font = null) + public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, ScalableFont font = null) :base (style) { this.Font = font == null ? GUI.Font : font; @@ -174,7 +174,7 @@ namespace Barotrauma wrappedText = text; - Vector2 size = MeasureText(text); + Vector2 size = MeasureText(text); if (Wrap && rect.Width>0) { @@ -184,7 +184,7 @@ namespace Barotrauma size = newSize; } - + if (LimitText && text.Length>1 && size.Y > rect.Height) { string[] lines = text.Split('\n'); @@ -205,7 +205,7 @@ namespace Barotrauma if (textAlignment.HasFlag(Alignment.Bottom)) origin.Y -= (rect.Height / 2.0f - padding.W) - size.Y / 2; - + origin.X = (int)origin.X; origin.Y = (int)origin.Y; @@ -263,7 +263,7 @@ namespace Barotrauma if (!string.IsNullOrEmpty(text)) { - spriteBatch.DrawString(Font, + Font.DrawString(spriteBatch, Wrap ? wrappedText : text, new Vector2(rect.X, rect.Y) + textPos + offset, textColor * (textColor.A / 255.0f), diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 30bdd6c6a..aa0fe900f 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -15,7 +15,7 @@ namespace Barotrauma bool caretVisible; float caretTimer; - + GUITextBlock textBlock; public delegate bool OnEnterHandler(GUITextBox textBox, string text); @@ -65,7 +65,7 @@ namespace Barotrauma } } - public override SpriteFont Font + public override ScalableFont Font { set { @@ -131,7 +131,7 @@ namespace Barotrauma if (textBlock.Text != "") { - //if you attempt to display a Character that is not in your font + /*//if you attempt to display a Character that is not in your font //you will get an exception, so we filter the characters //remove the filtering if you're using a default Character in your spritefont String filtered = ""; @@ -140,7 +140,7 @@ namespace Barotrauma if (Font.Characters.Contains(c)) filtered += c; } - textBlock.Text = filtered; + textBlock.Text = filtered;*/ if (!Wrap && Font.MeasureString(textBlock.Text).X > rect.Width) { @@ -182,6 +182,8 @@ namespace Barotrauma textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this); + Font = GUI.Font; + if (style != null) style.Apply(textBlock, this); textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f); diff --git a/Subsurface/Source/GUI/GUITickBox.cs b/Subsurface/Source/GUI/GUITickBox.cs index 8ed501baa..c54a620dc 100644 --- a/Subsurface/Source/GUI/GUITickBox.cs +++ b/Subsurface/Source/GUI/GUITickBox.cs @@ -65,7 +65,7 @@ namespace Barotrauma { } - public GUITickBox(Rectangle rect, string label, Alignment alignment, SpriteFont font, GUIComponent parent) + public GUITickBox(Rectangle rect, string label, Alignment alignment, ScalableFont font, GUIComponent parent) : base(null) { if (parent != null) diff --git a/Subsurface/Source/GUI/LoadingScreen.cs b/Subsurface/Source/GUI/LoadingScreen.cs index bbf194600..4d0a8863b 100644 --- a/Subsurface/Source/GUI/LoadingScreen.cs +++ b/Subsurface/Source/GUI/LoadingScreen.cs @@ -167,7 +167,7 @@ namespace Barotrauma if (GUI.LargeFont!=null) { - spriteBatch.DrawString(GUI.LargeFont, loadText, + GUI.LargeFont.DrawString(spriteBatch, loadText, new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f), Color.White); } diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 727c2c07b..7ab1ff275 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -103,6 +103,12 @@ namespace Barotrauma { get { return NetworkMember as GameClient; } } + + public double TotalElapsedTime + { + get; + private set; + } public GameMain() { @@ -202,6 +208,7 @@ namespace Barotrauma public IEnumerable Load() { + GUI.GraphicsDevice = GraphicsDevice; GUI.Init(Content); GUIComponent.Init(Window); @@ -215,7 +222,7 @@ namespace Barotrauma TitleScreen.LoadState = 1.0f; yield return CoroutineStatus.Running; - GUI.LoadContent(GraphicsDevice); + GUI.LoadContent(); TitleScreen.LoadState = 2.0f; yield return CoroutineStatus.Running; @@ -306,6 +313,8 @@ namespace Barotrauma while (Timing.Accumulator >= Timing.Step) { + TotalElapsedTime = gameTime.TotalGameTime.TotalSeconds; + fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly; TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16); fixedTime.ElapsedGameTime = addTime; diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 171e1c906..10dcb6646 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -387,7 +387,7 @@ namespace Barotrauma.Items.Components LinkedGap.ConnectedDoor = this; LinkedGap.Open = openState; - Vector2[] corners = GetConvexHullCorners(doorRect); + Vector2[] corners = GetConvexHullCorners(Rectangle.Empty); convexHull = new ConvexHull(corners, Color.Black, item); if (window != Rectangle.Empty) convexHull2 = new ConvexHull(corners, Color.Black, item); diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index 337fa286c..5e50936e5 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - spriteBatch.DrawString(GUI.Font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White); + GUI.Font.DrawString(spriteBatch, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White); } public override void AddToGUIUpdateList() diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index d14af7cf7..3cae88913 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -181,7 +181,7 @@ namespace Barotrauma.Items.Components GuiFrame.Draw(spriteBatch); - spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 40, y + 85), Color.White); + GUI.Font.DrawString(spriteBatch, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 40, y + 85), Color.White); } diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index ce1b91945..98b02238c 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -451,9 +451,9 @@ namespace Barotrauma.Items.Components //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - spriteBatch.DrawString(GUI.Font, "Output: " + (int)temperature + " kW", + GUI.Font.DrawString(spriteBatch, "Output: " + (int)temperature + " kW", new Vector2(x + 450, y + 30), Color.Red); - spriteBatch.DrawString(GUI.Font, "Grid load: " + (int)load + " kW", + GUI.Font.DrawString(spriteBatch, "Grid load: " + (int)load + " kW", new Vector2(x + 600, y + 30), Color.Yellow); float maxLoad = 0.0f; @@ -468,18 +468,18 @@ namespace Barotrauma.Items.Components DrawGraph(loadGraph, spriteBatch, new Rectangle(x + 30, y + 30, 400, 250), Math.Max(10000.0f, maxLoad), xOffset, Color.Yellow); - spriteBatch.DrawString(GUI.Font, "Shutdown Temperature: " + (int)shutDownTemp, new Vector2(x + 450, y + 80), Color.White); + GUI.Font.DrawString(spriteBatch, "Shutdown Temperature: " + (int)shutDownTemp, new Vector2(x + 450, y + 80), Color.White); - //spriteBatch.DrawString(GUI.Font, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 450, y + 180), Color.White); + //GUI.Font.DrawString(spriteBatch, "Automatic Temperature Control: " + ((autoTemp) ? "ON" : "OFF"), new Vector2(x + 450, y + 180), Color.White); y += 300; - spriteBatch.DrawString(GUI.Font, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y), Color.White); + GUI.Font.DrawString(spriteBatch, "Fission rate: " + (int)fissionRate + " %", new Vector2(x + 30, y), Color.White); DrawGraph(fissionRateGraph, spriteBatch, new Rectangle(x + 30, y + 30, 200, 100), 100.0f, xOffset, Color.Orange); - spriteBatch.DrawString(GUI.Font, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 320, y), Color.White); + GUI.Font.DrawString(spriteBatch, "Cooling rate: " + (int)coolingRate + " %", new Vector2(x + 320, y), Color.White); DrawGraph(coolingRateGraph, spriteBatch, new Rectangle(x + 320, y + 30, 200, 100), 100.0f, xOffset, Color.LightBlue); diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index 0982f8982..dacc142d7 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -228,11 +228,11 @@ namespace Barotrauma.Items.Components int y = GuiFrame.Rect.Y; //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - spriteBatch.DrawString(GUI.Font, + GUI.Font.DrawString(spriteBatch, "Charge: " + (int)charge + "/" + (int)capacity + " kWm (" + (int)((charge / capacity) * 100.0f) + " %)", new Vector2(x + 30, y + 30), Color.White); - spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", new Vector2(x + 30, y + 95), Color.White); + GUI.Font.DrawString(spriteBatch, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", new Vector2(x + 30, y + 95), Color.White); } public override void AddToGUIUpdateList() diff --git a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs index 9fa4d9b2c..2542019bc 100644 --- a/Subsurface/Source/Items/Components/Power/PowerTransfer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerTransfer.cs @@ -179,8 +179,8 @@ namespace Barotrauma.Items.Components GuiFrame.Draw(spriteBatch); - spriteBatch.DrawString(GUI.Font, "Power: " + (int)(-currPowerConsumption) + " kW", new Vector2(x + 30, y + 30), Color.White); - spriteBatch.DrawString(GUI.Font, "Load: " + (int)powerLoad + " kW", new Vector2(x + 30, y + 100), Color.White); + GUI.Font.DrawString(spriteBatch, "Power: " + (int)(-currPowerConsumption) + " kW", new Vector2(x + 30, y + 30), Color.White); + GUI.Font.DrawString(spriteBatch, "Load: " + (int)powerLoad + " kW", new Vector2(x + 30, y + 100), Color.White); } public override void AddToGUIUpdateList() diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index ff5e1d07f..f567086cc 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -372,7 +372,7 @@ namespace Barotrauma pos.Y = (int)pos.Y; GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true); - spriteBatch.DrawString(GUI.Font, toolTip, + GUI.Font.DrawString(spriteBatch, toolTip, new Vector2((int)(pos.X + rectSize.X * 0.5f), (int)(pos.Y + rectSize.Y * 0.5f)), Color.White, 0.0f, new Vector2((int)(textSize.X * 0.5f), (int)(textSize.Y * 0.5f)), diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 039a1709c..a80922f8f 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -618,7 +618,16 @@ namespace Barotrauma if (contained.body != null) { - contained.body.FarseerBody.SetTransformIgnoreContacts(ref simPos, 0.0f); + try + { + contained.body.FarseerBody.SetTransformIgnoreContacts(ref simPos, 0.0f); + } + catch (Exception e) + { +#if DEBUG + DebugConsole.ThrowError("SetTransformIgnoreContacts threw an exception in SetContainedItemPositions", e); +#endif + } } contained.Rect = diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 71663f13e..c595c48f8 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -604,9 +604,9 @@ namespace Barotrauma if (GameMain.DebugDraw) { - spriteBatch.DrawString(GUI.SmallFont, "Pressure: " + ((int)pressure - rect.Y).ToString() + + GUI.SmallFont.DrawString(spriteBatch, "Pressure: " + ((int)pressure - rect.Y).ToString() + " - Oxygen: " + ((int)OxygenPercentage), new Vector2(drawRect.X + 5, -drawRect.Y + 5), Color.White); - spriteBatch.DrawString(GUI.SmallFont, volume + " / " + FullVolume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White); + GUI.SmallFont.DrawString(spriteBatch, volume + " / " + FullVolume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White); } if ((IsSelected || isHighlighted) && editing) diff --git a/Subsurface/Source/Map/Lights/ConvexHull.cs b/Subsurface/Source/Map/Lights/ConvexHull.cs index c48285988..941cc827e 100644 --- a/Subsurface/Source/Map/Lights/ConvexHull.cs +++ b/Subsurface/Source/Map/Lights/ConvexHull.cs @@ -7,7 +7,7 @@ using System.Linq; namespace Barotrauma.Lights { - class CachedShadow : IDisposable + /*class CachedShadow : IDisposable { public VertexBuffer ShadowBuffer; @@ -40,7 +40,7 @@ namespace Barotrauma.Lights { ShadowBuffer.Dispose(); } - } + }*/ class ConvexHullList { @@ -65,17 +65,62 @@ namespace Barotrauma.Lights } } + class Segment + { + public SegmentPoint Start; + public SegmentPoint End; + + public bool IsHorizontal; + + public Segment(SegmentPoint start, SegmentPoint end) + { + Start = start; + End = end; + + start.Segment = this; + end.Segment = this; + + IsHorizontal = Math.Abs(start.Pos.X - end.Pos.X) > Math.Abs(start.Pos.Y - end.Pos.Y); + } + } + + struct SegmentPoint + { + public Vector2 Pos; + public Vector2 WorldPos; + + public Segment Segment; + + public SegmentPoint(Vector2 pos) + { + Pos = pos; + WorldPos = pos; + + Segment = null; + } + + public override string ToString() + { + return Pos.ToString(); + } + } + class ConvexHull { public static List HullLists = new List(); static BasicEffect shadowEffect; static BasicEffect penumbraEffect; - private Dictionary cachedShadows; - - private Vector2[] vertices; - private Vector2[] losVertices; - private int primitiveCount; + //private Dictionary cachedShadows; + + public VertexBuffer ShadowBuffer; + + Segment[] segments = new Segment[4]; + SegmentPoint[] vertices = new SegmentPoint[4]; + SegmentPoint[] losVertices = new SegmentPoint[4]; + + //private Vector2[] vertices; + //private Vector2[] losVertices; private bool[] backFacing; private bool[] ignoreEdge; @@ -95,10 +140,28 @@ namespace Barotrauma.Lights } + private bool enabled; public bool Enabled + { + get + { + return enabled; + } + set + { + if (enabled == value) return; + enabled = value; + LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + } + } + + /// + /// The elapsed gametime when the vertices of this hull last changed + /// + public float LastVertexChangeTime { get; - set; + private set; } public Rectangle BoundingBox @@ -124,18 +187,17 @@ namespace Barotrauma.Lights parentEntity = parent; - cachedShadows = new Dictionary(); + //cachedShadows = new Dictionary(); shadowVertices = new VertexPositionColor[6 * 2]; penumbraVertices = new VertexPositionTexture[6]; //vertices = points; - primitiveCount = points.Length; SetVertices(points); //CalculateDimensions(); - backFacing = new bool[primitiveCount]; - ignoreEdge = new bool[primitiveCount]; + backFacing = new bool[4]; + ignoreEdge = new bool[4]; Enabled = true; @@ -157,12 +219,14 @@ namespace Barotrauma.Lights private void UpdateIgnoredEdges(ConvexHull ch) { + if (ch == this) return; + //ignore edges that are inside some other convex hull for (int i = 0; i < vertices.Length; i++) { - if (vertices[i].X >= ch.boundingBox.X && vertices[i].X <= ch.boundingBox.Right && - vertices[i].Y >= ch.boundingBox.Y && vertices[i].Y <= ch.boundingBox.Bottom) + if (vertices[i].Pos.X >= ch.boundingBox.X && vertices[i].Pos.X <= ch.boundingBox.Right && + vertices[i].Pos.Y >= ch.boundingBox.Y && vertices[i].Pos.Y <= ch.boundingBox.Bottom) { - Vector2 p = vertices[(i + 1) % vertices.Length]; + Vector2 p = vertices[(i + 1) % vertices.Length].Pos; if (p.X >= ch.boundingBox.X && p.X <= ch.boundingBox.Right && p.Y >= ch.boundingBox.Y && p.Y <= ch.boundingBox.Bottom) @@ -179,11 +243,11 @@ namespace Barotrauma.Lights for (int i = 0; i < vertices.Length; i++) { - if (minX == null || vertices[i].X < minX) minX = vertices[i].X; - if (minY == null || vertices[i].Y < minY) minY = vertices[i].Y; + if (minX == null || vertices[i].Pos.X < minX) minX = vertices[i].Pos.X; + if (minY == null || vertices[i].Pos.Y < minY) minY = vertices[i].Pos.Y; - if (maxX == null || vertices[i].X > maxX) maxX = vertices[i].X; - if (maxY == null || vertices[i].Y > minY) maxY = vertices[i].Y; + if (maxX == null || vertices[i].Pos.X > maxX) maxX = vertices[i].Pos.X; + if (maxY == null || vertices[i].Pos.Y > minY) maxY = vertices[i].Pos.Y; } boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)); @@ -191,47 +255,73 @@ namespace Barotrauma.Lights public void Move(Vector2 amount) { - ClearCachedShadows(); - for (int i = 0; i < vertices.Length; i++) { - vertices[i] += amount; - losVertices[i] += amount; + vertices[i].Pos += amount; + losVertices[i].Pos += amount; + + segments[i].Start.Pos += amount; + segments[i].End.Pos += amount; } + LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + CalculateDimensions(); } public void SetVertices(Vector2[] points) { - ClearCachedShadows(); + Debug.Assert(points.Length == 4, "Only rectangular convex hulls are supported"); - vertices = points; - losVertices = points; + LastVertexChangeTime = (float)GameMain.Instance.TotalElapsedTime; + for (int i = 0; i < 4; i++) + { + vertices[i] = new SegmentPoint(points[i]); + losVertices[i] = new SegmentPoint(points[i]); + + } + for (int i = 0; i < 4; i++) + { + segments[i] = new Segment(vertices[i], vertices[(i + 1) % 4]); + } + int margin = 0; if (Math.Abs(points[0].X - points[2].X) < Math.Abs(points[0].Y - points[1].Y)) { - losVertices = new Vector2[] { - new Vector2(points[0].X+margin, points[0].Y), - new Vector2(points[1].X+margin, points[1].Y), - new Vector2(points[2].X-margin, points[2].Y), - new Vector2(points[3].X-margin, points[3].Y)}; + losVertices[0].Pos = new Vector2(points[0].X + margin, points[0].Y); + losVertices[1].Pos = new Vector2(points[1].X + margin, points[1].Y); + losVertices[2].Pos = new Vector2(points[2].X - margin, points[2].Y); + losVertices[3].Pos = new Vector2(points[3].X - margin, points[3].Y); } else { - losVertices = new Vector2[] { - new Vector2(points[0].X, points[0].Y +margin), - new Vector2(points[1].X, points[1].Y - margin), - new Vector2(points[2].X, points[2].Y - margin), - new Vector2(points[3].X, points[3].Y + margin)}; + losVertices[0].Pos = new Vector2(points[0].X, points[0].Y + margin); + losVertices[1].Pos = new Vector2(points[1].X, points[1].Y - margin); + losVertices[2].Pos = new Vector2(points[2].X, points[2].Y - margin); + losVertices[3].Pos = new Vector2(points[3].X, points[3].Y + margin); } CalculateDimensions(); + + if (parentEntity == null || ignoreEdge == null) return; + for (int i = 0; i<4; i++) + { + ignoreEdge[i] = false; + } + + var chList = HullLists.Find(x => x.Submarine == parentEntity.Submarine); + if (chList != null) + { + foreach (ConvexHull ch in chList.List) + { + UpdateIgnoredEdges(ch); + } + } } - private void RemoveCachedShadow(Lights.LightSource light) + /*private void RemoveCachedShadow(Lights.LightSource light) { CachedShadow shadow = null; cachedShadows.TryGetValue(light, out shadow); @@ -251,7 +341,7 @@ namespace Barotrauma.Lights cachedShadow.Value.Dispose(); } cachedShadows.Clear(); - } + }*/ public bool Intersects(Rectangle rect) { @@ -265,6 +355,50 @@ namespace Barotrauma.Lights } return transformedBounds.Intersects(rect); } + + /// + /// Returns the segments that are facing towards viewPosition + /// + public List GetVisibleSegments(Vector2 viewPosition) + { + List visibleFaces = new List(); + + for (int i = 0; i < 4; i++) + { + if (ignoreEdge[i]) continue; + + Vector2 pos1 = vertices[i].WorldPos; + Vector2 pos2 = vertices[(i + 1) % 4].WorldPos; + + Vector2 middle = (pos1 + pos2) / 2; + + Vector2 L = viewPosition - middle; + + Vector2 N = new Vector2( + -(pos2.Y - pos1.Y), + pos2.X - pos1.X); + + if (Vector2.Dot(N, L) > 0) + { + visibleFaces.Add(segments[i]); + } + } + + return visibleFaces; + } + + + public void RefreshWorldPositions() + { + if (parentEntity == null || parentEntity.Submarine == null) return; + for (int i = 0; i < 4; i++) + { + vertices[i].WorldPos = vertices[i].Pos + parentEntity.Submarine.DrawPosition; + segments[i].Start.WorldPos = segments[i].Start.Pos + parentEntity.Submarine.DrawPosition; + segments[i].End.WorldPos = segments[i].End.Pos + parentEntity.Submarine.DrawPosition; + + } + } private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true) { @@ -273,7 +407,7 @@ namespace Barotrauma.Lights var vertices = los ? losVertices : this.vertices; //compute facing of each edge, using N*L - for (int i = 0; i < primitiveCount; i++) + for (int i = 0; i < 4; i++) { if (ignoreEdge[i]) { @@ -281,12 +415,10 @@ namespace Barotrauma.Lights continue; } - Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y); - int secondIndex = (i + 1) % primitiveCount; - Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y); - Vector2 middle = (firstVertex + secondVertex) / 2; + Vector2 firstVertex = vertices[i].Pos; + Vector2 secondVertex = vertices[(i+1) % 4].Pos; - Vector2 L = lightSourcePos - middle; + Vector2 L = lightSourcePos - ((firstVertex + secondVertex) / 2.0f); Vector2 N = new Vector2( -(secondVertex.Y - firstVertex.Y), @@ -299,10 +431,10 @@ namespace Barotrauma.Lights //belong to the shadow int startingIndex = 0; int endingIndex = 0; - for (int i = 0; i < primitiveCount; i++) + for (int i = 0; i < 4; i++) { int currentEdge = i; - int nextEdge = (i + 1) % primitiveCount; + int nextEdge = (i + 1) % 4; if (backFacing[currentEdge] && !backFacing[nextEdge]) endingIndex = nextEdge; @@ -315,7 +447,7 @@ namespace Barotrauma.Lights if (endingIndex > startingIndex) shadowVertexCount = endingIndex - startingIndex + 1; else - shadowVertexCount = primitiveCount + 1 - startingIndex + endingIndex; + shadowVertexCount = 4 + 1 - startingIndex + endingIndex; //shadowVertices = new VertexPositionColor[shadowVertexCount * 2]; @@ -324,7 +456,7 @@ namespace Barotrauma.Lights int svCount = 0; while (svCount != shadowVertexCount * 2) { - Vector3 vertexPos = new Vector3(vertices[currentIndex], 0.0f); + Vector3 vertexPos = new Vector3(vertices[currentIndex].Pos, 0.0f); int i = los ? svCount : svCount + 1; int j = los ? svCount + 1 : svCount; @@ -338,14 +470,13 @@ namespace Barotrauma.Lights shadowVertices[j] = new VertexPositionColor(); shadowVertices[j].Color = shadowVertices[i].Color; - Vector3 L2P = vertexPos - new Vector3(lightSourcePos, 0); L2P.Normalize(); shadowVertices[j].Position = new Vector3(lightSourcePos, 0) + L2P * 9000; svCount += 2; - currentIndex = (currentIndex + 1) % primitiveCount; + currentIndex = (currentIndex + 1) % 4; } if (los) @@ -358,7 +489,7 @@ namespace Barotrauma.Lights { for (int n = 0; n < 4; n += 3) { - Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f); + Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex].Pos : vertices[endingIndex].Pos, 0.0f); penumbraVertices[n] = new VertexPositionTexture(); penumbraVertices[n].Position = penumbraStart; @@ -397,6 +528,59 @@ namespace Barotrauma.Lights } } + public static List GetHullsInRange(Vector2 position, float range, Submarine ParentSub) + { + List list = new List(); + + foreach (ConvexHullList chList in ConvexHull.HullLists) + { + Vector2 lightPos = position; + if (ParentSub == null) + { + //light and the convexhull are both outside + if (chList.Submarine == null) + { + list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + + } + //light is outside, convexhull inside a sub + else + { + if (!MathUtils.CircleIntersectsRectangle(lightPos - chList.Submarine.WorldPosition, range, chList.Submarine.Borders)) continue; + + lightPos -= (chList.Submarine.WorldPosition - chList.Submarine.HiddenSubPosition); + + list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + } + } + else + { + //light is inside, convexhull outside + if (chList.Submarine == null) continue; + + //light and convexhull are both inside the same sub + if (chList.Submarine == ParentSub) + { + list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + } + //light and convexhull are inside different subs + else + { + lightPos -= (chList.Submarine.Position - ParentSub.Position); + + Rectangle subBorders = chList.Submarine.Borders; + subBorders.Location += chList.Submarine.HiddenSubPosition.ToPoint() - new Point(0, chList.Submarine.Borders.Height); + + if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) continue; + + list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + } + } + } + + return list; + } + public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, LightSource light, Matrix transform, bool los = true) { if (!Enabled) return; @@ -415,29 +599,13 @@ namespace Barotrauma.Lights } } - - CachedShadow cachedShadow = null; - if (!cachedShadows.TryGetValue(light, out cachedShadow) || - Vector2.DistanceSquared(lightSourcePos, cachedShadow.LightPos) > 1.0f) - { - CalculateShadowVertices(lightSourcePos, los); - - if (cachedShadow != null) - { - cachedShadow.LightPos = lightSourcePos; - cachedShadow.ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length); - cachedShadow.ShadowVertexCount = shadowVertexCount; - } - else - { - cachedShadow = new CachedShadow(shadowVertices, lightSourcePos, shadowVertexCount, 0); - RemoveCachedShadow(light); - cachedShadows.Add(light, cachedShadow); - } - } - - graphicsDevice.SetVertexBuffer(cachedShadow.ShadowBuffer); - shadowVertexCount = cachedShadow.ShadowVertexCount; + + CalculateShadowVertices(lightSourcePos, los); + ShadowBuffer = new VertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionColor.VertexDeclaration, 6 * 2, BufferUsage.None); + ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length); + + graphicsDevice.SetVertexBuffer(ShadowBuffer); + shadowVertexCount = shadowVertices.Length; DrawShadows(graphicsDevice, cam, transform, los); } @@ -493,8 +661,6 @@ namespace Barotrauma.Lights public void Remove() { - ClearCachedShadows(); - var chList = HullLists.Find(x => x.Submarine == parentEntity.Submarine); if (chList != null) @@ -506,8 +672,6 @@ namespace Barotrauma.Lights } } } - - } } diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index b3d4c8382..b1ae2f9f9 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -25,6 +25,8 @@ namespace Barotrauma.Lights public Color AmbientLight; RenderTarget2D lightMap, losTexture; + + BasicEffect lightEffect; private static Texture2D alphaClearTexture; @@ -60,6 +62,15 @@ namespace Barotrauma.Lights losTexture = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight); + if (lightEffect == null) + { + lightEffect = new BasicEffect(GameMain.CurrGraphicsDevice); + lightEffect.VertexColorEnabled = false; + + lightEffect.TextureEnabled = true; + lightEffect.Texture = LightSource.LightTexture; + } + hullAmbientLights = new Dictionary(); smoothedHullAmbientLights = new Dictionary(); @@ -83,7 +94,8 @@ namespace Barotrauma.Lights { foreach (LightSource light in lights) { - light.NeedsHullUpdate = true; + light.NeedsHullCheck = true; + light.NeedsRecalculation = true; } } @@ -132,46 +144,27 @@ namespace Barotrauma.Lights //clear to some small ambient light graphics.Clear(AmbientLight); + graphics.BlendState = BlendState.Additive; + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform); + + Matrix transform = cam.ShaderTransform + * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; + + Vector3 offset = Vector3.Zero;// new Vector3(Submarine.MainSub.DrawPosition.X, Submarine.MainSub.DrawPosition.Y, 0.0f); + foreach (LightSource light in lights) { if (light.Color.A < 1 || light.Range < 1.0f || !light.CastShadows) continue; if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue; - - //clear alpha to 1 - ClearAlphaToOne(graphics, spriteBatch); - - //draw all shadows - //write only to the alpha channel, which sets alpha to 0 - graphics.RasterizerState = RasterizerState.CullNone; - graphics.BlendState = CustomBlendStates.WriteToAlpha; - light.DrawShadows(graphics, cam, shadowTransform); - - //draw the light shape - //where Alpha is 0, nothing will be written - spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, cam.Transform); - light.Draw(spriteBatch); - - spriteBatch.End(); + light.Draw(spriteBatch, lightEffect, transform); } - - ClearAlphaToOne(graphics, spriteBatch); - - spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, cam.Transform); - + lightEffect.World = Matrix.CreateTranslation(offset) * transform; + GameMain.ParticleManager.Draw(spriteBatch, false, Particles.ParticleBlendState.Additive); - - foreach (LightSource light in lights) - { - if (light.Color.A < 1 || light.Range < 1.0f || light.CastShadows) continue; - //if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue; - - light.Draw(spriteBatch); - } - if (Character.Controlled != null) { if (Character.Controlled.ClosestItem != null) @@ -185,10 +178,6 @@ namespace Barotrauma.Lights Character.Controlled.ClosestCharacter.Draw(spriteBatch); } } - spriteBatch.End(); - - - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform); foreach (Hull hull in smoothedHullAmbientLights.Keys) { @@ -207,11 +196,11 @@ namespace Barotrauma.Lights spriteBatch.End(); - //clear alpha, to avoid messing stuff up later - ClearAlphaToOne(graphics, spriteBatch); - + //ClearAlphaToOne(graphics, spriteBatch); + graphics.SetRenderTarget(null); + graphics.BlendState = BlendState.AlphaBlend; } public void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition) @@ -253,7 +242,7 @@ namespace Barotrauma.Lights Matrix shadowTransform = cam.ShaderTransform * Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f; - var convexHulls = LightSource.GetHullsInRange(viewTarget.Position, cam.WorldView.Width*0.75f, viewTarget.Submarine); + var convexHulls = ConvexHull.GetHullsInRange(viewTarget.Position, cam.WorldView.Width*0.75f, viewTarget.Submarine); if (convexHulls != null) { diff --git a/Subsurface/Source/Map/Lights/LightSource.cs b/Subsurface/Source/Map/Lights/LightSource.cs index f6d21525d..9daf95ace 100644 --- a/Subsurface/Source/Map/Lights/LightSource.cs +++ b/Subsurface/Source/Map/Lights/LightSource.cs @@ -15,27 +15,35 @@ namespace Barotrauma.Lights private List hullsInRange; private Color color; - private float range; - - public SpriteEffects SpriteEffect = SpriteEffects.None; - + + private Sprite overrideLightTexture; private Texture2D texture; + public SpriteEffects SpriteEffect = SpriteEffects.None; public Sprite LightSprite; - private Sprite overrideLightTexture; - public Submarine ParentSub; public bool CastShadows; - //what was the range of the light when HullsInRange were last updated - private float prevHullUpdateRange; + //what was the range of the light when lightvolumes were last calculated + private float prevCalculatedRange; + private Vector2 prevCalculatedPosition; - private Vector2 prevHullUpdatePosition; + //do we need to recheck which convex hulls are within range + //(e.g. position or range of the lightsource has changed) + public bool NeedsHullCheck = true; + //do we need to recalculate the vertices of the light volume + public bool NeedsRecalculation = true; - public bool NeedsHullUpdate; + //when were the vertices of the light volume last calculated + private float lastRecalculationTime; + + private DynamicVertexBuffer lightVolumeBuffer; + private DynamicIndexBuffer lightVolumeIndexBuffer; + private int vertexCount; + private int indexCount; private Vector2 position; public Vector2 Position @@ -46,17 +54,26 @@ namespace Barotrauma.Lights if (position == value) return; position = value; - if (Vector2.Distance(prevHullUpdatePosition, position) < 5.0f) return; + if (Vector2.Distance(prevCalculatedPosition, position) < 5.0f) return; - NeedsHullUpdate = true; - prevHullUpdatePosition = position; + NeedsHullCheck = true; + NeedsRecalculation = true; + prevCalculatedPosition = position; } } + private float rotation; public float Rotation { - get; - set; + get { return rotation; } + set + { + if (rotation == value) return; + rotation = value; + + NeedsHullCheck = true; + NeedsRecalculation = true; + } } public Vector2 WorldPosition @@ -90,10 +107,11 @@ namespace Barotrauma.Lights { range = MathHelper.Clamp(value, 0.0f, 2048.0f); - if (Math.Abs(prevHullUpdateRange - range) < 10.0f) return; + if (Math.Abs(prevCalculatedRange - range) < 10.0f) return; - NeedsHullUpdate = true; - prevHullUpdateRange = range; + NeedsHullCheck = true; + NeedsRecalculation = true; + prevCalculatedRange = range; } } @@ -130,13 +148,13 @@ namespace Barotrauma.Lights this.color = color; CastShadows = true; - + texture = LightTexture; - + GameMain.LightManager.AddLight(this); } - public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform) + /*public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform) { if (!CastShadows) return; if (range < 1.0f || color.A < 0.01f) return; @@ -161,147 +179,318 @@ namespace Barotrauma.Lights foreach (ConvexHull ch in outsideHulls) { ch.DrawShadows(graphics, cam, this, shadowTransform, false); - } - } + } + }*/ - private List GetHullsInRange(Submarine sub) + /// + /// Update the contents of ConvexHullList and check if we need to recalculate vertices + /// + private void RefreshConvexHullList(ConvexHullList chList, Vector2 lightPos, Submarine sub) { - //find the current list of hulls in range - var chList = hullsInRange.Find(x => x.Submarine == sub); + var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub); + if (fullChList == null) return; - //not found -> create one - if (chList == null) - { - chList = new ConvexHullList(sub); - hullsInRange.Add(chList); - } + chList.List = fullChList.List.FindAll(ch => ch.Enabled && MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox)); - Vector2 lightPos = position; - if (ParentSub == null) - { - //light and the convexhull are both outside - if (sub == null) - { - if (NeedsHullUpdate) - { - var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub); - if (fullChList != null) - chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox)); - } - } - //light is outside, convexhull inside a sub - else - { - lightPos -= sub.Position; - - Rectangle subBorders = sub.Borders; - subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height); - - //only draw if the light overlaps with the sub - if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) return null; - - var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub); - chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox)); - } - } - else - { - //light is inside, convexhull outside - if (sub == null) return null; - - //light and convexhull are both inside the same sub - if (sub == ParentSub) - { - if (NeedsHullUpdate) - { - var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub); - chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox)); - } - } - //light and convexhull are inside different subs - else - { - if (sub.DockedTo.Contains(ParentSub) && !NeedsHullUpdate) return chList.List; - - lightPos -= (sub.Position - ParentSub.Position); - - Rectangle subBorders = sub.Borders; - subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height); - - //only draw if the light overlaps with the sub - if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) return null; - - var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub); - chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox)); - } - } - - return chList.List; + NeedsHullCheck = true; } - public static List GetHullsInRange(Vector2 position, float range, Submarine ParentSub) + /// + /// Recheck which convex hulls are in range (if needed), + /// and check if we need to recalculate vertices due to changes in the convex hulls + /// + private void CheckHullsInRange() { - List list = new List(); + List subs = new List(Submarine.Loaded); + subs.Add(null); - foreach (ConvexHullList chList in ConvexHull.HullLists) + foreach (Submarine sub in subs) { + //find the list of convexhulls that belong to the sub + var chList = hullsInRange.Find(x => x.Submarine == sub); + + //not found -> create one + if (chList == null) + { + chList = new ConvexHullList(sub); + hullsInRange.Add(chList); + NeedsRecalculation = true; + } + + if (chList.List.Any(ch => ch.LastVertexChangeTime > lastRecalculationTime)) + { + NeedsRecalculation = true; + } + Vector2 lightPos = position; if (ParentSub == null) { - //light and the convexhull are both outside - if (chList.Submarine == null) + //light and the convexhulls are both outside + if (sub == null) { - list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); - + if (NeedsHullCheck) + { + RefreshConvexHullList(chList, lightPos, null); + } } - //light is outside, convexhull inside a sub + //light is outside, convexhulls inside a sub else { - if (!MathUtils.CircleIntersectsRectangle(lightPos - chList.Submarine.WorldPosition, range, chList.Submarine.Borders)) continue; + lightPos -= sub.Position; - lightPos -= (chList.Submarine.WorldPosition - chList.Submarine.HiddenSubPosition); + Rectangle subBorders = sub.Borders; + subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height); - list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + //only draw if the light overlaps with the sub + if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) + { + if (chList.List.Count > 0) NeedsRecalculation = true; + chList.List.Clear(); + continue; + } + + RefreshConvexHullList(chList, lightPos, sub); } } - else + else { //light is inside, convexhull outside - if (chList.Submarine == null) continue; - + if (sub == null) continue; + //light and convexhull are both inside the same sub - if (chList.Submarine == ParentSub) + if (sub == ParentSub) { - list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + if (NeedsHullCheck) + { + RefreshConvexHullList(chList, lightPos, sub); + } } //light and convexhull are inside different subs else { - lightPos -= (chList.Submarine.Position - ParentSub.Position); + if (sub.DockedTo.Contains(ParentSub) && !NeedsHullCheck) continue; - Rectangle subBorders = chList.Submarine.Borders; - subBorders.Location += chList.Submarine.HiddenSubPosition.ToPoint() - new Point(0, chList.Submarine.Borders.Height); + lightPos -= (sub.Position - ParentSub.Position); - if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) continue; + Rectangle subBorders = sub.Borders; + subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Point(0, sub.Borders.Height); - list.AddRange(chList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))); + //only draw if the light overlaps with the sub + if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) + { + if (chList.List.Count > 0) NeedsRecalculation = true; + chList.List.Clear(); + continue; + } + + RefreshConvexHullList(chList, lightPos, sub); } } } - - - return list; } - - public void Draw(SpriteBatch spriteBatch) + private List FindRaycastHits() { + if (!CastShadows) return null; + if (range < 1.0f || color.A < 0.01f) return null; + + Vector2 drawPos = position; + if (ParentSub != null) drawPos += ParentSub.DrawPosition; + + var hulls = new List();// ConvexHull.GetHullsInRange(position, range, ParentSub); + foreach (ConvexHullList chList in hullsInRange) + { + hulls.AddRange(chList.List); + } + + //find convexhull segments that are close enough and facing towards the light source + List visibleSegments = new List(); + List points = new List(); + foreach (ConvexHull hull in hulls) + { + hull.RefreshWorldPositions(); + + var visibleHullSegments = hull.GetVisibleSegments(drawPos); + visibleSegments.AddRange(visibleHullSegments); + + foreach (Segment s in visibleHullSegments) + { + points.Add(s.Start); + points.Add(s.End); + } + } + + //add a square-shaped boundary to make sure we've got something to construct the triangles from + //even if there aren't enough hull segments around the light source + + //(might be more effective to calculate if we actually need these extra points) + var boundaryCorners = new List { + new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y + range*2)), + new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y - range*2)), + new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y - range*2)), + new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y + range*2)) + }; + + points.AddRange(boundaryCorners); + + var compareCCW = new CompareSegmentPointCW(drawPos); + points.Sort(compareCCW); + + List output = new List(); + + //remove points that are very close to each other + for (int i = 0; i < points.Count - 1; i++) + { + if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 3 && + Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 3) + { + points.RemoveAt(i + 1); + } + } + + foreach (SegmentPoint p in points) + { + Vector2 dir = Vector2.Normalize(p.WorldPos - drawPos); + Vector2 dirNormal = new Vector2(-dir.Y, dir.X)*3; + + //do two slightly offset raycasts to hit the segment itself and whatever's behind it + Vector2 intersection1 = RayCast(drawPos, drawPos + dir * range * 2 - dirNormal, visibleSegments); + Vector2 intersection2 = RayCast(drawPos, drawPos + dir * range * 2 + dirNormal, visibleSegments); + + //hit almost the same position -> only add one vertex to output + if ((Math.Abs(intersection1.X - intersection2.X) < 5 && + Math.Abs(intersection1.Y - intersection2.Y) < 5)) + { + output.Add(intersection1); + } + else + { + output.Add(intersection1); + output.Add(intersection2); + } + } + + return output; + } + + private Vector2 RayCast(Vector2 rayStart, Vector2 rayEnd, List segments) + { + float closestDist = 0.0f; + Vector2? closestIntersection = null; + + foreach (Segment s in segments) + { + Vector2? intersection = MathUtils.GetAxisAlignedLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, s.IsHorizontal); + + if (intersection != null) + { + float dist = Vector2.Distance((Vector2)intersection, rayStart); + if (closestIntersection == null || dist < closestDist) + { + closestDist = dist; + closestIntersection = intersection; + } + } + } + + return closestIntersection == null ? rayEnd : (Vector2)closestIntersection; + } + + private void CalculateLightVertices(List rayCastHits) + { + List vertices = new List(); + + Vector2 drawPos = position; + if (ParentSub != null) drawPos += ParentSub.DrawPosition; + + float cosAngle = (float)Math.Cos(Rotation); + float sinAngle = -(float)Math.Sin(Rotation); + + Vector2 uvOffset = Vector2.Zero; + Vector2 overrideTextureDims = Vector2.One; + if (overrideLightTexture != null) + { + overrideTextureDims = new Vector2(overrideLightTexture.SourceRect.Width, overrideLightTexture.SourceRect.Height); + uvOffset = (overrideLightTexture.Origin / overrideTextureDims) - new Vector2(0.5f, 0.5f); + } + + // Add a vertex for the center of the mesh + vertices.Add(new VertexPositionTexture(new Vector3(position.X, position.Y, 0), + new Vector2(0.5f, 0.5f) + uvOffset)); + + // Add all the other encounter points as vertices + // storing their world position as UV coordinates + foreach (Vector2 vertex in rayCastHits) + { + Vector2 rawDiff = vertex - drawPos; + Vector2 diff = rawDiff; + diff /= range*2.0f; + if (overrideLightTexture != null) + { + Vector2 originDiff = diff; + + diff.X = originDiff.X * cosAngle - originDiff.Y * sinAngle; + diff.Y = originDiff.X * sinAngle + originDiff.Y * cosAngle; + diff *= (overrideTextureDims / overrideLightTexture.size) * 2.0f; + + diff += uvOffset; + } + + vertices.Add(new VertexPositionTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0), + new Vector2(0.5f, 0.5f) + diff)); + } + + // Compute the indices to form triangles + List indices = new List(); + for (int i = 0; i < rayCastHits.Count - 1; i++) + { + indices.Add(0); + indices.Add((short)((i + 2) % vertices.Count)); + indices.Add((short)((i + 1) % vertices.Count)); + } + + indices.Add(0); + indices.Add((short)(1)); + indices.Add((short)(vertices.Count - 1)); + + vertexCount = vertices.Count; + indexCount = indices.Count; + + //TODO: a better way to determine the size of the vertex buffer and handle changes in size? + //now we just create a buffer for 64 verts and make it larger if needed + if (lightVolumeBuffer == null) + { + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None); + lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.CurrGraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None); + } + else if (vertexCount > lightVolumeBuffer.VertexCount) + { + lightVolumeBuffer.Dispose(); + lightVolumeIndexBuffer.Dispose(); + + lightVolumeBuffer = new DynamicVertexBuffer(GameMain.CurrGraphicsDevice, VertexPositionTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None); + lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.CurrGraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None); + } + + lightVolumeBuffer.SetData(vertices.ToArray()); + lightVolumeIndexBuffer.SetData(indices.ToArray()); + } + + public void Draw(SpriteBatch spriteBatch, BasicEffect lightEffect, Matrix transform) + { + CheckHullsInRange(); + + Vector3 offset = ParentSub == null ? Vector3.Zero : + new Vector3(ParentSub.DrawPosition.X, ParentSub.DrawPosition.Y, 0.0f); + + lightEffect.World = Matrix.CreateTranslation(offset) * transform; + Vector2 drawPos = position; if (ParentSub != null) drawPos += ParentSub.DrawPosition; drawPos.Y = -drawPos.Y; - if (range > 1.0f) + if (range > 1.0f && false) { if (overrideLightTexture == null) { @@ -322,9 +511,38 @@ namespace Barotrauma.Lights if (LightSprite != null) { - LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin, -Rotation, 1, SpriteEffect); + //LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin, -Rotation, 1, SpriteEffect); + } - } + if (NeedsRecalculation) + { + var verts = FindRaycastHits(); + CalculateLightVertices(verts); + + lastRecalculationTime = (float)GameMain.Instance.TotalElapsedTime; + NeedsRecalculation = false; + } + + if (vertexCount == 0) return; + + lightEffect.DiffuseColor = (new Vector3(color.R, color.G, color.B) * (color.A / 255.0f)) / 255.0f;// color.ToVector3(); + if (overrideLightTexture != null) + { + lightEffect.Texture = overrideLightTexture.Texture; + } + else + { + lightEffect.Texture = LightTexture; + } + lightEffect.CurrentTechnique.Passes[0].Apply(); + + GameMain.CurrGraphicsDevice.SetVertexBuffer(lightVolumeBuffer); + GameMain.CurrGraphicsDevice.Indices = lightVolumeIndexBuffer; + + GameMain.CurrGraphicsDevice.DrawIndexedPrimitives + ( + PrimitiveType.TriangleList, 0, 0, indexCount / 3 + ); } public void FlipX() @@ -349,6 +567,18 @@ namespace Barotrauma.Lights { if (LightSprite != null) LightSprite.Remove(); + if (lightVolumeBuffer != null) + { + lightVolumeBuffer.Dispose(); + lightVolumeBuffer = null; + } + + if (lightVolumeIndexBuffer != null) + { + lightVolumeIndexBuffer.Dispose(); + lightVolumeIndexBuffer = null; + } + GameMain.LightManager.RemoveLight(this); } } diff --git a/Subsurface/Source/Map/MapEntityPrefab.cs b/Subsurface/Source/Map/MapEntityPrefab.cs index 7f6dacd67..24139401d 100644 --- a/Subsurface/Source/Map/MapEntityPrefab.cs +++ b/Subsurface/Source/Map/MapEntityPrefab.cs @@ -232,7 +232,7 @@ namespace Barotrauma public void DrawListLine(SpriteBatch spriteBatch, Vector2 pos, Color color) { - spriteBatch.DrawString(GUI.Font, name, pos, color); + GUI.Font.DrawString(spriteBatch, name, pos, color); } } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index f7c6a695b..29ab004e1 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -903,31 +903,61 @@ namespace Barotrauma public void CheckForErrors() { + List errorMsgs = new List(); + if (!Hull.hullList.Any()) { - DebugConsole.ThrowError("No hulls found in the submarine. Hulls determine the \"borders\" of an individual room and are required for water and air distribution to work correctly."); + errorMsgs.Add("No hulls found in the submarine. Hulls determine the \"borders\" of an individual room and are required for water and air distribution to work correctly."); } foreach (Item item in Item.ItemList) { - if (item.GetComponent() == null) continue; + if (item.GetComponent() == null) continue; if (!item.linkedTo.Any()) { - DebugConsole.ThrowError("The submarine contains vents which haven't been linked to an oxygen generator. Select a vent and click an oxygen generator while holding space to link them."); + errorMsgs.Add("The submarine contains vents which haven't been linked to an oxygen generator. Select a vent and click an oxygen generator while holding space to link them."); + break; } } if (WayPoint.WayPointList.Find(wp => !wp.MoveWithLevel && wp.SpawnType == SpawnType.Path) == null) { - DebugConsole.ThrowError("No waypoints found in the submarine. AI controlled crew members won't be able to navigate without waypoints."); + errorMsgs.Add("No waypoints found in the submarine. AI controlled crew members won't be able to navigate without waypoints."); } if (WayPoint.WayPointList.Find(wp => wp.SpawnType == SpawnType.Cargo) == null) { - DebugConsole.ThrowError("The submarine doesn't have spawnpoints for cargo (which are used for determining where to place bought items). " + errorMsgs.Add("The submarine doesn't have spawnpoints for cargo (which are used for determining where to place bought items). " +"To fix this, create a new spawnpoint and change its \"spawn type\" parameter to \"cargo\"."); } + + if (errorMsgs.Any()) + { + new GUIMessageBox("Warning", string.Join("\n\n", errorMsgs), 400, 0); + } + + foreach (MapEntity e in MapEntity.mapEntityList) + { + if (Vector2.Distance(e.Position, HiddenSubPosition) > 20000) + { + var msgBox = new GUIMessageBox( + "Warning", + "One or more structures have been placed very far from the submarine. Show the structures?", + new string[] {"Yes", "No"}); + + msgBox.Buttons[0].OnClicked += (btn, obj) => + { + GameMain.EditMapScreen.Cam.Position = e.WorldPosition; + return true; + }; + msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[1].OnClicked += msgBox.Close; + + break; + + } + } } public static void RefreshSavedSubs() @@ -1010,7 +1040,7 @@ namespace Barotrauma { stream = SaveUtil.DecompressFiletoStream(file); } - catch (Exception e) + catch (Exception e) { DebugConsole.ThrowError("Loading submarine \"" + file + "\" failed!", e); return null; diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 6575a5ff0..05626dfd8 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -158,7 +158,7 @@ namespace Barotrauma //GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.X, -drawRect.Y, rect.Width, rect.Height), clr, true); - //spriteBatch.DrawString(GUI.SmallFont, Position.ToString(), new Vector2(Position.X, -Position.Y), Color.White); + //GUI.SmallFont.DrawString(spriteBatch, Position.ToString(), new Vector2(Position.X, -Position.Y), Color.White); foreach (MapEntity e in linkedTo) { @@ -314,7 +314,7 @@ namespace Barotrauma - //spriteBatch.DrawString(GUI.font, "Spawnpoint: " + spawnType.ToString() + " +/-", new Vector2(x, y + 40), Color.Black); + //GUI.Font.DrawString(spriteBatch, "Spawnpoint: " + spawnType.ToString() + " +/-", new Vector2(x, y + 40), Color.Black); y = y + 30; diff --git a/Subsurface/Source/Networking/Client.cs b/Subsurface/Source/Networking/Client.cs index ff1804c5d..c1a463a66 100644 --- a/Subsurface/Source/Networking/Client.cs +++ b/Subsurface/Source/Networking/Client.cs @@ -119,7 +119,7 @@ namespace Barotrauma.Networking c != '<' && c != '/')); } - + public static string SanitizeName(string name) { name = name.Trim(); @@ -130,9 +130,8 @@ namespace Barotrauma.Networking string rName = ""; for (int i=0;i 126) + if (name[i] < 32) { - //TODO: allow safe unicode characters, this is just to prevent players from taking names that look similar but aren't the same rName += '?'; } else diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index aceb21c97..ca29e50ba 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -1091,23 +1091,23 @@ namespace Barotrauma.Networking int x = GameMain.GraphicsWidth - width, y = (int)(GameMain.GraphicsHeight * 0.3f); GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true); - spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); + GUI.Font.DrawString(spriteBatch, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); if (client.ServerConnection != null) { - spriteBatch.DrawString(GUI.Font, "Ping: " + (int)(client.ServerConnection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 10, y + 25), Color.White); + GUI.Font.DrawString(spriteBatch, "Ping: " + (int)(client.ServerConnection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x + 10, y + 25), Color.White); y += 15; - spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + client.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + client.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Received bytes: " + client.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Received packets: " + client.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); } else { - spriteBatch.DrawString(GUI.Font, "Disconnected", new Vector2(x + 10, y + 25), Color.White); + GUI.Font.DrawString(spriteBatch, "Disconnected", new Vector2(x + 10, y + 25), Color.White); } } diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 8688f9273..defe40261 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -39,6 +39,9 @@ namespace Barotrauma.Networking private ServerLog log; private GUIButton showLogButton; + private bool initiatedStartGame; + private CoroutineHandle startGameCoroutine; + private GUIScrollBar clientListScrollBar; public TraitorManager TraitorManager; @@ -398,6 +401,21 @@ namespace Barotrauma.Networking return; } } + else if (initiatedStartGame) + { + //tried to start up the game and StartGame coroutine is not running anymore + // -> something wen't wrong during startup, re-enable start button and reset AutoRestartTimer + if (startGameCoroutine != null && !CoroutineManager.IsCoroutineRunning(startGameCoroutine)) + { + if (autoRestart) AutoRestartTimer = Math.Max(AutoRestartInterval, 5.0f); + GameMain.NetLobbyScreen.StartButton.Enabled = true; + + GameMain.NetLobbyScreen.LastUpdateID++; + + startGameCoroutine = null; + initiatedStartGame = false; + } + } else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0) { AutoRestartTimer -= deltaTime; @@ -1021,13 +1039,15 @@ namespace Barotrauma.Networking } } - GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); + startGameCoroutine = GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); yield return CoroutineStatus.Success; } private IEnumerable StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode) { + initiatedStartGame = true; + Item.Spawner.Clear(); entityEventManager.Clear(); @@ -1037,38 +1057,19 @@ namespace Barotrauma.Networking roundStartSeed = DateTime.Now.Millisecond; Rand.SetSyncedSeed(roundStartSeed); - - bool couldNotStart = false; - + int teamCount = 1; int hostTeam = 1; + + GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]); - try - { - GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]); - - if (GameMain.GameSession.gameMode.Mission != null && - GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients,out hostTeam)) - { - teamCount = 2; - } - - GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed, teamCount > 1); - } - - catch (Exception e) + if (GameMain.GameSession.gameMode.Mission != null && + GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients,out hostTeam)) { - DebugConsole.ThrowError("Failed to start a new round", e); - - //try again in >5 seconds - if (autoRestart) AutoRestartTimer = Math.Max(AutoRestartInterval, 5.0f); - GameMain.NetLobbyScreen.StartButton.Enabled = true; - GameMain.NetLobbyScreen.LastUpdateID++; - - couldNotStart = true; + teamCount = 2; } - if (couldNotStart) yield return CoroutineStatus.Failure; + GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed, teamCount > 1); GameServer.Log("Starting a new round...", Color.Cyan); GameServer.Log("Submarine: " + selectedSub.Name, Color.Cyan); @@ -1183,6 +1184,7 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen.StartButton.Enabled = true; gameStarted = true; + initiatedStartGame = false; yield return CoroutineStatus.Success; } @@ -1658,14 +1660,14 @@ namespace Barotrauma.Networking GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black * 0.7f, true); - spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); + GUI.Font.DrawString(spriteBatch, "Network statistics:", new Vector2(x + 10, y + 10), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Connections: "+server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + MathUtils.GetBytesReadable(server.Statistics.ReceivedBytes), new Vector2(x + 10, y + 45), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Connections: "+server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Received bytes: " + MathUtils.GetBytesReadable(server.Statistics.ReceivedBytes), new Vector2(x + 10, y + 45), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + MathUtils.GetBytesReadable(server.Statistics.SentBytes), new Vector2(x + 10, y + 75), Color.White); - spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + server.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Sent bytes: " + MathUtils.GetBytesReadable(server.Statistics.SentBytes), new Vector2(x + 10, y + 75), Color.White); + GUI.SmallFont.DrawString(spriteBatch, "Sent packets: " + server.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); int resentMessages = 0; @@ -1685,10 +1687,10 @@ namespace Barotrauma.Networking if (y >= startY && y < startY + height - 120) { - spriteBatch.DrawString(GUI.SmallFont, c.name + " ("+c.Connection.RemoteEndPoint.Address.ToString()+")", new Vector2(x + 10, y), clientColor); - spriteBatch.DrawString(GUI.SmallFont, "Ping: " + (int)(c.Connection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x+20, y+10), clientColor); + GUI.SmallFont.DrawString(spriteBatch, c.name + " ("+c.Connection.RemoteEndPoint.Address.ToString()+")", new Vector2(x + 10, y), clientColor); + GUI.SmallFont.DrawString(spriteBatch, "Ping: " + (int)(c.Connection.AverageRoundtripTime * 1000.0f) + " ms", new Vector2(x+20, y+10), clientColor); } - if (y + 25 >= startY && y < startY + height - 130) spriteBatch.DrawString(GUI.SmallFont, "Resent messages: " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 20), clientColor); + if (y + 25 >= startY && y < startY + height - 130) GUI.SmallFont.DrawString(spriteBatch, "Resent messages: " + c.Connection.Statistics.ResentMessages, new Vector2(x + 20, y + 20), clientColor); resentMessages += (int)c.Connection.Statistics.ResentMessages; diff --git a/Subsurface/Source/Networking/NetStats.cs b/Subsurface/Source/Networking/NetStats.cs index 8ef1a651a..bdc19a3e6 100644 --- a/Subsurface/Source/Networking/NetStats.cs +++ b/Subsurface/Source/Networking/NetStats.cs @@ -71,24 +71,24 @@ namespace Barotrauma.Networking graphs[(int)NetStatType.ResentMessages].Draw(spriteBatch, rect, null, 0.0f, Color.Red); - spriteBatch.DrawString(GUI.SmallFont, + GUI.SmallFont.DrawString(spriteBatch, "Peak received: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.ReceivedBytes].LargestValue()) + "/s " + "Avg received: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.ReceivedBytes].Average()) + "/s", new Vector2(rect.X + 10, rect.Y + 10), Color.Cyan); - spriteBatch.DrawString(GUI.SmallFont, "Peak sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].LargestValue()) + "/s " + + GUI.SmallFont.DrawString(spriteBatch, "Peak sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].LargestValue()) + "/s " + "Avg sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].Average()) + "/s", new Vector2(rect.X + 10, rect.Y + 30), Color.Orange); - spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s", + GUI.SmallFont.DrawString(spriteBatch, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s", new Vector2(rect.X + 10, rect.Y + 50), Color.Red); #if DEBUG int y = 10; foreach (KeyValuePair msgBytesSent in server.messageCount.OrderBy(key => -key.Value)) { - spriteBatch.DrawString(GUI.SmallFont, msgBytesSent.Key + ": " + MathUtils.GetBytesReadable(msgBytesSent.Value), + GUI.SmallFont.DrawString(spriteBatch, msgBytesSent.Key + ": " + MathUtils.GetBytesReadable(msgBytesSent.Value), new Vector2(rect.Right - 200, rect.Y + y), Color.Red); y += 15; diff --git a/Subsurface/Source/Program.cs b/Subsurface/Source/Program.cs index 201d399c6..eaf57c560 100644 --- a/Subsurface/Source/Program.cs +++ b/Subsurface/Source/Program.cs @@ -139,11 +139,11 @@ namespace Barotrauma if (GameMain.Server != null) { - sb.AppendLine("Server (" + (GameMain.Server.GameStarted ? "Round had started)" : "Round hand't been started)")); + sb.AppendLine("Server (" + (GameMain.Server.GameStarted ? "Round had started)" : "Round hadn't been started)")); } else if (GameMain.Client != null) { - sb.AppendLine("Client (" + (GameMain.Client.GameStarted ? "Round had started)" : "Round hand't been started)")); + sb.AppendLine("Client (" + (GameMain.Client.GameStarted ? "Round had started)" : "Round hadn't been started)")); } sb.AppendLine("\n"); @@ -157,7 +157,7 @@ namespace Barotrauma sb.AppendLine("\n"); sb.AppendLine("Last debug messages:"); - for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 10; i-- ) + for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 15; i-- ) { sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text); } diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index f3d687559..bf6857632 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -309,9 +309,8 @@ namespace Barotrauma } else { - cam.Position = Submarine.HiddenSubStartPosition; - Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, "Unnamed.sub"), "", false); + cam.Position = Submarine.MainSub.Position; } SoundPlayer.OverrideMusicType = "none"; @@ -419,6 +418,9 @@ namespace Barotrauma private void CreateSaveScreen() { + if (characterMode) ToggleCharacterMode(); + if (wiringMode) ToggleWiringMode(); + int width = 400, height = 400; int y = 0; @@ -503,6 +505,9 @@ namespace Barotrauma private bool CreateLoadScreen(GUIButton button, object obj) { + if (characterMode) ToggleCharacterMode(); + if (wiringMode) ToggleWiringMode(); + Submarine.RefreshSavedSubs(); int width = 300, height = 400; @@ -588,8 +593,7 @@ namespace Barotrauma Submarine.MainSub = selectedSub; selectedSub.Load(true); - //nameBox.Text = selectedSub.Name; - //descriptionBox.Text = ToolBox.LimitString(selectedSub.Description,15); + cam.Position = Submarine.MainSub.Position + Submarine.MainSub.HiddenSubPosition; loadFrame = null; @@ -598,10 +602,14 @@ namespace Barotrauma private bool SelectTab(GUIButton button, object obj) { + if (characterMode) ToggleCharacterMode(); + if (wiringMode) ToggleWiringMode(); + selectedTab = (int)obj; var searchBox = GUItabs[selectedTab].GetChild(); ClearFilter(searchBox, null); + searchBox.Text = ""; searchBox.AddToGUIUpdateList(); searchBox.Select(); @@ -901,22 +909,28 @@ namespace Barotrauma wiringToolPanel.AddToGUIUpdateList(); } - if (loadFrame != null) - { - loadFrame.AddToGUIUpdateList(); - } - else if (saveFrame != null) - { - saveFrame.AddToGUIUpdateList(); - } - else if (selectedTab > -1) - { - GUItabs[selectedTab].AddToGUIUpdateList(); - } - if ((characterMode || wiringMode) && dummyCharacter != null) { CharacterHUD.AddToGUIUpdateList(dummyCharacter); + if (dummyCharacter.SelectedConstruction != null) + { + dummyCharacter.SelectedConstruction.AddToGUIUpdateList(); + } + } + else + { + if (loadFrame != null) + { + loadFrame.AddToGUIUpdateList(); + } + else if (saveFrame != null) + { + saveFrame.AddToGUIUpdateList(); + } + else if (selectedTab > -1) + { + GUItabs[selectedTab].AddToGUIUpdateList(); + } } GUI.AddToGUIUpdateList(); @@ -1064,7 +1078,7 @@ namespace Barotrauma graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f)); if (GameMain.DebugDraw) { - GUI.DrawLine(spriteBatch, new Vector2(0.0f, -cam.WorldView.Y), new Vector2(0.0f, -(cam.WorldView.Y - cam.WorldView.Height)), Color.White*0.5f, 1.0f, (int)(2.0f/cam.Zoom)); + GUI.DrawLine(spriteBatch, new Vector2(Submarine.MainSub.HiddenSubPosition.X, -cam.WorldView.Y), new Vector2(Submarine.MainSub.HiddenSubPosition.X, -(cam.WorldView.Y - cam.WorldView.Height)), Color.White * 0.5f, 1.0f, (int)(2.0f / cam.Zoom)); GUI.DrawLine(spriteBatch, new Vector2(cam.WorldView.X, -Submarine.MainSub.HiddenSubPosition.Y), new Vector2(cam.WorldView.Right, -Submarine.MainSub.HiddenSubPosition.Y), Color.White * 0.5f, 1.0f, (int)(2.0f / cam.Zoom)); } @@ -1084,6 +1098,11 @@ namespace Barotrauma spriteBatch.Begin(); + if (Submarine.MainSub != null) + { + DrawSubmarineIndicator(spriteBatch, Submarine.MainSub, Color.LightBlue * 0.5f); + } + leftPanel.Draw(spriteBatch); topPanel.Draw(spriteBatch); diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 64486c8a8..b351f7461 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -443,26 +443,5 @@ namespace Barotrauma } } - - private void DrawSubmarineIndicator(SpriteBatch spriteBatch, Submarine submarine, Color color) - { - Vector2 subDiff = submarine.WorldPosition - cam.WorldViewCenter; - - if (Math.Abs(subDiff.X) > cam.WorldView.Width || Math.Abs(subDiff.Y) > cam.WorldView.Height) - { - Vector2 normalizedSubDiff = Vector2.Normalize(subDiff); - - Vector2 iconPos = - cam.WorldToScreen(cam.WorldViewCenter) + - new Vector2(normalizedSubDiff.X * GameMain.GraphicsWidth * 0.4f, -normalizedSubDiff.Y * GameMain.GraphicsHeight * 0.4f); - - GUI.SubmarineIcon.Draw(spriteBatch, iconPos, color); - - Vector2 arrowOffset = normalizedSubDiff * GUI.SubmarineIcon.size.X * 0.7f; - arrowOffset.Y = -arrowOffset.Y; - GUI.Arrow.Draw(spriteBatch, iconPos + arrowOffset, color, MathUtils.VectorToAngle(arrowOffset) + MathHelper.PiOver2); - } - } - } } diff --git a/Subsurface/Source/Screens/LobbyScreen.cs b/Subsurface/Source/Screens/LobbyScreen.cs index 50fb6747f..76ac9323f 100644 --- a/Subsurface/Source/Screens/LobbyScreen.cs +++ b/Subsurface/Source/Screens/LobbyScreen.cs @@ -267,7 +267,7 @@ namespace Barotrauma frame.ToolTip = ep.Description; - SpriteFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font; + ScalableFont font = listBox.Rect.Width < 280 ? GUI.SmallFont : GUI.Font; GUITextBlock textBlock = new GUITextBlock( new Rectangle(50, 0, 0, 25), diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index 740eb7935..340edb26b 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -515,7 +515,7 @@ namespace Barotrauma GUI.Draw((float)deltaTime, spriteBatch, null); - spriteBatch.DrawString(GUI.Font, "Barotrauma v"+GameMain.Version, new Vector2(10, GameMain.GraphicsHeight-20), Color.White); + GUI.Font.DrawString(spriteBatch, "Barotrauma v"+GameMain.Version, new Vector2(10, GameMain.GraphicsHeight-20), Color.White); spriteBatch.End(); } diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index d076b539d..2a0f5877d 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -540,11 +540,18 @@ namespace Barotrauma infoButton.UserData = -1; infoButton.OnClicked += ViewJobInfo; - GUIButton upButton = new GUIButton(new Rectangle(30, 2, 15, 15), "^", GUI.Style, jobText); + GUIButton upButton = new GUIButton(new Rectangle(30, 2, 15, 15), "", GUI.Style, jobText); + //TODO: make GUIImages align correctly when scaled/rotated + //so there's no need to do this ↓ + new GUIImage(new Rectangle(3,2,0,0), GUI.Arrow, Alignment.Center, upButton).Scale = 0.6f; upButton.UserData = -1; upButton.OnClicked += ChangeJobPreference; - GUIButton downButton = new GUIButton(new Rectangle(50, 2, 15, 15), "Ë…", GUI.Style, jobText); + GUIButton downButton = new GUIButton(new Rectangle(50, 2, 15, 15), "", GUI.Style, jobText); + var downArrow = new GUIImage(new Rectangle(13,14,0,0), GUI.Arrow, Alignment.Center, downButton); + downArrow.Rotation = MathHelper.Pi; + downArrow.Scale = 0.6f; + downButton.UserData = 1; downButton.OnClicked += ChangeJobPreference; } diff --git a/Subsurface/Source/Screens/Screen.cs b/Subsurface/Source/Screens/Screen.cs index a57a06007..56dfa3421 100644 --- a/Subsurface/Source/Screens/Screen.cs +++ b/Subsurface/Source/Screens/Screen.cs @@ -75,5 +75,25 @@ namespace Barotrauma yield return CoroutineStatus.Success; } + protected void DrawSubmarineIndicator(SpriteBatch spriteBatch, Submarine submarine, Color color) + { + Vector2 subDiff = submarine.WorldPosition - Cam.WorldViewCenter; + + if (Math.Abs(subDiff.X) > Cam.WorldView.Width || Math.Abs(subDiff.Y) > Cam.WorldView.Height) + { + Vector2 normalizedSubDiff = Vector2.Normalize(subDiff); + + Vector2 iconPos = + Cam.WorldToScreen(Cam.WorldViewCenter) + + new Vector2(normalizedSubDiff.X * GameMain.GraphicsWidth * 0.4f, -normalizedSubDiff.Y * GameMain.GraphicsHeight * 0.4f); + + GUI.SubmarineIcon.Draw(spriteBatch, iconPos, color); + + Vector2 arrowOffset = normalizedSubDiff * GUI.SubmarineIcon.size.X * 0.7f; + arrowOffset.Y = -arrowOffset.Y; + GUI.Arrow.Draw(spriteBatch, iconPos + arrowOffset, color, MathUtils.VectorToAngle(arrowOffset) + MathHelper.PiOver2); + } + } + } } diff --git a/Subsurface/Source/Screens/ServerListScreen.cs b/Subsurface/Source/Screens/ServerListScreen.cs index b9891b09e..654ad1586 100644 --- a/Subsurface/Source/Screens/ServerListScreen.cs +++ b/Subsurface/Source/Screens/ServerListScreen.cs @@ -60,7 +60,7 @@ namespace Barotrauma if (n > 0) columnX[n] += columnX[n - 1]; } - SpriteFont font = GUI.SmallFont; // serverList.Rect.Width < 400 ? GUI.SmallFont : GUI.Font; + ScalableFont font = GUI.SmallFont; // serverList.Rect.Width < 400 ? GUI.SmallFont : GUI.Font; new GUITextBlock(new Rectangle(middleX, 30, 0, 30), "Password", GUI.Style, menu).Font = font; diff --git a/Subsurface/Source/Sounds/OggStream.cs b/Subsurface/Source/Sounds/OggStream.cs index cc02e522f..c2a3cb18e 100644 --- a/Subsurface/Source/Sounds/OggStream.cs +++ b/Subsurface/Source/Sounds/OggStream.cs @@ -381,6 +381,10 @@ namespace Barotrauma.Sounds Instance = this; underlyingThread = new Thread(EnsureBuffersFilled) { Priority = ThreadPriority.Lowest }; + + //background threads are automatically stopped when all foreground threads have been stopped + // -> the streaming thread won't stay running in the background if the main thread crashes + underlyingThread.IsBackground = true; underlyingThread.Start(); } diff --git a/Subsurface/Source/Sounds/Sound.cs b/Subsurface/Source/Sounds/Sound.cs index 867ae39f4..9ce6c8079 100644 --- a/Subsurface/Source/Sounds/Sound.cs +++ b/Subsurface/Source/Sounds/Sound.cs @@ -40,7 +40,7 @@ namespace Barotrauma if (loadedSound.filePath == file) oggSound = loadedSound.oggSound; } - if (oggSound == null) + if (oggSound == null && !SoundManager.Disabled) { try { @@ -198,8 +198,8 @@ namespace Barotrauma return sourceIndex; } - return SoundManager.Loop(this, sourceIndex, relativePos/100.0f, volume); - + alSourceId = SoundManager.Loop(this, sourceIndex, relativePos / 100.0f, volume); + return alSourceId; } public bool IsPlaying @@ -210,26 +210,6 @@ namespace Barotrauma } } - //public int Loop(float volume = 1.0f) - //{ - // return SoundManager.Loop(this, volume); - //} - - //public void Pause() - //{ - // SoundManager.Pause(this); - //} - - //public void Resume() - //{ - // SoundManager.Resume(this); - //} - - //public void Stop() - //{ - // SoundManager.Stop(this); - //} - public static void OnGameEnd() { List removableSounds = loadedSounds.FindAll(s => s.destroyOnGameEnd); @@ -268,17 +248,19 @@ namespace Barotrauma public static void StartStream(string file, float volume = 1.0f) { + if (SoundManager.Disabled) return; stream = SoundManager.StartStream(file, volume); } public static void StreamVolume(float volume = 1.0f) { + if (SoundManager.Disabled) return; stream.Volume = volume; } public static void StopStream() { - if (stream!=null) SoundManager.StopStream(); + if (stream != null) SoundManager.StopStream(); } public static void Dispose() diff --git a/Subsurface/Source/Sounds/SoundManager.cs b/Subsurface/Source/Sounds/SoundManager.cs index 986a1ee64..e1184e983 100644 --- a/Subsurface/Source/Sounds/SoundManager.cs +++ b/Subsurface/Source/Sounds/SoundManager.cs @@ -9,6 +9,12 @@ namespace Barotrauma.Sounds { static class SoundManager { + public static bool Disabled + { + get; + private set; + } + public const int DefaultSourceCount = 16; private static readonly List alSources = new List(); @@ -26,9 +32,17 @@ namespace Barotrauma.Sounds public static void Init() { + var availableDevices = AudioContext.AvailableDevices; + if (availableDevices.Count == 0) + { + DebugConsole.ThrowError("No audio devices found. Disabling audio playback."); + Disabled = true; + return; + } + try { - AC = new AudioContext(); + AC = new AudioContext(); ALHelper.Check(); } catch (DllNotFoundException e) @@ -55,11 +69,14 @@ namespace Barotrauma.Sounds public static int Play(Sound sound, float volume = 1.0f) { + if (Disabled) return -1; return Play(sound, Vector2.Zero, volume, 0.0f); } public static int Play(Sound sound, Vector2 position, float volume = 1.0f, float lowPassGain = 0.0f, bool loop=false) { + if (Disabled) return -1; + for (int i = 1; i < DefaultSourceCount; i++) { //find a source that's free to use (not playing or paused) @@ -85,11 +102,15 @@ namespace Barotrauma.Sounds public static int Loop(Sound sound, int sourceIndex, float volume = 1.0f) { + if (Disabled) return -1; + return Loop(sound,sourceIndex, Vector2.Zero, volume); } public static int Loop(Sound sound, int sourceIndex, Vector2 position, float volume = 1.0f) { + if (Disabled) return -1; + if (!MathUtils.IsValid(volume)) { volume = 0.0f; @@ -111,6 +132,8 @@ namespace Barotrauma.Sounds public static void Pause(int sourceIndex) { + if (Disabled) return; + if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing) return; @@ -120,6 +143,8 @@ namespace Barotrauma.Sounds public static void Resume(int sourceIndex) { + if (Disabled) return; + if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Paused) return; @@ -129,6 +154,8 @@ namespace Barotrauma.Sounds public static void Stop(int sourceIndex) { + if (Disabled) return; + if (sourceIndex < 1) return; var state = AL.GetSourceState(alSources[sourceIndex]); @@ -143,6 +170,8 @@ namespace Barotrauma.Sounds public static Sound GetPlayingSound(int sourceIndex) { + if (Disabled) return null; + if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return null; if (AL.GetSourceState(alSources[sourceIndex]) != ALSourceState.Playing) return null; @@ -152,6 +181,8 @@ namespace Barotrauma.Sounds public static bool IsPlaying(int sourceIndex) { + if (Disabled) return false; + if (sourceIndex < 1 || sourceIndex>alSources.Count-1) return false; return AL.GetSourceState(alSources[sourceIndex]) == ALSourceState.Playing; @@ -159,6 +190,8 @@ namespace Barotrauma.Sounds public static bool IsPaused(int sourceIndex) { + if (Disabled) return false; + if (sourceIndex < 1 || sourceIndex > alSources.Count - 1) return false; return AL.GetSourceState(alSources[sourceIndex]) == ALSourceState.Paused; @@ -166,6 +199,7 @@ namespace Barotrauma.Sounds public static bool IsLooping(int sourceIndex) { + if (Disabled) return false; if (sourceIndex < 1 || sourceIndex > alSources.Count - 1) return false; bool isLooping; @@ -177,6 +211,8 @@ namespace Barotrauma.Sounds public static void Volume(int sourceIndex, float volume) { + if (Disabled) return; + AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume * MasterVolume); ALHelper.Check(); } @@ -187,6 +223,7 @@ namespace Barotrauma.Sounds get { return lowPassHfGain; } set { + if (Disabled) return; if (ALHelper.Efx.IsInitialized) { lowPassHfGain = value; @@ -200,7 +237,6 @@ namespace Barotrauma.Sounds ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId); ALHelper.Check(); } - } } } @@ -208,7 +244,7 @@ namespace Barotrauma.Sounds public static void UpdateSoundPosition(int sourceIndex, Vector2 position, float baseVolume = 1.0f) { - if (sourceIndex < 1) return; + if (sourceIndex < 1 || Disabled) return; if (!MathUtils.IsValid(position)) { @@ -229,6 +265,8 @@ namespace Barotrauma.Sounds public static OggStream StartStream(string file, float volume = 1.0f) { + if (Disabled) return null; + if (oggStreamer == null) oggStreamer = new OggStreamer(); @@ -244,7 +282,7 @@ namespace Barotrauma.Sounds public static void StopStream() { - if (oggStream!=null) oggStream.Stop(); + if (oggStream != null) oggStream.Stop(); } public static void ClearAlSource(int bufferId) @@ -260,6 +298,8 @@ namespace Barotrauma.Sounds public static void Dispose() { + if (Disabled) return; + if (ALHelper.Efx.IsInitialized) ALHelper.Efx.DeleteFilter(lowpassFilterId); diff --git a/Subsurface/Source/Utils/Homoglyphs.cs b/Subsurface/Source/Utils/Homoglyphs.cs new file mode 100644 index 000000000..a6ce3b32c --- /dev/null +++ b/Subsurface/Source/Utils/Homoglyphs.cs @@ -0,0 +1,1839 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Barotrauma +{ + class Homoglyphs + { + ///List of homoglyphs taken from https://github.com/codebox/homoglyph/ + private static List homoglyphs = new List(){ + new uint[]{0x20,0xa0,0x1680,0x2000,0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200a,0x2028,0x2029,0x202f,0x205f}, + new uint[]{0x21,0x1c3,0x2d51,0xff01}, + new uint[]{0x24,0xff04}, + new uint[]{0x25,0xff05}, + new uint[]{0x26,0xa778,0xff06}, + new uint[]{0x27,0x60,0xb4,0x2b9,0x2bb,0x2bc,0x2bd,0x2be,0x2c8,0x2ca,0x2cb,0x2f4,0x374,0x384,0x55a,0x55d,0x5d9,0x5f3,0x7f4,0x7f5,0x144a,0x16cc,0x1fbd,0x1fbf,0x1fef,0x1ffd,0x1ffe,0x2018,0x2019,0x201b,0x2032,0x2035,0xa78c,0xff07,0xff40}, + new uint[]{0x28,0x2768,0x2772,0x3014,0xfd3e,0xff08,0xff3b}, + new uint[]{0x29,0x2769,0x2773,0x3015,0xfd3f,0xff09,0xff3d}, + new uint[]{0x2a,0x66d,0x204e,0x2217,0xff0a,0x1031f}, + new uint[]{0x2b,0x16ed,0x2795,0xff0b,0x1029b}, + new uint[]{0x2c,0xb8,0x60d,0x66b,0x201a,0xa4f9,0xff0c}, + new uint[]{0x2d,0x2d7,0x6d4,0x2010,0x2011,0x2012,0x2013,0x2043,0x2212,0x2796,0x2cba,0xfe58}, + new uint[]{0x2e,0x660,0x6f0,0x701,0x702,0x2024,0xa4f8,0xa60e,0xff0e,0x10a50,0x1d16d}, + new uint[]{0x2f,0x1735,0x2041,0x2044,0x2215,0x2571,0x27cb,0x29f8,0x2cc6,0x2f03,0x3033,0x31d3,0x4e3f,0xff0f}, + new uint[]{0x30,0x4f,0x39f,0x41e,0x555,0x7c0,0x9e6,0xb20,0xb66,0xd20,0x2c9e,0x2d54,0x3007,0xa4f3,0xff10,0xff2f,0x10292,0x102ab,0x10404,0x10516,0x114d0,0x118b5,0x118e0,0x1d40e,0x1d442,0x1d476,0x1d4aa,0x1d4de,0x1d512,0x1d546,0x1d57a,0x1d5ae,0x1d5e2,0x1d616,0x1d64a,0x1d67e,0x1d6b6,0x1d6f0,0x1d72a,0x1d764,0x1d79e,0x1d7ce,0x1d7d8,0x1d7e2,0x1d7ec,0x1d7f6}, + new uint[]{0x31,0x49,0x6c,0x7c,0x196,0x1c0,0x399,0x406,0x4c0,0x5c0,0x5d5,0x5df,0x627,0x661,0x6f1,0x7ca,0x16c1,0x2110,0x2111,0x2113,0x2160,0x217c,0x2223,0x2c92,0x2d4f,0xa4f2,0xfe8d,0xfe8e,0xff11,0xff29,0xff4c,0xffe8,0x1028a,0x10309,0x10320,0x1d408,0x1d425,0x1d43c,0x1d459,0x1d470,0x1d48d,0x1d4c1,0x1d4d8,0x1d4f5,0x1d529,0x1d540,0x1d55d,0x1d574,0x1d591,0x1d5a8,0x1d5c5,0x1d5dc,0x1d5f9,0x1d610,0x1d62d,0x1d644,0x1d661,0x1d678,0x1d695,0x1d6b0,0x1d6ea,0x1d724,0x1d75e,0x1d798,0x1d7cf,0x1d7d9,0x1d7e3,0x1d7ed,0x1d7f7,0x1e8c7,0x1ee00,0x1ee80}, + new uint[]{0x32,0x1a7,0x3e8,0x14bf,0xa644,0xa75a,0xff12,0x1d7d0,0x1d7da,0x1d7e4,0x1d7ee,0x1d7f8}, + new uint[]{0x33,0x1b7,0x21c,0x417,0x4e0,0x2ccc,0xa76a,0xa7ab,0xff13,0x118ca,0x1d7d1,0x1d7db,0x1d7e5,0x1d7ef,0x1d7f9}, + new uint[]{0x34,0x13ce,0xff14,0x118af,0x1d7d2,0x1d7dc,0x1d7e6,0x1d7f0,0x1d7fa}, + new uint[]{0x35,0x1bc,0xff15,0x118bb,0x1d7d3,0x1d7dd,0x1d7e7,0x1d7f1,0x1d7fb}, + new uint[]{0x36,0x431,0x13ee,0x2cd2,0xff16,0x118d5,0x1d7d4,0x1d7de,0x1d7e8,0x1d7f2,0x1d7fc}, + new uint[]{0x37,0xff17,0x118c6,0x1d7d5,0x1d7df,0x1d7e9,0x1d7f3,0x1d7fd}, + new uint[]{0x38,0x222,0x223,0x9ea,0xa6a,0xb03,0xff18,0x1031a,0x1d7d6,0x1d7e0,0x1d7ea,0x1d7f4,0x1d7fe,0x1e8cb}, + new uint[]{0x39,0x9ed,0xa67,0xb68,0x2cca,0xa76e,0xff19,0x118ac,0x118cc,0x118d6,0x1d7d7,0x1d7e1,0x1d7eb,0x1d7f5,0x1d7ff}, + new uint[]{0x3a,0x2d0,0x2f8,0x589,0x5c3,0x703,0x704,0x903,0xa83,0x16ec,0x1803,0x1809,0x205a,0x2236,0xa4fd,0xa789,0xfe30,0xff1a}, + new uint[]{0x3b,0x37e,0xff1b}, + new uint[]{0x3c,0x2c2,0x1438,0x16b2,0x2039,0x276e,0xff1c}, + new uint[]{0x3d,0x1400,0x2e40,0x30a0,0xa4ff,0xff1d}, + new uint[]{0x3e,0x2c3,0x1433,0x203a,0x276f,0xff1e}, + new uint[]{0x3f,0x241,0x294,0x97d,0x13ae,0xff1f}, + new uint[]{0x40,0xff20}, + new uint[]{0x41,0x391,0x410,0x13aa,0x15c5,0x1d00,0xa4ee,0xff21,0x102a0,0x1d400,0x1d434,0x1d468,0x1d49c,0x1d4d0,0x1d504,0x1d538,0x1d56c,0x1d5a0,0x1d5d4,0x1d608,0x1d63c,0x1d670,0x1d6a8,0x1d6e2,0x1d71c,0x1d756,0x1d790}, + new uint[]{0x42,0x299,0x392,0x412,0x432,0x13f4,0x15f7,0x16d2,0x212c,0xa4d0,0xa7b4,0xff22,0x10282,0x102a1,0x10301,0x1d401,0x1d435,0x1d469,0x1d4d1,0x1d505,0x1d539,0x1d56d,0x1d5a1,0x1d5d5,0x1d609,0x1d63d,0x1d671,0x1d6a9,0x1d6e3,0x1d71d,0x1d757,0x1d791}, + new uint[]{0x43,0x3f9,0x421,0x13df,0x2102,0x212d,0x216d,0x2ca4,0xa4da,0xff23,0x102a2,0x10302,0x10415,0x1051c,0x118e9,0x118f2,0x1d402,0x1d436,0x1d46a,0x1d49e,0x1d4d2,0x1d56e,0x1d5a2,0x1d5d6,0x1d60a,0x1d63e,0x1d672,0x1f74c}, + new uint[]{0x44,0x13a0,0x15de,0x15ea,0x2145,0x216e,0xa4d3,0xff24,0x1d403,0x1d437,0x1d46b,0x1d49f,0x1d4d3,0x1d507,0x1d53b,0x1d56f,0x1d5a3,0x1d5d7,0x1d60b,0x1d63f,0x1d673}, + new uint[]{0x45,0x395,0x415,0x13ac,0x2130,0x22ff,0x2d39,0xa4f0,0xff25,0x10286,0x118a6,0x118ae,0x1d404,0x1d438,0x1d46c,0x1d4d4,0x1d508,0x1d53c,0x1d570,0x1d5a4,0x1d5d8,0x1d60c,0x1d640,0x1d674,0x1d6ac,0x1d6e6,0x1d720,0x1d75a,0x1d794}, + new uint[]{0x46,0x3dc,0x15b4,0x2131,0xa4dd,0xa798,0xff26,0x10287,0x102a5,0x10525,0x118a2,0x118c2,0x1d405,0x1d439,0x1d46d,0x1d4d5,0x1d509,0x1d53d,0x1d571,0x1d5a5,0x1d5d9,0x1d60d,0x1d641,0x1d675,0x1d7ca}, + new uint[]{0x47,0x262,0x50c,0x50d,0x13c0,0x13f3,0xa4d6,0xff27,0x1d406,0x1d43a,0x1d46e,0x1d4a2,0x1d4d6,0x1d50a,0x1d53e,0x1d572,0x1d5a6,0x1d5da,0x1d60e,0x1d642,0x1d676}, + new uint[]{0x48,0x29c,0x397,0x41d,0x43d,0x13bb,0x157c,0x210b,0x210c,0x210d,0x2c8e,0xa4e7,0xff28,0x102cf,0x1d407,0x1d43b,0x1d46f,0x1d4d7,0x1d573,0x1d5a7,0x1d5db,0x1d60f,0x1d643,0x1d677,0x1d6ae,0x1d6e8,0x1d722,0x1d75c,0x1d796}, + new uint[]{0x4a,0x37f,0x408,0x13ab,0x148d,0xa4d9,0xa7b2,0xff2a,0x1d409,0x1d43d,0x1d471,0x1d4a5,0x1d4d9,0x1d50d,0x1d541,0x1d575,0x1d5a9,0x1d5dd,0x1d611,0x1d645,0x1d679}, + new uint[]{0x4b,0x39a,0x41a,0x13e6,0x16d5,0x212a,0x2c94,0xa4d7,0xff2b,0x10518,0x1d40a,0x1d43e,0x1d472,0x1d4a6,0x1d4da,0x1d50e,0x1d542,0x1d576,0x1d5aa,0x1d5de,0x1d612,0x1d646,0x1d67a,0x1d6b1,0x1d6eb,0x1d725,0x1d75f,0x1d799}, + new uint[]{0x4c,0x29f,0x13de,0x14aa,0x2112,0x216c,0x2cd0,0x2cd1,0xa4e1,0xff2c,0x1041b,0x10443,0x10526,0x118a3,0x118b2,0x1d40b,0x1d43f,0x1d473,0x1d4db,0x1d50f,0x1d543,0x1d577,0x1d5ab,0x1d5df,0x1d613,0x1d647,0x1d67b}, + new uint[]{0x4d,0x39c,0x3fa,0x41c,0x13b7,0x15f0,0x16d6,0x2133,0x216f,0x2c98,0xa4df,0xff2d,0x102b0,0x10311,0x1d40c,0x1d440,0x1d474,0x1d4dc,0x1d510,0x1d544,0x1d578,0x1d5ac,0x1d5e0,0x1d614,0x1d648,0x1d67c,0x1d6b3,0x1d6ed,0x1d727,0x1d761,0x1d79b}, + new uint[]{0x4e,0x274,0x39d,0x2115,0x2c9a,0xa4e0,0xff2e,0x10513,0x1d40d,0x1d441,0x1d475,0x1d4a9,0x1d4dd,0x1d511,0x1d579,0x1d5ad,0x1d5e1,0x1d615,0x1d649,0x1d67d,0x1d6b4,0x1d6ee,0x1d728,0x1d762,0x1d79c}, + new uint[]{0x50,0x3a1,0x420,0x13e2,0x146d,0x2119,0x2ca2,0xa4d1,0xff30,0x10295,0x1d40f,0x1d443,0x1d477,0x1d4ab,0x1d4df,0x1d513,0x1d57b,0x1d5af,0x1d5e3,0x1d617,0x1d64b,0x1d67f,0x1d6b8,0x1d6f2,0x1d72c,0x1d766,0x1d7a0}, + new uint[]{0x51,0x211a,0x2d55,0xff31,0x1d410,0x1d444,0x1d478,0x1d4ac,0x1d4e0,0x1d514,0x1d57c,0x1d5b0,0x1d5e4,0x1d618,0x1d64c,0x1d680}, + new uint[]{0x52,0x1a6,0x280,0x13a1,0x13d2,0x1587,0x16b1,0x211b,0x211c,0x211d,0xa4e3,0xff32,0x1d411,0x1d445,0x1d479,0x1d4e1,0x1d57d,0x1d5b1,0x1d5e5,0x1d619,0x1d64d,0x1d681}, + new uint[]{0x53,0x405,0x54f,0x13d5,0x13da,0xa4e2,0xff33,0x10296,0x10420,0x1d412,0x1d446,0x1d47a,0x1d4ae,0x1d4e2,0x1d516,0x1d54a,0x1d57e,0x1d5b2,0x1d5e6,0x1d61a,0x1d64e,0x1d682}, + new uint[]{0x54,0x3a4,0x422,0x13a2,0x22a4,0x27d9,0x2ca6,0xa4d4,0xff34,0x10297,0x102b1,0x10315,0x118bc,0x1d413,0x1d447,0x1d47b,0x1d4af,0x1d4e3,0x1d517,0x1d54b,0x1d57f,0x1d5b3,0x1d5e7,0x1d61b,0x1d64f,0x1d683,0x1d6bb,0x1d6f5,0x1d72f,0x1d769,0x1d7a3,0x1f768}, + new uint[]{0x55,0x54d,0x144c,0x222a,0x22c3,0xa4f4,0xff35,0x118b8,0x1d414,0x1d448,0x1d47c,0x1d4b0,0x1d4e4,0x1d518,0x1d54c,0x1d580,0x1d5b4,0x1d5e8,0x1d61c,0x1d650,0x1d684}, + new uint[]{0x56,0x474,0x667,0x6f7,0x13d9,0x142f,0x2164,0x2d38,0xa4e6,0xff36,0x1051d,0x118a0,0x1d415,0x1d449,0x1d47d,0x1d4b1,0x1d4e5,0x1d519,0x1d54d,0x1d581,0x1d5b5,0x1d5e9,0x1d61d,0x1d651,0x1d685}, + new uint[]{0x57,0x51c,0x13b3,0x13d4,0xa4ea,0xff37,0x118e6,0x118ef,0x1d416,0x1d44a,0x1d47e,0x1d4b2,0x1d4e6,0x1d51a,0x1d54e,0x1d582,0x1d5b6,0x1d5ea,0x1d61e,0x1d652,0x1d686}, + new uint[]{0x58,0x3a7,0x425,0x166d,0x16b7,0x2169,0x2573,0x2cac,0x2d5d,0xa4eb,0xa7b3,0xff38,0x10290,0x102b4,0x10317,0x10322,0x10527,0x118ec,0x1d417,0x1d44b,0x1d47f,0x1d4b3,0x1d4e7,0x1d51b,0x1d54f,0x1d583,0x1d5b7,0x1d5eb,0x1d61f,0x1d653,0x1d687,0x1d6be,0x1d6f8,0x1d732,0x1d76c,0x1d7a6}, + new uint[]{0x59,0x3a5,0x3d2,0x4ae,0x13a9,0x13bd,0x2ca8,0xa4ec,0xff39,0x102b2,0x118a4,0x1d418,0x1d44c,0x1d480,0x1d4b4,0x1d4e8,0x1d51c,0x1d550,0x1d584,0x1d5b8,0x1d5ec,0x1d620,0x1d654,0x1d688,0x1d6bc,0x1d6f6,0x1d730,0x1d76a,0x1d7a4}, + new uint[]{0x5a,0x396,0x13c3,0x2124,0x2128,0xa4dc,0xff3a,0x102f5,0x118a9,0x118e5,0x1d419,0x1d44d,0x1d481,0x1d4b5,0x1d4e9,0x1d585,0x1d5b9,0x1d5ed,0x1d621,0x1d655,0x1d689,0x1d6ad,0x1d6e7,0x1d721,0x1d75b,0x1d795}, + new uint[]{0x5c,0x2216,0x27cd,0x29f5,0x29f9,0x2f02,0x31d4,0x4e36,0xfe68,0xff3c}, + new uint[]{0x5e,0x2c4,0x2c6}, + new uint[]{0x5f,0x7fa,0xfe4d,0xfe4e,0xfe4f,0xff3f}, + new uint[]{0x61,0x251,0x3b1,0x430,0x237a,0xff41,0x1d41a,0x1d44e,0x1d482,0x1d4b6,0x1d4ea,0x1d51e,0x1d552,0x1d586,0x1d5ba,0x1d5ee,0x1d622,0x1d656,0x1d68a,0x1d6c2,0x1d6fc,0x1d736,0x1d770,0x1d7aa}, + new uint[]{0x62,0x184,0x42c,0x13cf,0x15af,0xff42,0x1d41b,0x1d44f,0x1d483,0x1d4b7,0x1d4eb,0x1d51f,0x1d553,0x1d587,0x1d5bb,0x1d5ef,0x1d623,0x1d657,0x1d68b}, + new uint[]{0x63,0x3f2,0x441,0x1d04,0x217d,0x2ca5,0xff43,0x1043d,0x1d41c,0x1d450,0x1d484,0x1d4b8,0x1d4ec,0x1d520,0x1d554,0x1d588,0x1d5bc,0x1d5f0,0x1d624,0x1d658,0x1d68c}, + new uint[]{0x64,0x501,0x13e7,0x146f,0x2146,0x217e,0xa4d2,0xff44,0x1d41d,0x1d451,0x1d485,0x1d4b9,0x1d4ed,0x1d521,0x1d555,0x1d589,0x1d5bd,0x1d5f1,0x1d625,0x1d659,0x1d68d}, + new uint[]{0x65,0x435,0x4bd,0x212e,0x212f,0x2147,0xab32,0xff45,0x1d41e,0x1d452,0x1d486,0x1d4ee,0x1d522,0x1d556,0x1d58a,0x1d5be,0x1d5f2,0x1d626,0x1d65a,0x1d68e}, + new uint[]{0x66,0x17f,0x584,0x1e9d,0xa799,0xab35,0xff46,0x1d41f,0x1d453,0x1d487,0x1d4bb,0x1d4ef,0x1d523,0x1d557,0x1d58b,0x1d5bf,0x1d5f3,0x1d627,0x1d65b,0x1d68f}, + new uint[]{0x67,0x18d,0x261,0x581,0x1d83,0x210a,0xff47,0x1d420,0x1d454,0x1d488,0x1d4f0,0x1d524,0x1d558,0x1d58c,0x1d5c0,0x1d5f4,0x1d628,0x1d65c,0x1d690}, + new uint[]{0x68,0x4bb,0x570,0x13c2,0x210e,0xff48,0x1d421,0x1d489,0x1d4bd,0x1d4f1,0x1d525,0x1d559,0x1d58d,0x1d5c1,0x1d5f5,0x1d629,0x1d65d,0x1d691}, + new uint[]{0x69,0x131,0x269,0x26a,0x2db,0x37a,0x3b9,0x456,0x4cf,0x13a5,0x1fbe,0x2139,0x2148,0x2170,0x2373,0xa647,0xff49,0x118c3,0x1d422,0x1d456,0x1d48a,0x1d4be,0x1d4f2,0x1d526,0x1d55a,0x1d58e,0x1d5c2,0x1d5f6,0x1d62a,0x1d65e,0x1d692,0x1d6a4,0x1d6ca,0x1d704,0x1d73e,0x1d778,0x1d7b2}, + new uint[]{0x6a,0x3f3,0x458,0x2149,0xff4a,0x1d423,0x1d457,0x1d48b,0x1d4bf,0x1d4f3,0x1d527,0x1d55b,0x1d58f,0x1d5c3,0x1d5f7,0x1d62b,0x1d65f,0x1d693}, + new uint[]{0x6b,0x138,0x3ba,0x3f0,0x43a,0x1d0b,0x2c95,0xff4b,0x1d424,0x1d458,0x1d48c,0x1d4c0,0x1d4f4,0x1d528,0x1d55c,0x1d590,0x1d5c4,0x1d5f8,0x1d62c,0x1d660,0x1d694,0x1d6cb,0x1d6de,0x1d705,0x1d718,0x1d73f,0x1d752,0x1d779,0x1d78c,0x1d7b3,0x1d7c6}, + new uint[]{0x6d,0xff4d}, + new uint[]{0x6e,0x3c0,0x3d6,0x43f,0x578,0x57c,0x1d28,0x213c,0xff4e,0x1d427,0x1d45b,0x1d48f,0x1d4c3,0x1d4f7,0x1d52b,0x1d55f,0x1d593,0x1d5c7,0x1d5fb,0x1d62f,0x1d663,0x1d697,0x1d6d1,0x1d6e1,0x1d70b,0x1d71b,0x1d745,0x1d755,0x1d77f,0x1d78f,0x1d7b9,0x1d7c9}, + new uint[]{0x6f,0x3bf,0x3c3,0x43e,0x585,0x5e1,0x647,0x665,0x6be,0x6c1,0x6d5,0x6f5,0x966,0xa66,0xae6,0xbe6,0xc02,0xc66,0xc82,0xce6,0xd02,0xd66,0xd82,0xe50,0xed0,0x101d,0x1040,0x10ff,0x1d0f,0x1d11,0x2134,0x2c9f,0xab3d,0xfba6,0xfba7,0xfba8,0xfba9,0xfbaa,0xfbab,0xfbac,0xfbad,0xfee9,0xfeea,0xfeeb,0xfeec,0xff4f,0x1042c,0x118c8,0x118d7,0x1d428,0x1d45c,0x1d490,0x1d4f8,0x1d52c,0x1d560,0x1d594,0x1d5c8,0x1d5fc,0x1d630,0x1d664,0x1d698,0x1d6d0,0x1d6d4,0x1d70a,0x1d70e,0x1d744,0x1d748,0x1d77e,0x1d782,0x1d7b8,0x1d7bc,0x1ee24,0x1ee64,0x1ee84}, + new uint[]{0x70,0x3c1,0x3f1,0x440,0x2374,0x2ca3,0xff50,0x1d429,0x1d45d,0x1d491,0x1d4c5,0x1d4f9,0x1d52d,0x1d561,0x1d595,0x1d5c9,0x1d5fd,0x1d631,0x1d665,0x1d699,0x1d6d2,0x1d6e0,0x1d70c,0x1d71a,0x1d746,0x1d754,0x1d780,0x1d78e,0x1d7ba,0x1d7c8}, + new uint[]{0x71,0x51b,0x563,0x566,0xff51,0x1d42a,0x1d45e,0x1d492,0x1d4c6,0x1d4fa,0x1d52e,0x1d562,0x1d596,0x1d5ca,0x1d5fe,0x1d632,0x1d666,0x1d69a}, + new uint[]{0x72,0x433,0x1d26,0x2c85,0xab47,0xab48,0xff52,0x1d42b,0x1d45f,0x1d493,0x1d4c7,0x1d4fb,0x1d52f,0x1d563,0x1d597,0x1d5cb,0x1d5ff,0x1d633,0x1d667,0x1d69b}, + new uint[]{0x73,0x1bd,0x455,0xa731,0xff53,0x10448,0x118c1,0x1d42c,0x1d460,0x1d494,0x1d4c8,0x1d4fc,0x1d530,0x1d564,0x1d598,0x1d5cc,0x1d600,0x1d634,0x1d668,0x1d69c}, + new uint[]{0x74,0x3c4,0x442,0x1d1b,0xff54,0x1d42d,0x1d461,0x1d495,0x1d4c9,0x1d4fd,0x1d531,0x1d565,0x1d599,0x1d5cd,0x1d601,0x1d635,0x1d669,0x1d69d,0x1d6d5,0x1d70f,0x1d749,0x1d783,0x1d7bd}, + new uint[]{0x75,0x28b,0x3c5,0x446,0x57d,0x1d1c,0xa79f,0xab4e,0xab52,0xff55,0x118d8,0x1d42e,0x1d462,0x1d496,0x1d4ca,0x1d4fe,0x1d532,0x1d566,0x1d59a,0x1d5ce,0x1d602,0x1d636,0x1d66a,0x1d69e,0x1d6d6,0x1d710,0x1d74a,0x1d784,0x1d7be}, + new uint[]{0x76,0x3bd,0x475,0x5d8,0x1d20,0x2174,0x2228,0x22c1,0xff56,0x118c0,0x1d42f,0x1d463,0x1d497,0x1d4cb,0x1d4ff,0x1d533,0x1d567,0x1d59b,0x1d5cf,0x1d603,0x1d637,0x1d66b,0x1d69f,0x1d6ce,0x1d708,0x1d742,0x1d77c,0x1d7b6}, + new uint[]{0x77,0xff57}, + new uint[]{0x78,0xd7,0x445,0x1541,0x157d,0x166e,0x2179,0x292b,0x292c,0x2a2f,0xff58,0x1d431,0x1d465,0x1d499,0x1d4cd,0x1d501,0x1d535,0x1d569,0x1d59d,0x1d5d1,0x1d605,0x1d639,0x1d66d,0x1d6a1}, + new uint[]{0x79,0x263,0x28f,0x3b3,0x443,0x4af,0x10e7,0x1d8c,0x1eff,0x213d,0xab5a,0xff59,0x118dc,0x1d432,0x1d466,0x1d49a,0x1d4ce,0x1d502,0x1d536,0x1d56a,0x1d59e,0x1d5d2,0x1d606,0x1d63a,0x1d66e,0x1d6a2,0x1d6c4,0x1d6fe,0x1d738,0x1d772,0x1d7ac}, + new uint[]{0x7a,0x1d22,0xff5a,0x118c4,0x1d433,0x1d467,0x1d49b,0x1d4cf,0x1d503,0x1d537,0x1d56b,0x1d59f,0x1d5d3,0x1d607,0x1d63b,0x1d66f,0x1d6a3}, + new uint[]{0x7b,0x2774,0xff5b,0x1d114}, + new uint[]{0x7d,0x2775,0xff5d}, + new uint[]{0x7e,0x2dc,0x1fc0,0x2053,0x223c}, + new uint[]{0xa3,0x20a4}, + new uint[]{0xa9,0x24b8}, + new uint[]{0xae,0x24c7}, + new uint[]{0xaf,0x2c9,0x203e,0x2594,0xfe49,0xfe4a,0xfe4b,0xfe4c,0xffe3}, + new uint[]{0xb0,0x2da,0x2218,0x25cb,0x25e6,0x2e30}, + new uint[]{0xb5,0x3bc,0x1d6cd,0x1d707,0x1d741,0x1d77b,0x1d7b5}, + new uint[]{0xb6,0x2e3f}, + new uint[]{0xb7,0x387,0x1427,0x16eb,0x2022,0x2027,0x2219,0x22c5,0x2e31,0x30fb,0xa78f,0xff65,0x10101}, + new uint[]{0xba,0x1d52,0x2070}, + new uint[]{0xc4,0x4d2}, + new uint[]{0xc5,0x226}, + new uint[]{0xd6,0x150,0x4e6,0x2365}, + new uint[]{0xde,0x3f7}, + new uint[]{0xdf,0x3b2,0x3d0,0x13f0,0xa7b5,0x1d6c3,0x1d6fd,0x1d737,0x1d771,0x1d7ab}, + new uint[]{0xe4,0x4d3}, + new uint[]{0xe5,0x227}, + new uint[]{0xf6,0x4e7,0x629,0x6c3,0xfe93,0xfe94}, + new uint[]{0xf7,0x2797}, + new uint[]{0xfe,0x1bf,0x3f8}, + new uint[]{0x102,0x1cd}, + new uint[]{0x103,0x1ce}, + new uint[]{0x114,0x11a}, + new uint[]{0x115,0x11b}, + new uint[]{0x11e,0x1e6}, + new uint[]{0x11f,0x1e7}, + new uint[]{0x123,0x1f5}, + new uint[]{0x12c,0x1cf}, + new uint[]{0x12d,0x1d0}, + new uint[]{0x146,0x272}, + new uint[]{0x14e,0x1d1}, + new uint[]{0x14f,0x1d2}, + new uint[]{0x162,0x21a}, + new uint[]{0x163,0x1ab,0x21b,0x13bf}, + new uint[]{0x16c,0x1d3}, + new uint[]{0x16d,0x1d4}, + new uint[]{0x185,0x44c}, + new uint[]{0x186,0x3fd,0x2183,0xa4db,0x10423}, + new uint[]{0x18e,0x2203,0x2d3a,0xa4f1}, + new uint[]{0x18f,0x4d8}, + new uint[]{0x190,0x510,0x13cb,0x2107,0x10401}, + new uint[]{0x1a8,0x3e9,0x1d24,0xa645}, + new uint[]{0x1a9,0x3a3,0x2140,0x2211,0x2d49,0x1d6ba,0x1d6f4,0x1d72e,0x1d768,0x1d7a2}, + new uint[]{0x1b1,0x162e,0x1634,0x2127}, + new uint[]{0x1dd,0x259,0x4d9}, + new uint[]{0x1f6,0x50a}, + new uint[]{0x21d,0x292,0x4e1,0x10f3,0x2ccd,0xa76b}, + new uint[]{0x237,0x575,0x1d6a5}, + new uint[]{0x245,0x39b,0x41b,0x668,0x6f8,0x1431,0x2d37,0xa4e5,0x1028d,0x1d6b2,0x1d6ec,0x1d726,0x1d760,0x1d79a}, + new uint[]{0x24b,0x1d90}, + new uint[]{0x254,0x37b,0x1d10,0x2184,0x1044b}, + new uint[]{0x25b,0x3b5,0x3f5,0x454,0x511,0x22f4,0x2c89,0xa793,0x10429,0x118ce,0x1d6c6,0x1d6dc,0x1d700,0x1d716,0x1d73a,0x1d750,0x1d774,0x1d78a,0x1d7ae,0x1d7c4}, + new uint[]{0x25c,0x437,0x1d08}, + new uint[]{0x25e,0xa79d,0x10442}, + new uint[]{0x270,0x57a}, + new uint[]{0x277,0x1043f}, + new uint[]{0x278,0x3c6,0x3d5,0x444,0x2cab,0x1d6d7,0x1d6df,0x1d711,0x1d719,0x1d74b,0x1d753,0x1d785,0x1d78d,0x1d7bf,0x1d7c7}, + new uint[]{0x27f,0x2129}, + new uint[]{0x283,0x222b,0xab4d}, + new uint[]{0x28c,0x1d27}, + new uint[]{0x298,0x2299,0x2609,0x2a00,0x2d59,0xa668}, + new uint[]{0x29a,0x1042a}, + new uint[]{0x2b3,0x18f4}, + new uint[]{0x2bf,0x2d3,0x559}, + new uint[]{0x2c1,0x2e4}, + new uint[]{0x2c7,0x2d8,0xa67e}, + new uint[]{0x2cf,0x375}, + new uint[]{0x2d9,0x971,0xd4e}, + new uint[]{0x2e1,0x18f3}, + new uint[]{0x2e2,0x18f5}, + new uint[]{0x2ea,0x2fb,0xa716}, + new uint[]{0x2eb,0xa714}, + new uint[]{0x2f3,0x3002}, + new uint[]{0x300,0x340,0x953}, + new uint[]{0x301,0x341,0x59c,0x59d,0x618,0x64e,0x747,0x954}, + new uint[]{0x302,0x311,0x65b,0x7ee,0x1cd0}, + new uint[]{0x303,0x342,0x653}, + new uint[]{0x304,0x305,0x659,0x7eb,0x1cd2}, + new uint[]{0x306,0x30c,0x36e,0x658,0x65a,0xa67c}, + new uint[]{0x307,0x358,0x5b9,0x5ba,0x5c1,0x5c2,0x5c4,0x6ec,0x740,0x741,0x7ed,0x8ea,0x902,0xa02,0xa82,0xbcd}, + new uint[]{0x308,0x7f3,0x8eb}, + new uint[]{0x309,0x302c}, + new uint[]{0x30a,0x366,0x5af,0x652,0x6df,0xb82,0xe4d,0xecd,0x1036,0x17c6,0x17d3,0x309a}, + new uint[]{0x30b,0x64b,0x8f0}, + new uint[]{0x30d,0x670}, + new uint[]{0x30e,0x1cda}, + new uint[]{0x312,0x657}, + new uint[]{0x313,0x315,0x343,0x619,0x64f,0x8f3}, + new uint[]{0x314,0x65d}, + new uint[]{0x316,0x1ced}, + new uint[]{0x317,0x61a,0x650}, + new uint[]{0x320,0x331,0x952}, + new uint[]{0x321,0x326,0x327,0x339}, + new uint[]{0x322,0x328,0x345,0x1ab7}, + new uint[]{0x323,0x5b4,0x5c5,0x65c,0x8ed,0x93c,0x9bc,0xa3c,0xabc,0xb3c,0x1cdd,0x10a3a,0x114c3}, + new uint[]{0x324,0x8ee,0x1cde}, + new uint[]{0x325,0x302d}, + new uint[]{0x329,0x656,0x1cdc}, + new uint[]{0x32b,0x1cd5}, + new uint[]{0x32d,0x1cd9}, + new uint[]{0x32e,0x1cd8}, + new uint[]{0x333,0x347}, + new uint[]{0x335,0x336}, + new uint[]{0x337,0x338}, + new uint[]{0x350,0x357,0x8f8,0x8ff}, + new uint[]{0x352,0x900}, + new uint[]{0x354,0x8f9}, + new uint[]{0x355,0x8fa}, + new uint[]{0x370,0x13a8,0x13b0,0x2c75}, + new uint[]{0x376,0x418,0x10425}, + new uint[]{0x377,0x438,0x1d0e,0x1044d}, + new uint[]{0x37d,0xa73f}, + new uint[]{0x393,0x413,0x13b1,0x14a5,0x213e,0x2c84,0x1d6aa,0x1d6e4,0x1d71e,0x1d758,0x1d792}, + new uint[]{0x394,0x1403,0x2206,0x25b3,0x2c86,0x2d60,0x10285,0x102a3,0x1d6ab,0x1d6e5,0x1d71f,0x1d759,0x1d793,0x1f702}, + new uint[]{0x39e,0x1d6b5,0x1d6ef,0x1d729,0x1d763,0x1d79d}, + new uint[]{0x3a0,0x41f,0x213f,0x220f,0x2ca0,0x1d6b7,0x1d6f1,0x1d72b,0x1d765,0x1d79f}, + new uint[]{0x3a6,0x424,0x553,0x16f0,0x2caa,0x102b3,0x1d6bd,0x1d6f7,0x1d731,0x1d76b,0x1d7a5}, + new uint[]{0x3a8,0x470,0x16d8,0x2cae,0x102b5,0x1d6bf,0x1d6f9,0x1d733,0x1d76d,0x1d7a7}, + new uint[]{0x3a9,0x162f,0x1635,0x2126,0x102b6,0x1d6c0,0x1d6fa,0x1d734,0x1d76e,0x1d7a8}, + new uint[]{0x3b4,0x56e,0x1577,0x1e9f,0x2e39,0x1d6c5,0x1d6ff,0x1d739,0x1d773,0x1d7ad}, + new uint[]{0x3b6,0x1d6c7,0x1d701,0x1d73b,0x1d775,0x1d7af}, + new uint[]{0x3bb,0x2c96,0x1d6cc,0x1d706,0x1d740,0x1d77a,0x1d7b4}, + new uint[]{0x3be,0x1d6cf,0x1d709,0x1d743,0x1d77d,0x1d7b7}, + new uint[]{0x3c2,0x3db,0x1d6d3,0x1d70d,0x1d747,0x1d781,0x1d7bb}, + new uint[]{0x3c7,0x2cad,0xab53,0xab55,0x1d6d8,0x1d712,0x1d74c,0x1d786,0x1d7c0}, + new uint[]{0x3c8,0x471,0x1d6d9,0x1d713,0x1d74d,0x1d787,0x1d7c1}, + new uint[]{0x3c9,0x2375,0x2cb1,0xa64d,0xa7b7,0x1d6da,0x1d714,0x1d74e,0x1d788,0x1d7c2}, + new uint[]{0x3d7,0x2ce4}, + new uint[]{0x3d8,0x102ad,0x10312}, + new uint[]{0x3dd,0x1d7cb}, + new uint[]{0x3ec,0x2cdc}, + new uint[]{0x3ff,0xa73e}, + new uint[]{0x404,0x20ac,0x2c88,0xa792}, + new uint[]{0x40d,0x419}, + new uint[]{0x428,0x2cbc}, + new uint[]{0x42d,0x2108}, + new uint[]{0x439,0x45d}, + new uint[]{0x43b,0x1d2b}, + new uint[]{0x448,0x2cbd}, + new uint[]{0x44f,0x1d19}, + new uint[]{0x459,0xab60}, + new uint[]{0x460,0x13c7,0x15ef}, + new uint[]{0x4b6,0x4cb}, + new uint[]{0x4b7,0x4cc}, + new uint[]{0x548,0x144e,0x2229,0x22c2,0xa4f5}, + new uint[]{0x554,0x20bd}, + new uint[]{0x596,0x5ad}, + new uint[]{0x598,0x5ae}, + new uint[]{0x599,0x5a8}, + new uint[]{0x59a,0x5a4}, + new uint[]{0x5d0,0x2135,0xfb21}, + new uint[]{0x5d1,0x2136}, + new uint[]{0x5d2,0x2137}, + new uint[]{0x5d3,0x2138,0xfb22}, + new uint[]{0x5d4,0xfb23}, + new uint[]{0x5db,0xfb24}, + new uint[]{0x5dc,0xfb25}, + new uint[]{0x5dd,0xfb26}, + new uint[]{0x5e2,0xfb20}, + new uint[]{0x5e8,0xfb27}, + new uint[]{0x5ea,0xfb28}, + new uint[]{0x60c,0x66c,0x2e32}, + new uint[]{0x60f,0x639,0xfec9,0xfeca,0xfecb,0xfecc,0x1ee0f,0x1ee2f,0x1ee4f,0x1ee6f,0x1ee8f,0x1eeaf}, + new uint[]{0x61b,0x2e35}, + new uint[]{0x61f,0x2e2e}, + new uint[]{0x621,0xfe80}, + new uint[]{0x622,0xfe81,0xfe82}, + new uint[]{0x628,0xfe8f,0xfe90,0xfe91,0xfe92,0x1ee01,0x1ee21,0x1ee61,0x1ee81,0x1eea1}, + new uint[]{0x62a,0xfe95,0xfe96,0xfe97,0xfe98,0x1ee15,0x1ee35,0x1ee75,0x1ee95,0x1eeb5}, + new uint[]{0x62c,0xfe9d,0xfe9e,0xfe9f,0xfea0,0x1ee02,0x1ee22,0x1ee42,0x1ee62,0x1ee82,0x1eea2}, + new uint[]{0x62d,0xfea1,0xfea2,0xfea3,0xfea4,0x1ee07,0x1ee27,0x1ee47,0x1ee67,0x1ee87,0x1eea7}, + new uint[]{0x62e,0xfea5,0xfea6,0xfea7,0xfea8,0x1ee17,0x1ee37,0x1ee57,0x1ee77,0x1ee97,0x1eeb7}, + new uint[]{0x62f,0xfea9,0xfeaa,0x102e1,0x1ee03,0x1ee83,0x1eea3}, + new uint[]{0x630,0xfeab,0xfeac,0x1ee18,0x1ee98,0x1eeb8}, + new uint[]{0x631,0xfead,0xfeae,0x1ee13,0x1ee93,0x1eeb3}, + new uint[]{0x632,0xfeaf,0xfeb0,0x1ee06,0x1ee86,0x1eea6}, + new uint[]{0x633,0xfeb1,0xfeb2,0xfeb3,0xfeb4,0x1ee0e,0x1ee2e,0x1ee4e,0x1ee6e,0x1ee8e,0x1eeae}, + new uint[]{0x635,0xfeb9,0xfeba,0xfebb,0xfebc,0x102f2,0x1ee11,0x1ee31,0x1ee51,0x1ee71,0x1ee91,0x1eeb1}, + new uint[]{0x636,0xfebd,0xfebe,0xfebf,0xfec0,0x1ee19,0x1ee39,0x1ee59,0x1ee79,0x1ee99,0x1eeb9}, + new uint[]{0x637,0xfec1,0xfec2,0xfec3,0xfec4,0x102e8,0x1ee08,0x1ee68,0x1ee88,0x1eea8}, + new uint[]{0x638,0xfec5,0xfec6,0xfec7,0xfec8,0x1ee1a,0x1ee7a,0x1ee9a,0x1eeba}, + new uint[]{0x63a,0xfecd,0xfece,0xfecf,0xfed0,0x1ee1b,0x1ee3b,0x1ee5b,0x1ee7b,0x1ee9b,0x1eebb}, + new uint[]{0x641,0x6a7,0xfed1,0xfed2,0xfed3,0xfed4,0x1ee10,0x1ee30,0x1ee70,0x1ee90,0x1eeb0}, + new uint[]{0x642,0xfed5,0xfed6,0xfed7,0xfed8,0x1ee12,0x1ee32,0x1ee52,0x1ee72,0x1ee92,0x1eeb2}, + new uint[]{0x643,0x6a9,0x6aa,0xfb8e,0xfb8f,0xfb90,0xfb91,0xfed9,0xfeda,0xfedb,0xfedc,0x1ee0a,0x1ee2a,0x1ee6a}, + new uint[]{0x644,0xfedd,0xfede,0xfedf,0xfee0,0x1ee0b,0x1ee2b,0x1ee4b,0x1ee8b,0x1eeab}, + new uint[]{0x645,0xfee1,0xfee2,0xfee3,0xfee4,0x1ee0c,0x1ee2c,0x1ee6c,0x1ee8c,0x1eeac}, + new uint[]{0x646,0xfee5,0xfee6,0xfee7,0xfee8,0x1ee0d,0x1ee2d,0x1ee4d,0x1ee6d,0x1ee8d,0x1eead}, + new uint[]{0x648,0x8b1,0xfeed,0xfeee,0x102e4,0x1ee05,0x1ee85,0x1eea5}, + new uint[]{0x649,0x64a,0x66e,0x6ba,0x6cc,0x6d2,0xfb9e,0xfb9f,0xfbae,0xfbaf,0xfbe8,0xfbe9,0xfbfc,0xfbfd,0xfbfe,0xfbff,0xfeef,0xfef0,0xfef1,0xfef2,0xfef3,0xfef4,0x1ee09,0x1ee1c,0x1ee1d,0x1ee29,0x1ee49,0x1ee5d,0x1ee69,0x1ee7c,0x1ee89,0x1eea9}, + new uint[]{0x64c,0x8e5,0x8e8,0x8f1}, + new uint[]{0x64d,0x8f2}, + new uint[]{0x655,0x65f}, + new uint[]{0x662,0x6f2,0xa9cf}, + new uint[]{0x663,0x6f3,0x1e8c9}, + new uint[]{0x664,0x6f4}, + new uint[]{0x666,0x6f6}, + new uint[]{0x669,0x6f9,0x967,0x118e4}, + new uint[]{0x66f,0x6a1,0x1ee1e,0x1ee1f,0x1ee5f,0x1ee7e}, + new uint[]{0x671,0xfb50,0xfb51}, + new uint[]{0x67a,0xfb5e,0xfb5f,0xfb60,0xfb61}, + new uint[]{0x67b,0x6d0,0xfb52,0xfb53,0xfb54,0xfb55,0xfbe4,0xfbe5,0xfbe6,0xfbe7}, + new uint[]{0x67f,0xfb62,0xfb63,0xfb64,0xfb65}, + new uint[]{0x680,0xfb5a,0xfb5b,0xfb5c,0xfb5d}, + new uint[]{0x683,0xfb76,0xfb77,0xfb78,0xfb79}, + new uint[]{0x684,0xfb72,0xfb73,0xfb74,0xfb75}, + new uint[]{0x686,0xfb7a,0xfb7b,0xfb7c,0xfb7d}, + new uint[]{0x687,0xfb7e,0xfb7f,0xfb80,0xfb81}, + new uint[]{0x68c,0xfb84,0xfb85}, + new uint[]{0x68d,0xfb82,0xfb83}, + new uint[]{0x6a6,0xfb6e,0xfb6f,0xfb70,0xfb71}, + new uint[]{0x6ac,0x762}, + new uint[]{0x6af,0x8b0,0xfb92,0xfb93,0xfb94,0xfb95}, + new uint[]{0x6b1,0xfb9a,0xfb9b,0xfb9c,0xfb9d}, + new uint[]{0x6b3,0xfb96,0xfb97,0xfb98,0xfb99}, + new uint[]{0x6c0,0x6c2,0xfba4,0xfba5}, + new uint[]{0x6c5,0xfbe0,0xfbe1}, + new uint[]{0x6d3,0xfbb0,0xfbb1}, + new uint[]{0x6db,0x1ab4,0x20db}, + new uint[]{0x73c,0x742}, + new uint[]{0x754,0x767,0x8a9}, + new uint[]{0x93d,0xabd}, + new uint[]{0x941,0xac1}, + new uint[]{0x942,0xac2}, + new uint[]{0x946,0xa4b}, + new uint[]{0x94d,0xa4d,0xacd}, + new uint[]{0x968,0xae8}, + new uint[]{0x969,0xae9}, + new uint[]{0x96a,0xaea}, + new uint[]{0x96e,0xaee}, + new uint[]{0x970,0xaf0,0x26ac,0x110bb,0x111c7}, + new uint[]{0x983,0xa03,0xc03,0xc83,0xd03,0xd83,0x1038,0x114c1}, + new uint[]{0x998,0x11492}, + new uint[]{0x99a,0x11494}, + new uint[]{0x99c,0x11496}, + new uint[]{0x99e,0x11498}, + new uint[]{0x99f,0x11499}, + new uint[]{0x9a1,0x1149b}, + new uint[]{0x9a3,0x114aa}, + new uint[]{0x9a4,0x1149e}, + new uint[]{0x9a5,0x1149f}, + new uint[]{0x9a6,0x114a0}, + new uint[]{0x9a7,0x114a1}, + new uint[]{0x9a8,0x114a2}, + new uint[]{0x9aa,0x114a3}, + new uint[]{0x9ac,0x114a9}, + new uint[]{0x9ae,0x114a7}, + new uint[]{0x9af,0x114a8}, + new uint[]{0x9b0,0x114ab}, + new uint[]{0x9b2,0x1149d}, + new uint[]{0x9b7,0x114ad}, + new uint[]{0x9b8,0x114ae}, + new uint[]{0x9bd,0x114c4}, + new uint[]{0x9be,0x114b0}, + new uint[]{0x9bf,0x114b1}, + new uint[]{0x9c7,0x114b9}, + new uint[]{0x9cb,0x114bc}, + new uint[]{0x9cc,0x114be}, + new uint[]{0x9cd,0x114c2}, + new uint[]{0x9d7,0x114bd}, + new uint[]{0x9e7,0x114d1}, + new uint[]{0x9e8,0x114d2}, + new uint[]{0x9ec,0x114d6}, + new uint[]{0xb85,0xbee}, + new uint[]{0xb88,0xbb0,0xbbe}, + new uint[]{0xb89,0xbe8,0xd09}, + new uint[]{0xb8e,0xbed}, + new uint[]{0xb90,0xb9c,0xd1c}, + new uint[]{0xb95,0xbe7}, + new uint[]{0xb9a,0xbea}, + new uint[]{0xba3,0xd23}, + new uint[]{0xba9,0xbc8}, + new uint[]{0xbaf,0xbf0}, + new uint[]{0xbb3,0xbd7}, + new uint[]{0xbb4,0xd34}, + new uint[]{0xbb6,0xd36}, + new uint[]{0xbb7,0xbf8}, + new uint[]{0xbbf,0xd3f,0xd40}, + new uint[]{0xbf3,0xbf5}, + new uint[]{0xc05,0xc85}, + new uint[]{0xc06,0xc86}, + new uint[]{0xc07,0xc87}, + new uint[]{0xc12,0xc92}, + new uint[]{0xc1c,0xc9c}, + new uint[]{0xc1e,0xc9e}, + new uint[]{0xc23,0xca3}, + new uint[]{0xc2f,0xcaf}, + new uint[]{0xc31,0xcb1}, + new uint[]{0xc32,0xcb2}, + new uint[]{0xc67,0xce7}, + new uint[]{0xc68,0xce8}, + new uint[]{0xc6f,0xcef}, + new uint[]{0xd1e,0xd61}, + new uint[]{0xd30,0xd31}, + new uint[]{0xd41,0xd42,0xd43}, + new uint[]{0xda2,0xdea}, + new uint[]{0xdaf,0xdeb}, + new uint[]{0xe02,0xe03}, + new uint[]{0xe04,0xe14,0xe15}, + new uint[]{0xe06,0xe21}, + new uint[]{0xe08,0xe88}, + new uint[]{0xe0a,0xe0b}, + new uint[]{0xe0e,0xe0f}, + new uint[]{0xe11,0xe17}, + new uint[]{0xe1a,0xe9a}, + new uint[]{0xe1b,0xe9b}, + new uint[]{0xe1d,0xe9d}, + new uint[]{0xe1e,0xe9e}, + new uint[]{0xe1f,0xe9f}, + new uint[]{0xe20,0xe26}, + new uint[]{0xe22,0xe8d}, + new uint[]{0xe2f,0x17d4}, + new uint[]{0xe32,0xe45}, + new uint[]{0xe34,0x17b7}, + new uint[]{0xe35,0x17b8}, + new uint[]{0xe36,0x17b9}, + new uint[]{0xe37,0x17ba}, + new uint[]{0xe38,0xeb8}, + new uint[]{0xe39,0xeb9}, + new uint[]{0xe48,0xec8,0x17cb}, + new uint[]{0xe49,0xec9}, + new uint[]{0xe4a,0xeca}, + new uint[]{0xe4b,0xecb}, + new uint[]{0xe4f,0x17d9}, + new uint[]{0xe5a,0x17d5}, + new uint[]{0xe5b,0x17da}, + new uint[]{0xf0b,0xf0c}, + new uint[]{0xf62,0xf6a}, + new uint[]{0x1041,0x1065}, + new uint[]{0x10a0,0xa786}, + new uint[]{0x1100,0x11a8,0x3131}, + new uint[]{0x1102,0x11ab,0x3134}, + new uint[]{0x1103,0x11ae,0x3137}, + new uint[]{0x1105,0x11af,0x3139}, + new uint[]{0x1106,0x11b7,0x3141}, + new uint[]{0x1107,0x11b8,0x3142}, + new uint[]{0x1109,0x11ba,0x3145}, + new uint[]{0x110b,0x11bc,0x3147}, + new uint[]{0x110c,0x11bd,0x3148}, + new uint[]{0x110e,0x11be,0x314a}, + new uint[]{0x110f,0x11bf,0x314b}, + new uint[]{0x1110,0x11c0,0x314c}, + new uint[]{0x1111,0x11c1,0x314d}, + new uint[]{0x1112,0x11c2,0x314e}, + new uint[]{0x1140,0x11eb,0x317f}, + new uint[]{0x114c,0x11f0,0x3181}, + new uint[]{0x1159,0x11f9,0x3186}, + new uint[]{0x1160,0x3164}, + new uint[]{0x1161,0x314f}, + new uint[]{0x1163,0x3151}, + new uint[]{0x1165,0x3153}, + new uint[]{0x1167,0x3155}, + new uint[]{0x1169,0x3157}, + new uint[]{0x116d,0x315b}, + new uint[]{0x116e,0x315c}, + new uint[]{0x1172,0x3160}, + new uint[]{0x1173,0x2014,0x2015,0x2500,0x2501,0x2f00,0x30fc,0x3161,0x31d0,0x4e00,0xa7f7,0xff0d}, + new uint[]{0x1175,0x239c,0x239f,0x23a2,0x23a5,0x23aa,0x23ae,0x2f01,0x3163,0x31d1,0x4e28}, + new uint[]{0x119e,0x318d}, + new uint[]{0x13ef,0x1ff6}, + new uint[]{0x1421,0x14d1}, + new uint[]{0x1429,0x1540}, + new uint[]{0x1435,0x2369}, + new uint[]{0x1450,0x2283,0x2e27}, + new uint[]{0x1455,0x2282,0x2e26}, + new uint[]{0x1489,0x1603}, + new uint[]{0x1490,0x1602}, + new uint[]{0x14d3,0x1604}, + new uint[]{0x14da,0x1607}, + new uint[]{0x1543,0x1622}, + new uint[]{0x1546,0x1623}, + new uint[]{0x154a,0x1624}, + new uint[]{0x15b5,0x2132,0xa4de}, + new uint[]{0x15b7,0xa7fb}, + new uint[]{0x15c4,0x2200,0x2c6f,0xa4ef}, + new uint[]{0x15d2,0x2aab}, + new uint[]{0x15d5,0x2aaa}, + new uint[]{0x15e1,0xa4f7}, + new uint[]{0x1646,0x1dbb}, + new uint[]{0x1660,0xa4ed}, + new uint[]{0x16bc,0x16e1}, + new uint[]{0x16bd,0x16c2,0x237f}, + new uint[]{0x16cf,0x2191}, + new uint[]{0x16d0,0x21bf}, + new uint[]{0x16da,0x21be,0x2a21}, + new uint[]{0x16dc,0x22c4,0x25c7,0x25ca,0x2662,0x10294,0x118b7,0x1f754}, + new uint[]{0x16de,0x22c8,0x2a1d}, + new uint[]{0x16e8,0x2195}, + new uint[]{0x16ef,0x2d63}, + new uint[]{0x17a2,0x17a3}, + new uint[]{0x1835,0x1855}, + new uint[]{0x185c,0x1896}, + new uint[]{0x199e,0x19d0}, + new uint[]{0x19b1,0x19d1}, + new uint[]{0x1a45,0x1a80,0x1a90}, + new uint[]{0x1b0d,0x1b52}, + new uint[]{0x1b11,0x1b53}, + new uint[]{0x1b28,0x1b58}, + new uint[]{0x1b50,0x1b5c}, + new uint[]{0x1d18,0x1d29}, + new uint[]{0x1d34,0x1d78}, + new uint[]{0x1d4b,0x1d9f}, + new uint[]{0x1d4d,0x1da2}, + new uint[]{0x1ddf,0x2de8}, + new uint[]{0x1e9a,0x1ea3}, + new uint[]{0x1f7d,0x1ff4}, + new uint[]{0x205d,0x22ee,0x2d57,0xfe19}, + new uint[]{0x205e,0x2999,0x2d42,0x2e3d}, + new uint[]{0x20b8,0x3012,0x3036}, + new uint[]{0x2117,0x24c5}, + new uint[]{0x2141,0xa4e8}, + new uint[]{0x2142,0xa4f6,0x10411}, + new uint[]{0x219e,0x2bec}, + new uint[]{0x219f,0x2bed}, + new uint[]{0x21a0,0x2bee}, + new uint[]{0x21a1,0x2bef}, + new uint[]{0x21b2,0x21b5}, + new uint[]{0x2202,0x1d6db,0x1d715,0x1d74f,0x1d789,0x1d7c3,0x1e8cc}, + new uint[]{0x2205,0x2300}, + new uint[]{0x2207,0x118a8,0x1d6c1,0x1d6fb,0x1d735,0x1d76f,0x1d7a9}, + new uint[]{0x220e,0x2588,0x25a0}, + new uint[]{0x2210,0x2a3f}, + new uint[]{0x2220,0x1e8c8}, + new uint[]{0x2227,0x22c0}, + new uint[]{0x2234,0x2e2b}, + new uint[]{0x2235,0x2e2a}, + new uint[]{0x2237,0x2e2c}, + new uint[]{0x2248,0x111de}, + new uint[]{0x224f,0x264e,0x1f75e}, + new uint[]{0x2261,0x2263}, + new uint[]{0x228d,0x2a03}, + new uint[]{0x228e,0x2a04}, + new uint[]{0x2293,0x2a05}, + new uint[]{0x2294,0x2a06}, + new uint[]{0x2295,0x2a01,0x102a8,0x1f728}, + new uint[]{0x2297,0x2a02}, + new uint[]{0x229b,0x235f}, + new uint[]{0x22a0,0x1f771}, + new uint[]{0x22a1,0x1f755}, + new uint[]{0x22a5,0x27c2,0xa4d5,0xa7b1}, + new uint[]{0x22b2,0x25c1}, + new uint[]{0x22b3,0x25b7}, + new uint[]{0x2307,0xfe34}, + new uint[]{0x2312,0x25e0}, + new uint[]{0x2319,0x2a3d}, + new uint[]{0x2324,0x2325}, + new uint[]{0x2329,0x276c,0x27e8,0x3008}, + new uint[]{0x232a,0x276d,0x27e9,0x3009}, + new uint[]{0x233b,0x29c7}, + new uint[]{0x233e,0x25ce,0x29be}, + new uint[]{0x2341,0x29c4,0x303c}, + new uint[]{0x2342,0x29c5}, + new uint[]{0x2349,0x29b0}, + new uint[]{0x234b,0x23c3}, + new uint[]{0x234e,0x23c2}, + new uint[]{0x2355,0x23c1}, + new uint[]{0x236d,0x23c6}, + new uint[]{0x2388,0x2638}, + new uint[]{0x23dc,0xfe35}, + new uint[]{0x23dd,0xfe36}, + new uint[]{0x23de,0xfe37}, + new uint[]{0x23df,0xfe38}, + new uint[]{0x23e0,0xfe39}, + new uint[]{0x23e1,0xfe3a}, + new uint[]{0x23e5,0x25b1}, + new uint[]{0x2460,0x2780}, + new uint[]{0x2461,0x2781}, + new uint[]{0x2462,0x2782}, + new uint[]{0x2463,0x2783}, + new uint[]{0x2464,0x2784}, + new uint[]{0x2465,0x2785}, + new uint[]{0x2466,0x2786}, + new uint[]{0x2467,0x2787}, + new uint[]{0x2468,0x2788}, + new uint[]{0x2469,0x2789}, + new uint[]{0x24be,0x24db}, + new uint[]{0x2502,0x2503,0xfe31,0xff5c}, + new uint[]{0x250c,0x250f}, + new uint[]{0x251c,0x2523}, + new uint[]{0x258c,0x2590}, + new uint[]{0x2596,0x2597}, + new uint[]{0x2598,0x259d}, + new uint[]{0x25a1,0x2610}, + new uint[]{0x25aa,0xffed}, + new uint[]{0x25b6,0x25b8,0x25ba}, + new uint[]{0x25bd,0x102bc,0x1f704}, + new uint[]{0x2625,0x1099e,0x132f9}, + new uint[]{0x2627,0x2ce9}, + new uint[]{0x2629,0x1f70a}, + new uint[]{0x2630,0x2cb6}, + new uint[]{0x263d,0x1f312,0x1f319}, + new uint[]{0x263e,0x1f318}, + new uint[]{0x27e6,0x301a}, + new uint[]{0x27e7,0x301b}, + new uint[]{0x299a,0x29d9}, + new uint[]{0x29d6,0x102c0}, + new uint[]{0x29df,0x1f73a}, + new uint[]{0x2a1f,0x2a3e}, + new uint[]{0x2c70,0x1041f}, + new uint[]{0x2d40,0x102b8}, + new uint[]{0x2e83,0x31df,0x4e5a}, + new uint[]{0x2e85,0x4ebb}, + new uint[]{0x2e89,0x5202}, + new uint[]{0x2e8b,0x353e}, + new uint[]{0x2e8e,0x5140,0xfa0c}, + new uint[]{0x2e8f,0x5c23}, + new uint[]{0x2e90,0x2f2a,0x5c22,0x2f875}, + new uint[]{0x2e92,0x5df3}, + new uint[]{0x2e93,0x2f33,0x5e7a}, + new uint[]{0x2e94,0x5f51}, + new uint[]{0x2e96,0x5fc4}, + new uint[]{0x2e97,0x38fa}, + new uint[]{0x2e98,0x624c}, + new uint[]{0x2e99,0x6535}, + new uint[]{0x2e9b,0x65e1}, + new uint[]{0x2e9e,0x6b7a}, + new uint[]{0x2e9f,0x6bcd}, + new uint[]{0x2ea0,0x6c11}, + new uint[]{0x2ea1,0x6c35}, + new uint[]{0x2ea2,0x6c3a}, + new uint[]{0x2ea3,0x706c}, + new uint[]{0x2ea4,0x722b,0xfa49}, + new uint[]{0x2ea6,0x4e2c}, + new uint[]{0x2ea8,0x72ad}, + new uint[]{0x2eab,0x2eb2,0x7f52}, + new uint[]{0x2ead,0x793b}, + new uint[]{0x2eaf,0x7cf9}, + new uint[]{0x2eb1,0x7f53}, + new uint[]{0x2eb9,0x8002}, + new uint[]{0x2eba,0x8080}, + new uint[]{0x2ebe,0x2ebf,0x2ec0,0x8279,0xfa5d,0xfa5e}, + new uint[]{0x2ec1,0x864e}, + new uint[]{0x2ec2,0x8864}, + new uint[]{0x2ec3,0x8980}, + new uint[]{0x2ec4,0x897f}, + new uint[]{0x2ec5,0x89c1}, + new uint[]{0x2ec8,0x8ba0}, + new uint[]{0x2ec9,0x8d1d}, + new uint[]{0x2ecb,0x8f66}, + new uint[]{0x2ecc,0x2ecd,0x8fb6,0xfa66}, + new uint[]{0x2ecf,0x2ed6,0x961d}, + new uint[]{0x2ed0,0x9485}, + new uint[]{0x2ed1,0x2fa7,0x9577}, + new uint[]{0x2ed2,0x9578}, + new uint[]{0x2ed3,0x957f}, + new uint[]{0x2ed4,0x95e8}, + new uint[]{0x2ed8,0x9752}, + new uint[]{0x2ed9,0x97e6}, + new uint[]{0x2eda,0x9875}, + new uint[]{0x2edb,0x98ce}, + new uint[]{0x2edc,0x98de}, + new uint[]{0x2edd,0x2fb7,0x98df}, + new uint[]{0x2edf,0x98e0}, + new uint[]{0x2ee0,0x9963}, + new uint[]{0x2ee2,0x9a6c}, + new uint[]{0x2ee4,0x2fc1,0x9b3c}, + new uint[]{0x2ee5,0x9c7c}, + new uint[]{0x2ee8,0x9ea6}, + new uint[]{0x2ee9,0x9ec4}, + new uint[]{0x2eeb,0x6589}, + new uint[]{0x2eec,0x9f50}, + new uint[]{0x2eed,0x6b6f}, + new uint[]{0x2eee,0x9f7f}, + new uint[]{0x2eef,0x7adc}, + new uint[]{0x2ef0,0x9f99}, + new uint[]{0x2ef2,0x4e80}, + new uint[]{0x2ef3,0x9f9f}, + new uint[]{0x2f04,0x31e0,0x4e59}, + new uint[]{0x2f05,0x31da,0x4e85}, + new uint[]{0x2f06,0x4e8c}, + new uint[]{0x2f07,0x4ea0}, + new uint[]{0x2f08,0x4eba}, + new uint[]{0x2f09,0x513f}, + new uint[]{0x2f0a,0x5165}, + new uint[]{0x2f0b,0x516b}, + new uint[]{0x2f0c,0x5182}, + new uint[]{0x2f0d,0x5196}, + new uint[]{0x2f0e,0x51ab}, + new uint[]{0x2f0f,0x51e0}, + new uint[]{0x2f10,0x51f5,0x2f81d}, + new uint[]{0x2f11,0x5200}, + new uint[]{0x2f12,0x529b,0xf98a}, + new uint[]{0x2f13,0x52f9}, + new uint[]{0x2f14,0x5315}, + new uint[]{0x2f15,0x531a}, + new uint[]{0x2f16,0x5338}, + new uint[]{0x2f17,0x3038,0x5341}, + new uint[]{0x2f18,0x535c}, + new uint[]{0x2f19,0x5369}, + new uint[]{0x2f1a,0x5382}, + new uint[]{0x2f1b,0x53b6}, + new uint[]{0x2f1c,0x53c8}, + new uint[]{0x2f1d,0x53e3}, + new uint[]{0x2f1e,0x56d7}, + new uint[]{0x2f1f,0x571f}, + new uint[]{0x2f20,0x58eb}, + new uint[]{0x2f21,0x5902}, + new uint[]{0x2f22,0x590a}, + new uint[]{0x2f23,0x5915}, + new uint[]{0x2f24,0x5927}, + new uint[]{0x2f25,0x5973,0xf981}, + new uint[]{0x2f26,0x5b50}, + new uint[]{0x2f27,0x5b80}, + new uint[]{0x2f28,0x5bf8}, + new uint[]{0x2f29,0x5c0f}, + new uint[]{0x2f2b,0x5c38}, + new uint[]{0x2f2c,0x5c6e,0xfa3c,0x2f878}, + new uint[]{0x2f2d,0x5c71}, + new uint[]{0x2f2e,0x5ddb}, + new uint[]{0x2f2f,0x5de5}, + new uint[]{0x2f30,0x5df1}, + new uint[]{0x2f31,0x5dfe}, + new uint[]{0x2f32,0x5e72}, + new uint[]{0x2f34,0x5e7f}, + new uint[]{0x2f35,0x5ef4}, + new uint[]{0x2f36,0x5efe,0x2f890}, + new uint[]{0x2f37,0x5f0b}, + new uint[]{0x2f38,0x5f13}, + new uint[]{0x2f39,0x5f50}, + new uint[]{0x2f3a,0x5f61}, + new uint[]{0x2f3b,0x5f73}, + new uint[]{0x2f3c,0x5fc3}, + new uint[]{0x2f3d,0x6208}, + new uint[]{0x2f3e,0x6236,0x6238}, + new uint[]{0x2f3f,0x624b}, + new uint[]{0x2f40,0x652f}, + new uint[]{0x2f41,0x6534}, + new uint[]{0x2f42,0x6587}, + new uint[]{0x2f43,0x6597}, + new uint[]{0x2f44,0x65a4}, + new uint[]{0x2f45,0x65b9}, + new uint[]{0x2f46,0x65e0}, + new uint[]{0x2f47,0x65e5}, + new uint[]{0x2f48,0x66f0}, + new uint[]{0x2f49,0x6708}, + new uint[]{0x2f4a,0x6728}, + new uint[]{0x2f4b,0x6b20}, + new uint[]{0x2f4c,0x6b62}, + new uint[]{0x2f4d,0x6b79,0xfa95}, + new uint[]{0x2f4e,0x6bb3}, + new uint[]{0x2f4f,0x6bcb}, + new uint[]{0x2f50,0x6bd4}, + new uint[]{0x2f51,0x6bdb}, + new uint[]{0x2f52,0x6c0f}, + new uint[]{0x2f53,0x6c14}, + new uint[]{0x2f54,0x6c34}, + new uint[]{0x2f55,0x706b}, + new uint[]{0x2f56,0x722a}, + new uint[]{0x2f57,0x7236}, + new uint[]{0x2f58,0x723b}, + new uint[]{0x2f59,0x723f}, + new uint[]{0x2f5a,0x7247}, + new uint[]{0x2f5b,0x7259}, + new uint[]{0x2f5c,0x725b}, + new uint[]{0x2f5d,0x72ac}, + new uint[]{0x2f5e,0x7384}, + new uint[]{0x2f5f,0x7389}, + new uint[]{0x2f60,0x74dc}, + new uint[]{0x2f61,0x74e6}, + new uint[]{0x2f62,0x7518}, + new uint[]{0x2f63,0x751f}, + new uint[]{0x2f64,0x7528}, + new uint[]{0x2f65,0x7530}, + new uint[]{0x2f66,0x758b}, + new uint[]{0x2f67,0x7592}, + new uint[]{0x2f68,0x7676}, + new uint[]{0x2f69,0x767d}, + new uint[]{0x2f6a,0x76ae}, + new uint[]{0x2f6b,0x76bf}, + new uint[]{0x2f6c,0x76ee}, + new uint[]{0x2f6d,0x77db}, + new uint[]{0x2f6e,0x77e2}, + new uint[]{0x2f6f,0x77f3}, + new uint[]{0x2f70,0x793a}, + new uint[]{0x2f71,0x79b8}, + new uint[]{0x2f72,0x79be}, + new uint[]{0x2f73,0x7a74}, + new uint[]{0x2f74,0x7acb,0xf9f7}, + new uint[]{0x2f75,0x7af9}, + new uint[]{0x2f76,0x7c73}, + new uint[]{0x2f77,0x7cf8}, + new uint[]{0x2f78,0x7f36}, + new uint[]{0x2f79,0x7f51}, + new uint[]{0x2f7a,0x7f8a}, + new uint[]{0x2f7b,0x7fbd,0xfa1e}, + new uint[]{0x2f7c,0x8001,0xf934}, + new uint[]{0x2f7d,0x800c}, + new uint[]{0x2f7e,0x8012}, + new uint[]{0x2f7f,0x8033}, + new uint[]{0x2f80,0x807f}, + new uint[]{0x2f81,0x8089}, + new uint[]{0x2f82,0x81e3}, + new uint[]{0x2f83,0x81ea}, + new uint[]{0x2f84,0x81f3}, + new uint[]{0x2f85,0x81fc}, + new uint[]{0x2f86,0x820c}, + new uint[]{0x2f87,0x821b}, + new uint[]{0x2f88,0x821f}, + new uint[]{0x2f89,0x826e}, + new uint[]{0x2f8a,0x8272}, + new uint[]{0x2f8b,0x8278}, + new uint[]{0x2f8c,0x864d}, + new uint[]{0x2f8d,0x866b}, + new uint[]{0x2f8e,0x8840}, + new uint[]{0x2f8f,0x884c,0xfa08}, + new uint[]{0x2f90,0x8863,0x2f9c4}, + new uint[]{0x2f91,0x897e}, + new uint[]{0x2f92,0x898b,0xfa0a}, + new uint[]{0x2f93,0x89d2}, + new uint[]{0x2f94,0x8a00}, + new uint[]{0x2f95,0x8c37}, + new uint[]{0x2f96,0x8c46}, + new uint[]{0x2f97,0x8c55,0x2f9d2}, + new uint[]{0x2f98,0x8c78}, + new uint[]{0x2f99,0x8c9d}, + new uint[]{0x2f9a,0x8d64}, + new uint[]{0x2f9b,0x8d70}, + new uint[]{0x2f9c,0x8db3}, + new uint[]{0x2f9d,0x8eab}, + new uint[]{0x2f9e,0x8eca,0xf902}, + new uint[]{0x2f9f,0x8f9b}, + new uint[]{0x2fa0,0x8fb0,0xf971}, + new uint[]{0x2fa1,0x8fb5}, + new uint[]{0x2fa2,0x9091}, + new uint[]{0x2fa3,0x9149}, + new uint[]{0x2fa4,0x91c6}, + new uint[]{0x2fa5,0x91cc,0xf9e9}, + new uint[]{0x2fa6,0x91d1,0xf90a}, + new uint[]{0x2fa8,0x9580}, + new uint[]{0x2fa9,0x961c}, + new uint[]{0x2faa,0x96b6}, + new uint[]{0x2fab,0x96b9}, + new uint[]{0x2fac,0x96e8}, + new uint[]{0x2fad,0x9751}, + new uint[]{0x2fae,0x975e}, + new uint[]{0x2faf,0x9762}, + new uint[]{0x2fb0,0x9769}, + new uint[]{0x2fb1,0x97cb}, + new uint[]{0x2fb2,0x97ed}, + new uint[]{0x2fb3,0x97f3}, + new uint[]{0x2fb4,0x9801}, + new uint[]{0x2fb5,0x98a8}, + new uint[]{0x2fb6,0x98db}, + new uint[]{0x2fb8,0x9996}, + new uint[]{0x2fb9,0x9999}, + new uint[]{0x2fba,0x99ac}, + new uint[]{0x2fbb,0x9aa8}, + new uint[]{0x2fbc,0x9ad8}, + new uint[]{0x2fbd,0x9adf}, + new uint[]{0x2fbe,0x9b25}, + new uint[]{0x2fbf,0x9b2f}, + new uint[]{0x2fc0,0x9b32}, + new uint[]{0x2fc2,0x9b5a}, + new uint[]{0x2fc3,0x9ce5}, + new uint[]{0x2fc4,0x9e75}, + new uint[]{0x2fc5,0x9e7f,0xf940}, + new uint[]{0x2fc6,0x9ea5}, + new uint[]{0x2fc7,0x9ebb,0x2fa15}, + new uint[]{0x2fc8,0x9ec3}, + new uint[]{0x2fc9,0x9ecd}, + new uint[]{0x2fca,0x9ed1,0x9ed2}, + new uint[]{0x2fcb,0x9ef9,0x2fa17}, + new uint[]{0x2fcc,0x9efd}, + new uint[]{0x2fcd,0x9f0e}, + new uint[]{0x2fce,0x9f13}, + new uint[]{0x2fcf,0x9f20}, + new uint[]{0x2fd0,0x9f3b,0x2fa1c}, + new uint[]{0x2fd1,0x9f4a}, + new uint[]{0x2fd2,0x9f52}, + new uint[]{0x2fd3,0x9f8d,0xf9c4}, + new uint[]{0x2fd4,0x9f9c,0xf907,0xf908,0xface}, + new uint[]{0x2fd5,0x9fa0}, + new uint[]{0x301c,0xff5e}, + new uint[]{0x3039,0x5344}, + new uint[]{0x303a,0x5345}, + new uint[]{0x3078,0x30d8}, + new uint[]{0x309b,0xff9e}, + new uint[]{0x309c,0xff9f}, + new uint[]{0x31d6,0x4e5b}, + new uint[]{0x349e,0x2f80c}, + new uint[]{0x34b9,0x2f813}, + new uint[]{0x34bb,0x2f9ca}, + new uint[]{0x34df,0x2f81f}, + new uint[]{0x3515,0x2f824}, + new uint[]{0x3588,0x439b}, + new uint[]{0x363d,0x39b3}, + new uint[]{0x36ee,0x2f867}, + new uint[]{0x36fc,0x2f868}, + new uint[]{0x3781,0x2f876}, + new uint[]{0x382f,0x2f883}, + new uint[]{0x3862,0x2f888}, + new uint[]{0x387c,0x2f88a}, + new uint[]{0x38c7,0x2f896}, + new uint[]{0x38e3,0x2f89b}, + new uint[]{0x391c,0x2f8a2}, + new uint[]{0x393a,0x2f8a1}, + new uint[]{0x3a2e,0x2f8c2}, + new uint[]{0x3a41,0x6409}, + new uint[]{0x3a6c,0x2f8c7}, + new uint[]{0x3ada,0x66f6}, + new uint[]{0x3ae4,0x2f8d1}, + new uint[]{0x3b08,0x2f8d0}, + new uint[]{0x3b19,0x2f8ce}, + new uint[]{0x3b35,0x80f6}, + new uint[]{0x3b3a,0x5e50}, + new uint[]{0x3b3b,0x4420}, + new uint[]{0x3b49,0x2f8de}, + new uint[]{0x3b9d,0xfad2,0x2f8e7}, + new uint[]{0x3ba3,0x69e9}, + new uint[]{0x3c18,0x2f8ee}, + new uint[]{0x3c4e,0x2f8f2}, + new uint[]{0x3d33,0x2f90a}, + new uint[]{0x3d96,0x2f916}, + new uint[]{0x3eac,0x2f92a}, + new uint[]{0x3eb8,0x2f92c,0x2f92d}, + new uint[]{0x3f1b,0x2f933}, + new uint[]{0x3ffc,0x2f93e}, + new uint[]{0x4008,0x2f93f}, + new uint[]{0x4018,0xfad3}, + new uint[]{0x4039,0x9fc3,0xfad4,0x2f949}, + new uint[]{0x403f,0x6663}, + new uint[]{0x4046,0x2f94b}, + new uint[]{0x4096,0x2f94c}, + new uint[]{0x40e3,0x2f951}, + new uint[]{0x412f,0x2f958}, + new uint[]{0x4202,0x2f960}, + new uint[]{0x4227,0x2f964}, + new uint[]{0x42a0,0x2f967}, + new uint[]{0x4301,0x2f96d}, + new uint[]{0x4334,0x2f971}, + new uint[]{0x4359,0x2f974}, + new uint[]{0x43d5,0x2f981}, + new uint[]{0x43d9,0x2f8d7}, + new uint[]{0x440b,0x2f984}, + new uint[]{0x4443,0x6726}, + new uint[]{0x446b,0x2f98e}, + new uint[]{0x452b,0x2f9a7}, + new uint[]{0x455d,0x2f9ae}, + new uint[]{0x4561,0x2f9af}, + new uint[]{0x456b,0x2f9b2}, + new uint[]{0x45d7,0x2f9bf}, + new uint[]{0x45f9,0x2f9c2}, + new uint[]{0x4635,0x2f9c8}, + new uint[]{0x46b6,0x8a1e}, + new uint[]{0x46be,0x2f9cd}, + new uint[]{0x46c7,0x2f9ce}, + new uint[]{0x4995,0x2f9ef}, + new uint[]{0x49e6,0x2f9f2}, + new uint[]{0x4a6e,0x2f9f8}, + new uint[]{0x4a76,0x2f9f9}, + new uint[]{0x4ab2,0x2f9fc}, + new uint[]{0x4b33,0x2fa03}, + new uint[]{0x4bce,0x2fa08}, + new uint[]{0x4cce,0x2fa0d}, + new uint[]{0x4ced,0x2fa0e}, + new uint[]{0x4cf8,0x2fa11}, + new uint[]{0x4d56,0x2fa16}, + new uint[]{0x4e0d,0xf967}, + new uint[]{0x4e26,0xfa70}, + new uint[]{0x4e32,0xf905}, + new uint[]{0x4e38,0x2f801}, + new uint[]{0x4e39,0xf95e}, + new uint[]{0x4e3d,0x2f800}, + new uint[]{0x4e41,0x2f802}, + new uint[]{0x4e82,0xf91b}, + new uint[]{0x4e86,0xf9ba}, + new uint[]{0x4eae,0xf977}, + new uint[]{0x4ec0,0xf9fd}, + new uint[]{0x4ecc,0x2f819}, + new uint[]{0x4ee4,0xf9a8}, + new uint[]{0x4f60,0x2f804}, + new uint[]{0x4f75,0x5002,0x2f807}, + new uint[]{0x4f80,0xfa73}, + new uint[]{0x4f86,0xf92d}, + new uint[]{0x4f8b,0xf9b5}, + new uint[]{0x4fae,0xfa30,0x2f805}, + new uint[]{0x4fbb,0x2f806}, + new uint[]{0x4fbf,0xf965}, + new uint[]{0x5024,0x503c}, + new uint[]{0x502b,0xf9d4}, + new uint[]{0x507a,0x2f808}, + new uint[]{0x5099,0x2f809}, + new uint[]{0x50cf,0x2f80b}, + new uint[]{0x50da,0xf9bb}, + new uint[]{0x50e7,0xfa31,0x2f80a}, + new uint[]{0x5145,0xfa74}, + new uint[]{0x514d,0xfa32,0x2f80e}, + new uint[]{0x5154,0x2f80f}, + new uint[]{0x5164,0x2f810}, + new uint[]{0x5167,0x2f814}, + new uint[]{0x5168,0xfa72}, + new uint[]{0x5169,0xf978}, + new uint[]{0x516d,0xf9d1}, + new uint[]{0x5177,0x2f811}, + new uint[]{0x5180,0xfa75}, + new uint[]{0x518d,0x2f815}, + new uint[]{0x5192,0x2f8d2}, + new uint[]{0x5195,0x2f8d3}, + new uint[]{0x5197,0x2f817}, + new uint[]{0x51a4,0x2f818}, + new uint[]{0x51ac,0x2f81a}, + new uint[]{0x51b5,0xfa71,0x2f81b}, + new uint[]{0x51b7,0xf92e}, + new uint[]{0x51c9,0xf979}, + new uint[]{0x51cc,0xf955}, + new uint[]{0x51dc,0xf954}, + new uint[]{0x51de,0xfa15}, + new uint[]{0x5203,0x2f81e}, + new uint[]{0x5207,0xfa00,0x2f850}, + new uint[]{0x5217,0xf99c}, + new uint[]{0x5229,0xf9dd}, + new uint[]{0x523a,0xf9ff}, + new uint[]{0x523b,0x2f820}, + new uint[]{0x5246,0x2f821}, + new uint[]{0x5272,0x2f822}, + new uint[]{0x5277,0x2f823}, + new uint[]{0x5289,0xf9c7}, + new uint[]{0x52a3,0xf99d}, + new uint[]{0x52b3,0x2f992}, + new uint[]{0x52c7,0xfa76,0x2f825}, + new uint[]{0x52c9,0xfa33,0x2f826}, + new uint[]{0x52d2,0xf952}, + new uint[]{0x52de,0xf92f}, + new uint[]{0x52e4,0xfa34,0x2f827}, + new uint[]{0x52f5,0xf97f}, + new uint[]{0x52fa,0xfa77,0x2f828}, + new uint[]{0x5305,0x2f829}, + new uint[]{0x5306,0x2f82a}, + new uint[]{0x5317,0xf963,0x2f82b}, + new uint[]{0x533f,0xf9eb}, + new uint[]{0x5349,0x2f82c}, + new uint[]{0x5351,0xfa35,0x2f82d}, + new uint[]{0x535a,0x2f82e}, + new uint[]{0x5373,0x2f82f}, + new uint[]{0x5375,0xf91c}, + new uint[]{0x537d,0x2f830}, + new uint[]{0x537f,0x2f831,0x2f832,0x2f833}, + new uint[]{0x53c3,0xf96b}, + new uint[]{0x53ca,0x2f836}, + new uint[]{0x53df,0x2f837}, + new uint[]{0x53e5,0xf906}, + new uint[]{0x53eb,0x2f839}, + new uint[]{0x53f1,0x2f83a}, + new uint[]{0x5406,0x2f83b}, + new uint[]{0x540f,0xf9de}, + new uint[]{0x541d,0xf9ed}, + new uint[]{0x5438,0x2f83d}, + new uint[]{0x5442,0xf980}, + new uint[]{0x5448,0x2f83e}, + new uint[]{0x5468,0x2f83f}, + new uint[]{0x549e,0x2f83c}, + new uint[]{0x54a2,0x2f840}, + new uint[]{0x54bd,0xf99e}, + new uint[]{0x54f6,0x2f841}, + new uint[]{0x5510,0x2f842}, + new uint[]{0x5553,0x555f,0x2f843}, + new uint[]{0x5555,0xfa79}, + new uint[]{0x5563,0x2f844}, + new uint[]{0x5584,0x2f845,0x2f846}, + new uint[]{0x5587,0xf90b}, + new uint[]{0x5599,0xfa7a,0x2f847}, + new uint[]{0x559d,0xfa36,0xfa78}, + new uint[]{0x55ab,0x2f848}, + new uint[]{0x55b3,0x2f849}, + new uint[]{0x55c0,0xfa0d}, + new uint[]{0x55c2,0x2f84a}, + new uint[]{0x55e2,0xfa7b}, + new uint[]{0x5606,0xfa37,0x2f84c}, + new uint[]{0x5651,0x2f84e}, + new uint[]{0x5668,0xfa38}, + new uint[]{0x5674,0x2f84f}, + new uint[]{0x56f9,0xf9a9}, + new uint[]{0x5716,0x2f84b}, + new uint[]{0x5717,0x2f84d}, + new uint[]{0x578b,0x2f855}, + new uint[]{0x57ce,0x2f852}, + new uint[]{0x57f4,0x2f853}, + new uint[]{0x580d,0x2f854}, + new uint[]{0x5831,0x2f857}, + new uint[]{0x5832,0x2f856}, + new uint[]{0x5840,0xfa39}, + new uint[]{0x585a,0xfa10,0xfa7c}, + new uint[]{0x585e,0xf96c}, + new uint[]{0x5861,0x586b}, + new uint[]{0x58a8,0xfa3a}, + new uint[]{0x58ab,0x58ff}, + new uint[]{0x58ac,0x2f858}, + new uint[]{0x58b3,0xfa7d}, + new uint[]{0x58d8,0xf94a}, + new uint[]{0x58df,0xf942}, + new uint[]{0x58ee,0x2f851}, + new uint[]{0x58f2,0x2f85a}, + new uint[]{0x58f7,0x2f85b}, + new uint[]{0x5906,0x2f85c}, + new uint[]{0x591a,0x2f85d}, + new uint[]{0x5922,0x2f85e}, + new uint[]{0x5944,0xfa7e}, + new uint[]{0x5948,0xf90c}, + new uint[]{0x5951,0xf909}, + new uint[]{0x5954,0xfa7f}, + new uint[]{0x5962,0x2f85f}, + new uint[]{0x59d8,0x2f865}, + new uint[]{0x59ec,0x2f862}, + new uint[]{0x5a1b,0x2f863}, + new uint[]{0x5a27,0x2f864}, + new uint[]{0x5a62,0xfa80}, + new uint[]{0x5a66,0x2f866}, + new uint[]{0x5aaf,0x5b00}, + new uint[]{0x5ab5,0x2f986}, + new uint[]{0x5b08,0x2f869}, + new uint[]{0x5b28,0xfa81}, + new uint[]{0x5b3e,0x2f86a,0x2f86b}, + new uint[]{0x5b85,0xfa04}, + new uint[]{0x5bc3,0x2f86d}, + new uint[]{0x5bd8,0x2f86e}, + new uint[]{0x5be7,0xf95f,0xf9aa,0x2f86f}, + new uint[]{0x5bee,0xf9bc}, + new uint[]{0x5bf3,0x2f870}, + new uint[]{0x5bff,0x2f872}, + new uint[]{0x5c06,0x2f873}, + new uint[]{0x5c3f,0xf9bd}, + new uint[]{0x5c60,0x2f877}, + new uint[]{0x5c62,0xf94b}, + new uint[]{0x5c64,0xfa3b}, + new uint[]{0x5c65,0xf9df}, + new uint[]{0x5c8d,0x2f87a}, + new uint[]{0x5cc0,0x2f879}, + new uint[]{0x5d19,0xf9d5}, + new uint[]{0x5d43,0x2f87c}, + new uint[]{0x5d50,0xf921}, + new uint[]{0x5d6b,0x2f87f}, + new uint[]{0x5d6e,0x2f87e}, + new uint[]{0x5d7c,0x2f880}, + new uint[]{0x5db2,0x2f9f4}, + new uint[]{0x5dba,0xf9ab}, + new uint[]{0x5de1,0x2f881}, + new uint[]{0x5de2,0x2f882}, + new uint[]{0x5dfd,0x2f884}, + new uint[]{0x5e21,0x5e32}, + new uint[]{0x5e28,0x2f885}, + new uint[]{0x5e3d,0x2f886}, + new uint[]{0x5e69,0x2f887}, + new uint[]{0x5e74,0xf98e}, + new uint[]{0x5ea6,0xfa01}, + new uint[]{0x5eb0,0x2f88b}, + new uint[]{0x5eb3,0x2f88c}, + new uint[]{0x5eb6,0x2f88d}, + new uint[]{0x5ec9,0xf9a2}, + new uint[]{0x5eca,0xf928,0x2f88e}, + new uint[]{0x5ed2,0xfa82}, + new uint[]{0x5ed3,0xfa0b}, + new uint[]{0x5ed9,0xfa83}, + new uint[]{0x5eec,0xf982}, + new uint[]{0x5f04,0xf943}, + new uint[]{0x5f22,0x2f894,0x2f895}, + new uint[]{0x5f53,0x2f874}, + new uint[]{0x5f62,0x2f899}, + new uint[]{0x5f69,0xfa84}, + new uint[]{0x5f6b,0x2f89a}, + new uint[]{0x5f8b,0xf9d8}, + new uint[]{0x5f9a,0x2f89c}, + new uint[]{0x5fa9,0xf966}, + new uint[]{0x5fad,0xfa85}, + new uint[]{0x5fcd,0x2f89d}, + new uint[]{0x5fd7,0x2f89e}, + new uint[]{0x5ff5,0xf9a3}, + new uint[]{0x5ff9,0x2f89f}, + new uint[]{0x6012,0xf960}, + new uint[]{0x601c,0xf9ac}, + new uint[]{0x6075,0xfa6b}, + new uint[]{0x6081,0x2f8a0}, + new uint[]{0x6094,0xfa3d,0x2f8a3}, + new uint[]{0x60c7,0x2f8a5}, + new uint[]{0x60d8,0xfa86}, + new uint[]{0x60e1,0xf9b9}, + new uint[]{0x6108,0xfa88}, + new uint[]{0x6144,0xf9d9}, + new uint[]{0x6148,0x2f8a6}, + new uint[]{0x614c,0x2f8a7,0x2f8a9}, + new uint[]{0x614e,0xfa87,0x2f8a8}, + new uint[]{0x6160,0xfa8a}, + new uint[]{0x6168,0xfa3e}, + new uint[]{0x617a,0x2f8aa}, + new uint[]{0x618e,0xfa3f,0xfa89,0x2f8ab}, + new uint[]{0x6190,0xf98f}, + new uint[]{0x61a4,0x2f8ad}, + new uint[]{0x61af,0x2f8ae}, + new uint[]{0x61b2,0x2f8ac}, + new uint[]{0x61de,0x2f8af}, + new uint[]{0x61f2,0xfa40,0xfa8b,0x2f8b0}, + new uint[]{0x61f6,0xf90d,0x2f8b1}, + new uint[]{0x6200,0xf990}, + new uint[]{0x6210,0x2f8b2}, + new uint[]{0x621b,0x2f8b3}, + new uint[]{0x622e,0xf9d2}, + new uint[]{0x6234,0xfa8c}, + new uint[]{0x625d,0x2f8b4}, + new uint[]{0x62b1,0x2f8b5}, + new uint[]{0x62c9,0xf925}, + new uint[]{0x62cf,0xf95b}, + new uint[]{0x62d3,0xfa02}, + new uint[]{0x62d4,0x2f8b6}, + new uint[]{0x62fc,0x2f8ba}, + new uint[]{0x62fe,0xf973}, + new uint[]{0x633d,0x2f8b9}, + new uint[]{0x6350,0x2f8b7}, + new uint[]{0x6368,0x2f8bb}, + new uint[]{0x637b,0xf9a4}, + new uint[]{0x6383,0x2f8bc}, + new uint[]{0x63a0,0xf975}, + new uint[]{0x63a9,0x2f8c1}, + new uint[]{0x63c4,0xfa8d}, + new uint[]{0x63c5,0x2f8c0}, + new uint[]{0x63e4,0x2f8bd}, + new uint[]{0x641c,0xfa8e}, + new uint[]{0x6422,0x2f8bf}, + new uint[]{0x6452,0xfa8f}, + new uint[]{0x6469,0x2f8c3}, + new uint[]{0x6477,0x2f8c6}, + new uint[]{0x647e,0x2f8c4}, + new uint[]{0x649a,0xf991}, + new uint[]{0x649d,0x2f8c5}, + new uint[]{0x64c4,0xf930}, + new uint[]{0x654f,0xfa41,0x2f8c8}, + new uint[]{0x6556,0xfa90}, + new uint[]{0x656c,0x2f8c9}, + new uint[]{0x6578,0xf969}, + new uint[]{0x6599,0xf9be}, + new uint[]{0x65c5,0xf983}, + new uint[]{0x65e2,0xfa42}, + new uint[]{0x65e3,0x2f8cb}, + new uint[]{0x6613,0xf9e0}, + new uint[]{0x6649,0x2f8cd}, + new uint[]{0x665a,0x6669}, + new uint[]{0x6674,0xfa12,0xfa91}, + new uint[]{0x6688,0xf9c5}, + new uint[]{0x6691,0xfa43,0x2f8cf}, + new uint[]{0x669c,0x2f8d5}, + new uint[]{0x66b4,0xfa06}, + new uint[]{0x66c6,0xf98b}, + new uint[]{0x66f4,0xf901}, + new uint[]{0x66f8,0x2f8cc}, + new uint[]{0x6700,0x2f8d4}, + new uint[]{0x670c,0x80a6}, + new uint[]{0x670f,0x80d0}, + new uint[]{0x6710,0x80ca}, + new uint[]{0x6713,0x8101}, + new uint[]{0x6717,0xf929,0xfa92,0x2f8d8}, + new uint[]{0x6718,0x8127}, + new uint[]{0x671b,0xfa93,0x2f8d9}, + new uint[]{0x6721,0x2f8da}, + new uint[]{0x6723,0x81a7}, + new uint[]{0x674e,0xf9e1}, + new uint[]{0x6753,0x2f8dc}, + new uint[]{0x6756,0xfa94}, + new uint[]{0x675e,0x2f8db}, + new uint[]{0x676e,0x67ff}, + new uint[]{0x677b,0xf9c8}, + new uint[]{0x6785,0x2f8e0}, + new uint[]{0x6797,0xf9f4}, + new uint[]{0x67f3,0xf9c9}, + new uint[]{0x67fa,0x2f8df}, + new uint[]{0x6817,0xf9da}, + new uint[]{0x681f,0x2f8e5}, + new uint[]{0x6852,0x2f8e1}, + new uint[]{0x6881,0xf97a}, + new uint[]{0x6885,0xfa44,0x2f8e2}, + new uint[]{0x688e,0x2f8e4}, + new uint[]{0x68a8,0xf9e2}, + new uint[]{0x6914,0x2f8e6}, + new uint[]{0x6942,0x2f8e8}, + new uint[]{0x699d,0x6a27}, + new uint[]{0x69a3,0x2f8e9}, + new uint[]{0x69ea,0x2f8ea}, + new uint[]{0x6a02,0xf914,0xf95c,0xf9bf}, + new uint[]{0x6a13,0xf94c}, + new uint[]{0x6aa8,0x2f8eb}, + new uint[]{0x6ad3,0xf931}, + new uint[]{0x6adb,0x2f8ed}, + new uint[]{0x6b04,0xf91d}, + new uint[]{0x6b21,0x2f8ef}, + new uint[]{0x6b54,0x2f8f1}, + new uint[]{0x6b72,0x2f8f3}, + new uint[]{0x6b77,0xf98c}, + new uint[]{0x6b9f,0x2f8f4}, + new uint[]{0x6bae,0xf9a5}, + new uint[]{0x6bba,0xf970,0xfa96,0x2f8f5}, + new uint[]{0x6bbb,0x2f8f6}, + new uint[]{0x6c4e,0x2f8fa}, + new uint[]{0x6c67,0x2f8fe}, + new uint[]{0x6c88,0xf972}, + new uint[]{0x6cbf,0x2f8fc}, + new uint[]{0x6ccc,0xf968}, + new uint[]{0x6ccd,0x2f8fd}, + new uint[]{0x6ce5,0xf9e3}, + new uint[]{0x6d16,0x2f8ff}, + new uint[]{0x6d1b,0xf915}, + new uint[]{0x6d1e,0xfa05}, + new uint[]{0x6d34,0x2f907}, + new uint[]{0x6d3e,0x2f900}, + new uint[]{0x6d41,0xf9ca,0xfa97,0x2f902}, + new uint[]{0x6d69,0x2f903}, + new uint[]{0x6d6a,0xf92a}, + new uint[]{0x6d77,0xfa45,0x2f901}, + new uint[]{0x6d78,0x2f904}, + new uint[]{0x6d85,0x2f905}, + new uint[]{0x6dcb,0xf9f5}, + new uint[]{0x6dda,0xf94d}, + new uint[]{0x6dea,0xf9d6}, + new uint[]{0x6df9,0x2f90e}, + new uint[]{0x6e1a,0xfa46}, + new uint[]{0x6e2f,0x2f908}, + new uint[]{0x6e6e,0x2f909}, + new uint[]{0x6e88,0x6f59}, + new uint[]{0x6e9c,0xf9cb}, + new uint[]{0x6eba,0xf9ec}, + new uint[]{0x6ec7,0x2f90c}, + new uint[]{0x6ecb,0xfa99,0x2f90b}, + new uint[]{0x6ed1,0xf904}, + new uint[]{0x6edb,0xfa98}, + new uint[]{0x6f0f,0xf94e}, + new uint[]{0x6f22,0xfa47,0xfa9a}, + new uint[]{0x6f23,0xf992}, + new uint[]{0x6f6e,0x2f90f}, + new uint[]{0x6fc6,0x2f912}, + new uint[]{0x6feb,0xf922}, + new uint[]{0x6ffe,0xf984}, + new uint[]{0x701b,0x2f915}, + new uint[]{0x701e,0xfa9b,0x2f914}, + new uint[]{0x7039,0x2f913}, + new uint[]{0x704a,0x2f917}, + new uint[]{0x7070,0x2f835}, + new uint[]{0x7077,0x2f919}, + new uint[]{0x707d,0x2f918}, + new uint[]{0x7099,0xf9fb}, + new uint[]{0x70ad,0x2f91a}, + new uint[]{0x70c8,0xf99f}, + new uint[]{0x70d9,0xf916}, + new uint[]{0x7145,0x2f91c}, + new uint[]{0x7149,0xf993}, + new uint[]{0x716e,0xfa48,0xfa9c}, + new uint[]{0x719c,0x2f91e}, + new uint[]{0x71ce,0xf9c0}, + new uint[]{0x71d0,0xf9ee}, + new uint[]{0x7210,0xf932}, + new uint[]{0x721b,0xf91e}, + new uint[]{0x7228,0x2f920}, + new uint[]{0x7235,0xfa9e,0x2f921}, + new uint[]{0x7250,0x2f922}, + new uint[]{0x7262,0xf946}, + new uint[]{0x7280,0x2f924}, + new uint[]{0x7295,0x2f925}, + new uint[]{0x72af,0xfa9f}, + new uint[]{0x72c0,0xf9fa}, + new uint[]{0x72fc,0xf92b}, + new uint[]{0x732a,0xfa16,0xfaa0}, + new uint[]{0x7375,0xf9a7}, + new uint[]{0x737a,0x2f928}, + new uint[]{0x7387,0xf961,0xf9db}, + new uint[]{0x738b,0x2f929}, + new uint[]{0x73a5,0x2f92b}, + new uint[]{0x73b2,0xf9ad}, + new uint[]{0x73de,0xf917}, + new uint[]{0x7406,0xf9e4}, + new uint[]{0x7409,0xf9cc}, + new uint[]{0x7422,0xfa4a}, + new uint[]{0x7447,0x2f92e}, + new uint[]{0x745c,0x2f92f}, + new uint[]{0x7469,0xf9ae}, + new uint[]{0x7471,0xfaa1,0x2f930}, + new uint[]{0x7485,0x2f931}, + new uint[]{0x7489,0xf994}, + new uint[]{0x7498,0xf9ef}, + new uint[]{0x74ca,0x2f932}, + new uint[]{0x7506,0xfaa2}, + new uint[]{0x7524,0x2f934}, + new uint[]{0x753b,0xfaa3}, + new uint[]{0x753e,0x2f936}, + new uint[]{0x7559,0xf9cd}, + new uint[]{0x7565,0xf976}, + new uint[]{0x7570,0xf962,0x2f938}, + new uint[]{0x75e2,0xf9e5}, + new uint[]{0x7610,0x2f93a}, + new uint[]{0x761d,0xfaa4}, + new uint[]{0x761f,0xfaa5}, + new uint[]{0x7642,0xf9c1}, + new uint[]{0x7669,0xf90e}, + new uint[]{0x76ca,0xfa17,0xfaa6}, + new uint[]{0x76db,0xfaa7}, + new uint[]{0x76e7,0xf933}, + new uint[]{0x76f4,0xfaa8,0x2f940}, + new uint[]{0x7701,0xf96d}, + new uint[]{0x771e,0x2f945}, + new uint[]{0x771f,0x2f946,0x2f947}, + new uint[]{0x7740,0xfaaa}, + new uint[]{0x774a,0xfaa9,0x2f948}, + new uint[]{0x778b,0x2f94a}, + new uint[]{0x77a7,0xfa9d}, + new uint[]{0x7814,0x784f}, + new uint[]{0x784e,0x2f94e}, + new uint[]{0x786b,0xf9ce}, + new uint[]{0x788c,0xf93b,0x2f94f}, + new uint[]{0x7891,0xfa4b}, + new uint[]{0x78ca,0xf947}, + new uint[]{0x78cc,0xfaab,0x2f950}, + new uint[]{0x78fb,0xf964}, + new uint[]{0x792a,0xf985}, + new uint[]{0x793c,0xfa18}, + new uint[]{0x793e,0xfa4c}, + new uint[]{0x7948,0xfa4e}, + new uint[]{0x7949,0xfa4d}, + new uint[]{0x7950,0xfa4f}, + new uint[]{0x7956,0xfa50,0x2f953}, + new uint[]{0x795d,0xfa51}, + new uint[]{0x795e,0xfa19}, + new uint[]{0x7965,0xfa1a}, + new uint[]{0x797f,0xf93c}, + new uint[]{0x798d,0xfa52}, + new uint[]{0x798e,0xfa53}, + new uint[]{0x798f,0xfa1b,0x2f956}, + new uint[]{0x79ae,0xf9b6}, + new uint[]{0x79ca,0xf995}, + new uint[]{0x79eb,0x2f957}, + new uint[]{0x7a1c,0xf956}, + new uint[]{0x7a40,0xfa54,0x2f959}, + new uint[]{0x7a4a,0x2f95a}, + new uint[]{0x7a4f,0x2f95b}, + new uint[]{0x7a81,0xfa55}, + new uint[]{0x7ab1,0xfaac}, + new uint[]{0x7aee,0x2f95f}, + new uint[]{0x7b20,0xf9f8}, + new uint[]{0x7bc0,0xfa56,0xfaad}, + new uint[]{0x7bc6,0x2f962}, + new uint[]{0x7bc9,0x2f963}, + new uint[]{0x7c3e,0xf9a6}, + new uint[]{0x7c60,0xf944}, + new uint[]{0x7c7b,0xfaae}, + new uint[]{0x7c92,0xf9f9}, + new uint[]{0x7cbe,0xfa1d}, + new uint[]{0x7cd2,0x2f966}, + new uint[]{0x7cd6,0xfa03}, + new uint[]{0x7ce3,0x2f969}, + new uint[]{0x7ce7,0xf97b}, + new uint[]{0x7ce8,0x2f968}, + new uint[]{0x7d00,0x2f96a}, + new uint[]{0x7d10,0xf9cf}, + new uint[]{0x7d22,0xf96a}, + new uint[]{0x7d2f,0xf94f}, + new uint[]{0x7d55,0x7d76}, + new uint[]{0x7d5b,0xfaaf}, + new uint[]{0x7d63,0x2f96c}, + new uint[]{0x7da0,0xf93d}, + new uint[]{0x7dbe,0xf957}, + new uint[]{0x7dc7,0x2f96e}, + new uint[]{0x7df4,0xf996,0xfa57,0xfab0}, + new uint[]{0x7e02,0x2f96f}, + new uint[]{0x7e09,0xfa58}, + new uint[]{0x7e37,0xf950}, + new uint[]{0x7e41,0xfa59}, + new uint[]{0x7e45,0x2f970}, + new uint[]{0x7f3e,0xfab1}, + new uint[]{0x7f72,0xfa5a}, + new uint[]{0x7f79,0xf9e6}, + new uint[]{0x7f7a,0x2f976}, + new uint[]{0x7f85,0xf90f}, + new uint[]{0x7f95,0x2f978}, + new uint[]{0x7f9a,0xf9af}, + new uint[]{0x7ffa,0x2f979}, + new uint[]{0x8005,0xfa5b,0xfab2,0x2f97a}, + new uint[]{0x8046,0xf9b0}, + new uint[]{0x8060,0x2f97d}, + new uint[]{0x806f,0xf997}, + new uint[]{0x8070,0x2f97f}, + new uint[]{0x807e,0xf945}, + new uint[]{0x808b,0xf953}, + new uint[]{0x80ad,0x2f8d6}, + new uint[]{0x80b2,0x2f982}, + new uint[]{0x80fc,0x8141}, + new uint[]{0x8103,0x2f983}, + new uint[]{0x813e,0x2f985}, + new uint[]{0x81d8,0xf926}, + new uint[]{0x81e8,0xf9f6}, + new uint[]{0x81ed,0xfa5c}, + new uint[]{0x8201,0x2f893,0x2f98b}, + new uint[]{0x8204,0x2f98c}, + new uint[]{0x8218,0xfa6d}, + new uint[]{0x826f,0xf97c}, + new uint[]{0x828b,0x2f990}, + new uint[]{0x8291,0x2f98f}, + new uint[]{0x829d,0x2f991}, + new uint[]{0x82b1,0x2f993}, + new uint[]{0x82b3,0x2f994}, + new uint[]{0x82bd,0x2f995}, + new uint[]{0x82e5,0xf974,0x2f998}, + new uint[]{0x82e6,0x2f996}, + new uint[]{0x831d,0x2f999}, + new uint[]{0x8323,0x2f99c}, + new uint[]{0x8336,0xf9fe}, + new uint[]{0x8352,0xfab3}, + new uint[]{0x8353,0x2f9a0}, + new uint[]{0x8363,0x2f99a}, + new uint[]{0x83ad,0x2f99b}, + new uint[]{0x83bd,0x2f99d}, + new uint[]{0x83c9,0xf93e}, + new uint[]{0x83ca,0x2f9a1}, + new uint[]{0x83cc,0x2f9a2}, + new uint[]{0x83dc,0x2f9a3}, + new uint[]{0x83e7,0x2f99e}, + new uint[]{0x83ef,0xfab4}, + new uint[]{0x83f1,0xf958}, + new uint[]{0x843d,0xf918}, + new uint[]{0x8449,0xf96e}, + new uint[]{0x8457,0xfa5f,0x2f99f}, + new uint[]{0x848d,0x853f}, + new uint[]{0x84ee,0xf999}, + new uint[]{0x84f1,0x2f9a8}, + new uint[]{0x84f3,0x2f9a9}, + new uint[]{0x84fc,0xf9c2}, + new uint[]{0x8516,0x2f9aa}, + new uint[]{0x8564,0x2f9ac}, + new uint[]{0x85cd,0xf923}, + new uint[]{0x85fa,0xf9f0}, + new uint[]{0x8606,0xf935}, + new uint[]{0x8612,0xfa20}, + new uint[]{0x862d,0xf91f}, + new uint[]{0x8637,0x8641}, + new uint[]{0x863f,0xf910}, + new uint[]{0x8650,0x2f9b3}, + new uint[]{0x865c,0xf936,0x2f9b4}, + new uint[]{0x8667,0x2f9b5}, + new uint[]{0x8669,0x2f9b6}, + new uint[]{0x8688,0x2f9b8}, + new uint[]{0x86a9,0x2f9b7}, + new uint[]{0x86e2,0x2f9ba}, + new uint[]{0x870e,0x2f9b9}, + new uint[]{0x8728,0x2f9bc}, + new uint[]{0x876b,0x2f9bd}, + new uint[]{0x8779,0xfab5,0x2f9bb}, + new uint[]{0x8786,0x2f9be}, + new uint[]{0x87ba,0xf911}, + new uint[]{0x87e1,0x2f9c0}, + new uint[]{0x8801,0x2f9c1}, + new uint[]{0x881f,0xf927}, + new uint[]{0x8860,0x2f9c3}, + new uint[]{0x88c2,0xf9a0}, + new uint[]{0x88cf,0xf9e7}, + new uint[]{0x88d7,0x2f9c6}, + new uint[]{0x88de,0x2f9c7}, + new uint[]{0x88e1,0xf9e8}, + new uint[]{0x88f8,0xf912}, + new uint[]{0x88fa,0x2f9c9}, + new uint[]{0x8910,0xfa60}, + new uint[]{0x8941,0xfab6}, + new uint[]{0x8964,0xf924}, + new uint[]{0x8986,0xfab7}, + new uint[]{0x8996,0xfa61,0xfab8}, + new uint[]{0x8a2e,0x8a7d}, + new uint[]{0x8aa0,0x2f9cf}, + new uint[]{0x8aaa,0xf96f,0xf9a1}, + new uint[]{0x8abf,0xfab9}, + new uint[]{0x8acb,0xfabb}, + new uint[]{0x8ad2,0xf97d}, + new uint[]{0x8ad6,0xf941}, + new uint[]{0x8aed,0xfabe,0x2f9d0}, + new uint[]{0x8af8,0xfa22,0xfaba}, + new uint[]{0x8afe,0xf95d,0xfabd}, + new uint[]{0x8b01,0xfa62,0xfabc}, + new uint[]{0x8b39,0xfa63,0xfabf}, + new uint[]{0x8b58,0xf9fc}, + new uint[]{0x8b80,0xf95a}, + new uint[]{0x8b86,0x8b8f}, + new uint[]{0x8b8a,0xfac0,0x2f9d1}, + new uint[]{0x8c48,0xf900}, + new uint[]{0x8c5c,0x8c63}, + new uint[]{0x8cab,0x2f9d4}, + new uint[]{0x8cc1,0x2f9d5}, + new uint[]{0x8cc2,0xf948}, + new uint[]{0x8cc8,0xf903}, + new uint[]{0x8cd3,0xfa64}, + new uint[]{0x8d08,0xfa65,0xfac1}, + new uint[]{0x8d1b,0x2f9d6}, + new uint[]{0x8d77,0x2f9d7}, + new uint[]{0x8d7f,0x8d86}, + new uint[]{0x8dbc,0x2f9db}, + new uint[]{0x8dcb,0x2f9da}, + new uint[]{0x8de5,0x8dfa}, + new uint[]{0x8def,0xf937}, + new uint[]{0x8df0,0x2f9dc}, + new uint[]{0x8e97,0x8e9b}, + new uint[]{0x8ed4,0x2f9de}, + new uint[]{0x8eff,0x8f27}, + new uint[]{0x8f26,0xf998}, + new uint[]{0x8f2a,0xf9d7}, + new uint[]{0x8f38,0xfac2,0x2f9df}, + new uint[]{0x8f3b,0xfa07}, + new uint[]{0x8f62,0xf98d}, + new uint[]{0x8f9e,0x2f98d}, + new uint[]{0x9023,0xf99a}, + new uint[]{0x9038,0xfa25,0xfa67}, + new uint[]{0x9072,0xfac3}, + new uint[]{0x907c,0xf9c3}, + new uint[]{0x908f,0xf913}, + new uint[]{0x9094,0x2f9e2}, + new uint[]{0x90ce,0x90de,0xf92c,0xfa2e}, + new uint[]{0x90f1,0x2f9e3}, + new uint[]{0x90fd,0xfa26}, + new uint[]{0x9111,0x2f9e4}, + new uint[]{0x911b,0x2f9e6}, + new uint[]{0x916a,0xf919}, + new uint[]{0x9199,0xfac4}, + new uint[]{0x91b4,0xf9b7}, + new uint[]{0x91cf,0xf97e}, + new uint[]{0x9234,0xf9b1}, + new uint[]{0x9238,0x2f9e7}, + new uint[]{0x9276,0xfac5}, + new uint[]{0x927c,0x2f9ea}, + new uint[]{0x92d7,0x2f9e8}, + new uint[]{0x92d8,0x2f9e9}, + new uint[]{0x9304,0xf93f}, + new uint[]{0x934a,0xf99b}, + new uint[]{0x93ad,0x93ae}, + new uint[]{0x93f9,0x2f9eb}, + new uint[]{0x9415,0x2f9ec}, + new uint[]{0x958b,0x2f9ee}, + new uint[]{0x95ad,0xf986}, + new uint[]{0x95b7,0x2f9f0}, + new uint[]{0x962e,0xf9c6}, + new uint[]{0x964b,0xf951}, + new uint[]{0x964d,0xfa09}, + new uint[]{0x9675,0xf959}, + new uint[]{0x9678,0xf9d3}, + new uint[]{0x967c,0xfac6}, + new uint[]{0x9686,0xf9dc}, + new uint[]{0x96a3,0xf9f1}, + new uint[]{0x96b7,0x96b8,0xf9b8,0xfa2f}, + new uint[]{0x96c3,0x2f9f3}, + new uint[]{0x96e2,0xf9ea}, + new uint[]{0x96e3,0xfa68,0xfac7}, + new uint[]{0x96f6,0xf9b2}, + new uint[]{0x96f7,0xf949}, + new uint[]{0x9723,0x2f9f5}, + new uint[]{0x9732,0xf938}, + new uint[]{0x9748,0xf9b3}, + new uint[]{0x9756,0xfa1c,0xfac8}, + new uint[]{0x97db,0xfac9}, + new uint[]{0x97e0,0x2f9fa}, + new uint[]{0x97ff,0xfa69,0xfaca}, + new uint[]{0x980b,0xfacb,0x2f9fe,0x2f9ff}, + new uint[]{0x9818,0xf9b4}, + new uint[]{0x9829,0x2fa00}, + new uint[]{0x983b,0xfa6a,0xfacc}, + new uint[]{0x985e,0xf9d0}, + new uint[]{0x98e2,0x2fa02}, + new uint[]{0x98ef,0xfa2a}, + new uint[]{0x98fc,0xfa2b}, + new uint[]{0x9928,0xfa2c}, + new uint[]{0x9929,0x2fa04}, + new uint[]{0x99a7,0x2fa05}, + new uint[]{0x99c2,0x2fa06}, + new uint[]{0x99f1,0xf91a}, + new uint[]{0x99fe,0x2fa07}, + new uint[]{0x9a6a,0xf987}, + new uint[]{0x9b12,0xfacd,0x2fa0a}, + new uint[]{0x9b6f,0xf939}, + new uint[]{0x9c40,0x2fa0b}, + new uint[]{0x9c57,0xf9f2}, + new uint[]{0x9cfd,0x2fa0c}, + new uint[]{0x9d67,0x2fa0f}, + new uint[]{0x9db4,0xfa2d}, + new uint[]{0x9dfa,0xf93a}, + new uint[]{0x9e1e,0xf920}, + new uint[]{0x9e42,0x9e43}, + new uint[]{0x9e97,0xf988}, + new uint[]{0x9e9f,0xf9f3}, + new uint[]{0x9ece,0xf989}, + new uint[]{0x9efe,0x2fa18}, + new uint[]{0x9f05,0x2fa19}, + new uint[]{0x9f0f,0x2fa1a}, + new uint[]{0x9f16,0x2fa1b}, + new uint[]{0x9f43,0xfad8}, + new uint[]{0x9f8e,0xfad9}, + new uint[]{0xa04a,0xa49e}, + new uint[]{0xa050,0xa4ac}, + new uint[]{0xa0c0,0xa49c}, + new uint[]{0xa132,0xa4a8}, + new uint[]{0xa259,0xa4bf}, + new uint[]{0xa2b1,0xa4be}, + new uint[]{0xa2cd,0xa494}, + new uint[]{0xa3ab,0xa4c0}, + new uint[]{0xa3b5,0xa4c2}, + new uint[]{0xa3bf,0xa4ba}, + new uint[]{0xa3c2,0xa4b0}, + new uint[]{0xa458,0xa4a7}, + new uint[]{0xa4e4,0xa79e}, + new uint[]{0xa64c,0xa7b6}, + new uint[]{0xa727,0xa795}, + new uint[]{0xa779,0xa77a}, + new uint[]{0xa79a,0x10412}, + new uint[]{0xa79b,0x1043a}, + new uint[]{0xa8fb,0x111dc}, + new uint[]{0xa8fc,0x111db}, + new uint[]{0xa9c6,0xa9d0}, + new uint[]{0xaa01,0xaa53}, + new uint[]{0xaa23,0xaa56}, + new uint[]{0xfa6c,0x242ee}, + new uint[]{0xfacf,0x2284a}, + new uint[]{0xfad0,0x22844}, + new uint[]{0xfad1,0x233d5}, + new uint[]{0xfad5,0x25249}, + new uint[]{0xfad6,0x25cd0}, + new uint[]{0xfad7,0x27ed3}, + new uint[]{0xfb1d,0xfb39}, + new uint[]{0xfb2a,0xfb2b,0xfb49}, + new uint[]{0xfb2c,0xfb2d}, + new uint[]{0xfb2e,0xfb2f,0xfb30}, + new uint[]{0xfe3f,0xff3e}, + new uint[]{0x10382,0x103d1}, + new uint[]{0x10393,0x103d3}, + new uint[]{0x1039a,0x12038}, + new uint[]{0x10486,0x104a0}, + new uint[]{0x11582,0x115d8,0x115d9}, + new uint[]{0x11583,0x115da}, + new uint[]{0x11584,0x115db}, + new uint[]{0x20122,0x2f803}, + new uint[]{0x2051c,0x2f812}, + new uint[]{0x20525,0x2f91b}, + new uint[]{0x2054b,0x2f816}, + new uint[]{0x2063a,0x2f80d}, + new uint[]{0x20804,0x2f9d9}, + new uint[]{0x208de,0x2f9dd}, + new uint[]{0x20a2c,0x2f834}, + new uint[]{0x20b63,0x2f838}, + new uint[]{0x214e4,0x2f859}, + new uint[]{0x216a8,0x2f860}, + new uint[]{0x216ea,0x2f861}, + new uint[]{0x219c8,0x2f86c}, + new uint[]{0x21b18,0x2f871}, + new uint[]{0x21d0b,0x2f8f8}, + new uint[]{0x21de4,0x2f87b}, + new uint[]{0x21de6,0x2f87d}, + new uint[]{0x22183,0x2f889}, + new uint[]{0x2219f,0x2f939}, + new uint[]{0x22331,0x2f891,0x2f892}, + new uint[]{0x226d4,0x2f8a4}, + new uint[]{0x22b0c,0x2f8b8}, + new uint[]{0x22bf1,0x2f8be}, + new uint[]{0x2300a,0x2f8ca}, + new uint[]{0x232b8,0x2f897}, + new uint[]{0x2335f,0x2f980}, + new uint[]{0x23393,0x2f989}, + new uint[]{0x2339c,0x2f98a}, + new uint[]{0x233c3,0x2f8dd}, + new uint[]{0x2346d,0x2f8e3}, + new uint[]{0x236a3,0x2f8ec}, + new uint[]{0x238a7,0x2f8f0}, + new uint[]{0x23a8d,0x2f8f7}, + new uint[]{0x23afa,0x2f8f9}, + new uint[]{0x23cbc,0x2f8fb}, + new uint[]{0x23d1e,0x2f906}, + new uint[]{0x23ed1,0x2f90d}, + new uint[]{0x23f5e,0x2f910}, + new uint[]{0x23f8e,0x2f911}, + new uint[]{0x24263,0x2f91d}, + new uint[]{0x243ab,0x2f91f}, + new uint[]{0x24608,0x2f923}, + new uint[]{0x24735,0x2f926}, + new uint[]{0x24814,0x2f927}, + new uint[]{0x24c36,0x2f935}, + new uint[]{0x24c92,0x2f937}, + new uint[]{0x24fa1,0x2f93b}, + new uint[]{0x24fb8,0x2f93c}, + new uint[]{0x25044,0x2f93d}, + new uint[]{0x250f2,0x2f942}, + new uint[]{0x250f3,0x2f941}, + new uint[]{0x25119,0x2f943}, + new uint[]{0x25133,0x2f944}, + new uint[]{0x2541d,0x2f94d}, + new uint[]{0x25626,0x2f952}, + new uint[]{0x2569a,0x2f954}, + new uint[]{0x256c5,0x2f955}, + new uint[]{0x2597c,0x2f95c}, + new uint[]{0x25aa7,0x2f95d,0x2f95e}, + new uint[]{0x25bab,0x2f961}, + new uint[]{0x25c80,0x2f965}, + new uint[]{0x25f86,0x2f96b}, + new uint[]{0x261da,0x2f898}, + new uint[]{0x26228,0x2f972}, + new uint[]{0x26247,0x2f973}, + new uint[]{0x262d9,0x2f975}, + new uint[]{0x2633e,0x2f977}, + new uint[]{0x264da,0x2f97b}, + new uint[]{0x26523,0x2f97c}, + new uint[]{0x265a8,0x2f97e}, + new uint[]{0x267a7,0x2f987}, + new uint[]{0x267b5,0x2f988}, + new uint[]{0x26b3c,0x2f997}, + new uint[]{0x26c36,0x2f9a4}, + new uint[]{0x26cd5,0x2f9a6}, + new uint[]{0x26d6b,0x2f9a5}, + new uint[]{0x26f2c,0x2f9ad}, + new uint[]{0x26fb1,0x2f9b0}, + new uint[]{0x270d2,0x2f9b1}, + new uint[]{0x273ca,0x2f9ab}, + new uint[]{0x27667,0x2f9c5}, + new uint[]{0x278ae,0x2f9cb}, + new uint[]{0x27966,0x2f9cc}, + new uint[]{0x27ca8,0x2f9d3}, + new uint[]{0x27f2f,0x2f9d8}, + new uint[]{0x285d2,0x2f9e0}, + new uint[]{0x285ed,0x2f9e1}, + new uint[]{0x2872e,0x2f9e5}, + new uint[]{0x28bfa,0x2f9ed}, + new uint[]{0x28d77,0x2f9f1}, + new uint[]{0x29145,0x2f9f6}, + new uint[]{0x291df,0x2f81c}, + new uint[]{0x2921a,0x2f9f7}, + new uint[]{0x2940a,0x2f9fb}, + new uint[]{0x29496,0x2f9fd}, + new uint[]{0x295b6,0x2fa01}, + new uint[]{0x29b30,0x2fa09}, + new uint[]{0x2a0ce,0x2fa10}, + new uint[]{0x2a105,0x2fa12}, + new uint[]{0x2a20e,0x2fa13}, + new uint[]{0x2a291,0x2fa14}, + new uint[]{0x2a392,0x2f88f}, + new uint[]{0x2a600,0x2fa1d}, + }; + + public static bool Compare(string a,string b) + { + if (a.Equals(b, StringComparison.InvariantCulture)) return true; + if (a.Length != b.Length) return false; + for (int i=0;i g.Contains((uint)a[i])); + if (glyphGroup==null || !glyphGroup.Contains((uint)b[i])) return false; + } + return true; + } + } +} diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index ccdf61cc5..0aa6b5760 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -207,57 +207,111 @@ namespace Barotrauma return a1 + t * b; } + + public static Vector2? GetAxisAlignedLineIntersection(Vector2 a1, Vector2 a2, Vector2 axisAligned1, Vector2 axisAligned2, bool isHorizontal) + { + if (!isHorizontal) + { + if (Math.Sign(a1.X - axisAligned1.X) == Math.Sign(a2.X - axisAligned1.X)) + return null; + + float s = (a2.Y - a1.Y) / (a2.X - a1.X); + float y = a1.Y + (axisAligned1.X - a1.X) * s; + + if (axisAligned1.Y < axisAligned2.Y) + { + if (y < axisAligned1.Y) return null; + if (y > axisAligned2.Y) return null; + } + else + { + if (y > axisAligned1.Y) return null; + if (y < axisAligned2.Y) return null; + } + + return new Vector2(axisAligned1.X, y); + } + else //horizontal line + { + if (Math.Sign(a1.Y - axisAligned1.Y) == Math.Sign(a2.Y - axisAligned1.Y)) + return null; + + float s = (a2.X - a1.X) / (a2.Y - a1.Y); + float x = a1.X + (axisAligned1.Y - a1.Y) * s; + + if (axisAligned1.X < axisAligned2.X) + { + if (x < axisAligned1.X) return null; + if (x > axisAligned2.X) return null; + } + else + { + if (x > axisAligned1.X) return null; + if (x < axisAligned2.X) return null; + } + + return new Vector2(x, axisAligned1.Y); + } + } public static Vector2? GetLineRectangleIntersection(Vector2 a1, Vector2 a2, Rectangle rect) { - Vector2? intersection = GetLineIntersection(a1, a2, + Vector2? intersection = GetAxisAlignedLineIntersection(a1, a2, new Vector2(rect.X, rect.Y), - new Vector2(rect.Right, rect.Y)); - - if (intersection != null) return intersection; - - intersection = GetLineIntersection(a1, a2, - new Vector2(rect.X, rect.Y-rect.Height), - new Vector2(rect.Right, rect.Y-rect.Height)); - - if (intersection != null) return intersection; - - intersection = GetLineIntersection(a1, a2, - new Vector2(rect.X, rect.Y), - new Vector2(rect.X, rect.Y - rect.Height)); - - if (intersection != null) return intersection; - - return GetLineIntersection(a1, a2, new Vector2(rect.Right, rect.Y), - new Vector2(rect.Right, rect.Y - rect.Height)); + true); + + if (intersection != null) return intersection; + + intersection = GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.X, rect.Y-rect.Height), + new Vector2(rect.Right, rect.Y-rect.Height), + true); + + if (intersection != null) return intersection; + + intersection = GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.X, rect.Y), + new Vector2(rect.X, rect.Y - rect.Height), + false); + + if (intersection != null) return intersection; + + return GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.Right, rect.Y), + new Vector2(rect.Right, rect.Y - rect.Height), + false); } public static List GetLineRectangleIntersections(Vector2 a1, Vector2 a2, Rectangle rect) { List intersections = new List(); - Vector2? intersection = GetLineIntersection(a1, a2, + Vector2? intersection = GetAxisAlignedLineIntersection(a1, a2, new Vector2(rect.X, rect.Y), - new Vector2(rect.Right, rect.Y)); - - if (intersection != null) intersections.Add((Vector2)intersection); - - intersection = GetLineIntersection(a1, a2, - new Vector2(rect.X, rect.Y - rect.Height), - new Vector2(rect.Right, rect.Y - rect.Height)); - - if (intersection != null) intersections.Add((Vector2)intersection); - - intersection = GetLineIntersection(a1, a2, - new Vector2(rect.X, rect.Y), - new Vector2(rect.X, rect.Y - rect.Height)); - - if (intersection != null) intersections.Add((Vector2)intersection); - - intersection = GetLineIntersection(a1, a2, new Vector2(rect.Right, rect.Y), - new Vector2(rect.Right, rect.Y - rect.Height)); + true); + + if (intersection != null) intersections.Add((Vector2)intersection); + + intersection = GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.X, rect.Y - rect.Height), + new Vector2(rect.Right, rect.Y - rect.Height), + true); + + if (intersection != null) intersections.Add((Vector2)intersection); + + intersection = GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.X, rect.Y), + new Vector2(rect.X, rect.Y - rect.Height), + false); + + if (intersection != null) intersections.Add((Vector2)intersection); + + intersection = GetAxisAlignedLineIntersection(a1, a2, + new Vector2(rect.Right, rect.Y), + new Vector2(rect.Right, rect.Y - rect.Height), + false); if (intersection != null) intersections.Add((Vector2)intersection); @@ -276,15 +330,16 @@ namespace Barotrauma public static bool CircleIntersectsRectangle(Vector2 circlePos, float radius, Rectangle rect) { float xDist = Math.Abs(circlePos.X - rect.Center.X); + float yDist = Math.Abs(circlePos.Y - rect.Center.Y); + int halfWidth = rect.Width / 2; + int halfHeight = rect.Height / 2; if (xDist > (halfWidth + radius)) { return false; } - if (xDist <= (halfWidth)) { return true; } + if (yDist > (halfHeight + radius)) { return false; } - float yDist = Math.Abs(circlePos.Y - rect.Center.Y); - int halfHeight = rect.Height / 2; - if (yDist > (halfHeight + radius)) { return false; } + if (xDist <= (halfWidth)) { return true; } if (yDist <= (halfHeight)) { return true; } float distSqX = xDist - halfWidth; @@ -475,4 +530,18 @@ namespace Barotrauma return Math.Sign(d2 - d1); } } + + class CompareSegmentPointCW : IComparer + { + private Vector2 center; + + public CompareSegmentPointCW(Vector2 center) + { + this.center = center; + } + public int Compare(Lights.SegmentPoint a, Lights.SegmentPoint b) + { + return -CompareCCW.Compare(a.WorldPos, b.WorldPos, center); + } + } } diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs index b78fee054..83c39e761 100644 --- a/Subsurface/Source/Utils/SaveUtil.cs +++ b/Subsurface/Source/Utils/SaveUtil.cs @@ -28,7 +28,7 @@ namespace Barotrauma Directory.CreateDirectory(tempPath); try { - ClearFolder(tempPath); + ClearFolder(tempPath, new string[] { GameMain.GameSession.Submarine.FilePath }); } catch { @@ -37,7 +37,7 @@ namespace Barotrauma try { - if (Submarine.MainSub != null) + if (Submarine.MainSub != null && Submarine.Loaded.Contains(Submarine.MainSub)) { Submarine.MainSub.FilePath = Path.Combine(tempPath, Submarine.MainSub.Name + ".sub"); Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath); @@ -77,7 +77,7 @@ namespace Barotrauma XDocument doc = ToolBox.TryLoadXml(Path.Combine(TempPath, "gamesession.xml")); - string subPath = Path.Combine(TempPath, ToolBox.GetAttributeString(doc.Root, "submarine", "")); + string subPath = Path.Combine(TempPath, ToolBox.GetAttributeString(doc.Root, "submarine", ""))+".sub"; Submarine selectedMap = new Submarine(subPath, "");// Submarine.Load(); GameMain.GameSession = new GameSession(selectedMap, fileName, doc); @@ -285,19 +285,31 @@ namespace Barotrauma while (DecompressFile(sDir, zipStream, progress)) ; } - private static void ClearFolder(string FolderName) + private static void ClearFolder(string FolderName, string[] ignoredFiles = null) { DirectoryInfo dir = new DirectoryInfo(FolderName); foreach (FileInfo fi in dir.GetFiles()) { + bool ignore = false; + foreach (string ignoredFile in ignoredFiles) + { + if (Path.GetFullPath(fi.FullName).Equals(Path.GetFullPath(ignoredFile))) + { + ignore = true; + break; + } + } + + if (ignore) continue; + fi.IsReadOnly = false; fi.Delete(); } foreach (DirectoryInfo di in dir.GetDirectories()) { - ClearFolder(di.FullName); + ClearFolder(di.FullName, ignoredFiles); di.Delete(); } } diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index decd88e39..eb11099ec 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -89,7 +89,7 @@ namespace Barotrauma return doc; } - public static SpriteFont TryLoadFont(string file, Microsoft.Xna.Framework.Content.ContentManager contentManager) + /*public static SpriteFont TryLoadFont(string file, Microsoft.Xna.Framework.Content.ContentManager contentManager) { SpriteFont font = null; try @@ -102,7 +102,7 @@ namespace Barotrauma } return font; - } + }*/ public static object GetAttributeObject(XElement element, string name) { @@ -383,7 +383,7 @@ namespace Barotrauma return str.Substring(0, maxCharacters-3) + "..."; } - public static string LimitString(string str, SpriteFont font, int maxWidth) + public static string LimitString(string str, ScalableFont font, int maxWidth) { if (maxWidth <= 0 || string.IsNullOrWhiteSpace(str)) return ""; @@ -465,7 +465,7 @@ namespace Barotrauma return d[n, m]; } - public static string WrapText(string text, float lineLength, SpriteFont font) + public static string WrapText(string text, float lineLength, ScalableFont font) //TODO: could integrate this into the ScalableFont class directly { if (font.MeasureString(text).X < lineLength) return text; diff --git a/Subsurface/changelog.txt b/Subsurface/changelog.txt index adf12903a..fd2ca4ec7 100644 --- a/Subsurface/changelog.txt +++ b/Subsurface/changelog.txt @@ -1,3 +1,38 @@ +--------------------------------------------------------------------------------------------------------- +v0.5.4.5 +--------------------------------------------------------------------------------------------------------- + +- optimized light rendering +- switched fonts again, now to ones that support the cyrillic alphabet +- special symbols are allowed in player names again (unless there's already a player on the server +with a visually identical name) +- fixed monsters not appearing in the position indicated by the sonar in monster missions (or being desynced +whenever they did) +- fixed the game process staying active in the background after a crash +- players can't use headsets that are in the inventory +- the warning message about unlinked vents is only shown once when saving a sub (not for each vent) +- another attempt to fix AddToGUIUpdateList and SetTransformIgnoreContacts errors + +--------------------------------------------------------------------------------------------------------- +v0.5.4.4 +--------------------------------------------------------------------------------------------------------- + +- new fonts +- spectators see indicators for both subs during combat missions +- fixed saves becoming corrupted if the player saves and quits in the "map view" +- fixed "OpenAL not found" errors if trying to run the game with no enabled audio devices +- fixed OpenAL errors when quitting a round +- fixed unconscious/dead characters falling through floors +- the server list accepts multiple servers from the same IP (assuming they're running on different ports) +- fixed autorestart and the start button getting stuck if the server fails to load the respawn shuttle +- fixed server failing to start a round if the cargo spawnpoint has been placed outside the submarine +- fixed AddToGUIUpdateList errors +- fixed SetTransformIgnoreContacts errors +- tickboxes work again in the item UIs in wiring/character mode +- fixed characters standing in an incorrect position when using railgun controllers in a mirrored sub +- spawning a scorpion (an old placeholder enemy) doesn't crash the game anymore +- submarine editor shows a warning if there are structures/items way outside the sub + --------------------------------------------------------------------------------------------------------- v0.5.4.3 --------------------------------------------------------------------------------------------------------- diff --git a/Subsurface/freetype6.dll b/Subsurface/freetype6.dll new file mode 100644 index 000000000..3a94b26fe Binary files /dev/null and b/Subsurface/freetype6.dll differ diff --git a/Subsurface_Solution.sln b/Subsurface_Solution.sln index 19e687774..33d7b3913 100644 --- a/Subsurface_Solution.sln +++ b/Subsurface_Solution.sln @@ -1,9 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Barotrauma", "Subsurface\Barotrauma.csproj", "{008C0F83-E914-4966-9135-EA885059EDD8}" + ProjectSection(ProjectDependencies) = postProject + {C293DB32-FA42-486D-B128-5A12522FAE4E} = {C293DB32-FA42-486D-B128-5A12522FAE4E} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Farseer Physics MonoGame", "Farseer Physics Engine 3.5\Farseer Physics MonoGame.csproj", "{0AAD36E3-51A5-4A07-AB60-5C8A66BD38B7}" EndProject @@ -15,7 +18,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyper.ComponentModel", "Hyper.ComponentModel\Hyper.ComponentModel.csproj", "{3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpFont", "SharpFont\Source\SharpFont\SharpFont.csproj", "{C293DB32-FA42-486D-B128-5A12522FAE4E}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharpFontShared", "SharpFont\Source\SharpFontShared\SharpFontShared.shproj", "{2E4773B7-961A-4328-9D77-9749F9071CA2}" +EndProject Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + SharpFont\Source\SharpFontShared\SharpFontShared.projitems*{2e4773b7-961a-4328-9d77-9749f9071ca2}*SharedItemsImports = 13 + SharpFont\Source\SharpFontShared\SharpFontShared.projitems*{c293db32-fa42-486d-b128-5a12522fae4e}*SharedItemsImports = 4 + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Android|Any CPU = Android|Any CPU Android|Mixed Platforms = Android|Mixed Platforms @@ -280,6 +291,60 @@ Global {3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Windows8|Mixed Platforms.Build.0 = Release|Any CPU {3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Windows8|x86.ActiveCfg = Release|Any CPU {3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Windows8|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Android|x86.Build.0 = Release|Any CPU + {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}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Debug|x86.ActiveCfg = Debug|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Debug|x86.Build.0 = Debug|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.iOS|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Linux|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.OSX|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.PSM|x86.Build.0 = Release|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 + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Release|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows|x86.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|Any CPU.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|Any CPU.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|Mixed Platforms.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|Mixed Platforms.Build.0 = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|x86.ActiveCfg = Release|Any CPU + {C293DB32-FA42-486D-B128-5A12522FAE4E}.Windows8|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE