meijun e5a458c459 创建初始版本 | 3 éve | |
---|---|---|
.. | ||
Examples | 3 éve | |
SharpFont | 3 éve | |
.gitignore | 3 éve | |
LICENSE | 3 éve | |
README.md | 3 éve | |
SharpFont.FxCop | 3 éve | |
SharpFont.sln | 3 éve |
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, 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:
out
parameter are returned instead.For example, a regular FreeType method looks like this:
Face face;
int err = FT_New_Face(library, "./myfont.ttf", 0, &face);
The equivalent code in C# with SharpFont is:
Face face = new Face(library, "./myfont.ttf");
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 freetype.dll
in the project's output directory. It is
possible to rename the file by changing the filename constant in
FT.Internal.cs 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.
A 32-bit copy of freetype.dll
is included in the Examples project.
Currently, Windows 64-bit systems require you to either compile SharpFont under the WIN64 configurations and include a
64-bit copy of freetype.dll
or to compile your project as an x86 project (instead of Any CPU). I describe this issue
in further detail in the Known Issues section.
Thanks to this StackOverflow answer for the directions:
builds\win32\vc2010\freetype.sln
(or whatever version of Visual Studio you have) in Visual Studio.General
selection, change the Target Name
to freetype
and the Configuration Type
to Dynamic Library
(.dll)
.ftoption.h
(in the project's Header Files
section) and add the following two lines near the DLL export
compilation
section:#define FT_EXPORT(x) __declspec(dllexport) x
#define FT_BASE(x) __declspec(dllexport) x
Finally, complile the project (F6
or Build -> Build Solution). freetype.dll
will be output to objs\win32\vc2010
.
The biggest currently known issue is the Windows 64-bit incompatibility. This is a three part issue:
long long
s and pointers are 64 bits long and everything else remains 32 bits
long. On LP64 systems, long
s are also 64 bits long. This creates a discrepancy between the length of the long
type
on different operating systems.long
type, specifically their FT_Long
, FT_ULong
, FT_Fixed
, FT_Pos
, and
FT_F26Dot6
typedefs. This makes the size of FreeType structs different on Windows 64-bit systems and other 64-bit
systems.long
type is always 64 bits long, which doesn't always match the length of the native long
type. For all
LP64 systems, the IntPtr
type works because it's length matches the length of a pointer on that system. For LLP64
systems, this doesn't work because long
is 32 bits long while a pointer is 64 bits long.The simplest solution is to compile your project as x86 because all systems will default on the 32 bit FreeType binary.
However, this can be restrictive to some applications. The best solution is to compile a version of FreeType with
64-bit long
s, which I will look into and test in the near future.
As metioned earlier, SharpFont is licensed under the MIT License. The terms of the MIT license are included in both the LICENSE file and below:
Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.