Merges thirdparty modules into this repo.
This commit is contained in:
1
thirdparty/ft4d
vendored
1
thirdparty/ft4d
vendored
Submodule thirdparty/ft4d deleted from 791af0dfe6
5
thirdparty/ft4d/.gitignore
vendored
Normal file
5
thirdparty/ft4d/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/.bin
|
||||
/.dub
|
||||
/dub.selections.json
|
||||
|
||||
*.swp
|
9
thirdparty/ft4d/LICENSE
vendored
Normal file
9
thirdparty/ft4d/LICENSE
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 KajiroNagi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
thirdparty/ft4d/dub.json
vendored
Normal file
14
thirdparty/ft4d/dub.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "ft4d",
|
||||
"license": "Boost",
|
||||
|
||||
"targetType": "library",
|
||||
"targetPath": ".bin",
|
||||
|
||||
"dependencies": {
|
||||
"bindbc-freetype": "~>0.7.0"
|
||||
},
|
||||
|
||||
"versions": ["BindFT_Static"],
|
||||
"libs": ["freetype"]
|
||||
}
|
100
thirdparty/ft4d/src/ft4d/Face.d
vendored
Normal file
100
thirdparty/ft4d/src/ft4d/Face.d
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// License: MIT
|
||||
module ft4d.Face;
|
||||
|
||||
import std.conv,
|
||||
std.exception,
|
||||
std.string,
|
||||
std.typecons;
|
||||
|
||||
import ft4d.ft;
|
||||
|
||||
/// RefCounted version of Face.
|
||||
alias FaceRef = RefCounted!Face;
|
||||
|
||||
/// A wrapper type for freetype Face object.
|
||||
///
|
||||
/// Usually this is wrapped by RefCounted.
|
||||
/// When it's default, empty() property returns true.
|
||||
struct Face {
|
||||
public:
|
||||
@disable this(this);
|
||||
|
||||
alias native this;
|
||||
|
||||
/// Creates new face from the path.
|
||||
static FaceRef CreateFromPath(string path, int index = 0) {
|
||||
FT_Face f;
|
||||
FT_New_Face(ft.lib, path.toStringz, index.to!FT_Long, &f).
|
||||
EnforceFT();
|
||||
return FaceRef(f);
|
||||
}
|
||||
/// Creates new face from the buffer.
|
||||
static FaceRef CreateFromBuffer(in ubyte[] buf, int index = 0) {
|
||||
FT_Face f;
|
||||
FT_New_Memory_Face(ft.lib, buf.ptr, buf.length.to!FT_Long, index.to!FT_Long, &f).
|
||||
EnforceFT();
|
||||
return FaceRef(f);
|
||||
}
|
||||
|
||||
~this() {
|
||||
if (!empty) FT_Done_Face(native_).EnforceFT();
|
||||
}
|
||||
|
||||
/// A move operator. RHS will be empty.
|
||||
ref Face opAssign(ref Face rhs) {
|
||||
if (&rhs != &this) {
|
||||
native_ = rhs.native_;
|
||||
rhs.native_ = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
///
|
||||
@property bool empty() const {
|
||||
return !native_;
|
||||
}
|
||||
/// You should not modify the pointer directly.
|
||||
@property inout(FT_Face) native() inout in (!empty) {
|
||||
return native_;
|
||||
}
|
||||
|
||||
private:
|
||||
FT_Face native_;
|
||||
}
|
||||
|
||||
/// A set of parameters for loading glyphs.
|
||||
struct GlyphLoader {
|
||||
public:
|
||||
///
|
||||
int pxWidth, pxHeight;
|
||||
///
|
||||
dchar character;
|
||||
|
||||
///
|
||||
FT_Int32 flags = FT_LOAD_DEFAULT;
|
||||
|
||||
/// Loads a glyph with the parameters this has.
|
||||
bool Load(ref FaceRef face) const
|
||||
in {
|
||||
assert(!face.empty);
|
||||
assert(pxWidth+pxHeight > 0 && pxWidth >= 0 && pxHeight >= 0);
|
||||
}
|
||||
do {
|
||||
const i = FT_Get_Char_Index(face, character.to!FT_ULong);
|
||||
if (i == 0) return false;
|
||||
|
||||
FT_Set_Pixel_Sizes(face, pxWidth.to!FT_UInt, pxHeight.to!FT_UInt).EnforceFT();
|
||||
|
||||
FT_Load_Glyph(face, i, flags).EnforceFT();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Throws an exception if the face doesn't have a rendered bitmap in its glyph slot.
|
||||
///
|
||||
/// Returns: the rendered bitmap in the glyph slot
|
||||
ref const(FT_Bitmap) EnforceGlyphBitmap(in ref FaceRef face) in (!face.empty) {
|
||||
(face.glyph.format == FT_GLYPH_FORMAT_BITMAP).
|
||||
enforce("the glyph doesn't have bitmap");
|
||||
return face.glyph.bitmap;
|
||||
}
|
40
thirdparty/ft4d/src/ft4d/ft.d
vendored
Normal file
40
thirdparty/ft4d/src/ft4d/ft.d
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// License: MIT
|
||||
module ft4d.ft;
|
||||
|
||||
import std.exception;
|
||||
|
||||
public import bindbc.freetype;
|
||||
|
||||
/// This class is just for separating ft functions from global namespace.
|
||||
abstract class ft {
|
||||
public:
|
||||
/// Initializes freetype library.
|
||||
static void Initialize() {
|
||||
if (lib_) return;
|
||||
FT_Init_FreeType(&lib_).EnforceFT();
|
||||
}
|
||||
/// Disposes all resources allocated by freetype library.
|
||||
static void Dispose() {
|
||||
if (!lib_) return;
|
||||
FT_Done_FreeType(lib_).EnforceFT();
|
||||
}
|
||||
/// Checks if freetype library has already been initialized
|
||||
static @property bool IsInitialized() {
|
||||
return !!lib_;
|
||||
}
|
||||
|
||||
/// Returns: a pointer to an initialized library
|
||||
static @property FT_Library lib() in (IsInitialized) {
|
||||
return lib_;
|
||||
}
|
||||
|
||||
private:
|
||||
static FT_Library lib_;
|
||||
}
|
||||
|
||||
/// Checks the result value of freetype functions and throws an exception if needed.
|
||||
void EnforceFT(FT_Error i) {
|
||||
// TODO: throw with descriptions
|
||||
|
||||
(i == FT_Err_Ok).enforce("unknown error");
|
||||
}
|
7
thirdparty/ft4d/src/ft4d/package.d
vendored
Normal file
7
thirdparty/ft4d/src/ft4d/package.d
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// License: MIT
|
||||
module ft4d;
|
||||
|
||||
public {
|
||||
import ft4d.ft,
|
||||
ft4d.Face;
|
||||
}
|
32
thirdparty/ft4d/test.d
vendored
Normal file
32
thirdparty/ft4d/test.d
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env dub
|
||||
|
||||
/+ dub.json:
|
||||
{
|
||||
"name": "test",
|
||||
|
||||
"dependencies": {
|
||||
"ft4d": {"path": "."}
|
||||
}
|
||||
}
|
||||
+/
|
||||
|
||||
import std;
|
||||
import ft4d;
|
||||
|
||||
void main() {
|
||||
ft.Initialize();
|
||||
assert(ft.IsInitialized);
|
||||
scope(exit) ft.Dispose();
|
||||
|
||||
auto face = Face.CreateFromPath("/usr/share/fonts/TTF/Ricty-Regular.ttf");
|
||||
|
||||
GlyphLoader loader;
|
||||
loader.pxWidth = 16;
|
||||
loader.pxHeight = 0;
|
||||
loader.flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER;
|
||||
|
||||
loader.character = 'a';
|
||||
loader.Load(face).enforce();
|
||||
|
||||
face.EnforceGlyphBitmap().writeln;
|
||||
}
|
Reference in New Issue
Block a user