8000 Add FreeType rasterizer by SemMulder · Pull Request #58 · inkyblackness/imgui-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Add FreeType rasterizer #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions FreeType.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package imgui

// #cgo pkg-config: freetype2
// #include "FreeTypeWrapper.h"
import "C"
import (
"errors"
)

const (
// By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
FreeTypeRasterizerFlagsNoHinting = 1 << 0 // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
FreeTypeRasterizerFlagsNoAutoHint = 1 << 1 // Disable auto-hinter.
FreeTypeRasterizerFlagsForceAutoHint = 1 << 2 // Indicates that the auto-hinter is preferred over the font's native hinter.
FreeTypeRasterizerFlagsLightHinting = 1 << 3 // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text.
FreeTypeRasterizerFlagsMonoHinting = 1 << 4 // Strong hinting algorithm that should only be used for monochrome output.
FreeTypeRasterizerFlagsBold = 1 << 5 // Styling: Should we artificially embolden the font?
FreeTypeRasterizerFlagsOblique = 1 << 6 // Styling: Should we slant the font, emulating italic style?
FreeTypeRasterizerFlagsMonochrome = 1 << 7 // Disable anti-aliasing. Combine this with MonoHinting for best results!
)

// BuildFontAtlasFreeType builds the FontAtlas using FreeType instead of the
// default rasterizer. FreeType renders small fonts better. Make sure to call
// `FontAtlas.BuildFontAtlasFreeType()` *BEFORE* calling
// `FontAtlas.GetTexDataAsRGBA32()` or `FontAtlas.Build()` (so normal Build()
// won't be called)
func (atlas FontAtlas) BuildFontAtlasFreeTypeV(flags int) error {
if C.iggImGuiFreeTypeBuildFontAtlas(atlas.handle(), C.uint(flags)) == 0 {
return errors.New("Failed to build FreeType FontAtlas")
} else {
return nil
}
}

// BuildFontAtlasFreeType calls BuildFontAtlasFreeTypeV(0)
func (atlas FontAtlas) BuildFontAtlasFreeType() error {
return atlas.BuildFontAtlasFreeTypeV(0)
}
9 changes: 9 additions & 0 deletions FreeTypeWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "imguiWrappedHeader.h"
#include "imgui_freetype.h"
#include "FreeTypeWrapper.h"

int iggImGuiFreeTypeBuildFontAtlas(IggFontAtlas handle, unsigned int flags)
{
ImFontAtlas *fontAtlas = reinterpret_cast<ImFontAtlas *>(handle);
return ImGuiFreeType::BuildFontAtlas(fontAtlas, flags);
}
14 changes: 14 additions & 0 deletions FreeTypeWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "imguiWrapperTypes.h"

#ifdef __cplusplus
extern "C"
{
#endif

extern int iggImGuiFreeTypeBuildFontAtlas(IggFontAtlas handle, unsigned int flags);

#ifdef __cplusplus
}
#endif
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/inkyblackness/imgui-go

require github.com/stretchr/testify v1.3.0

go 1.13
Loading
0