harfbuzz

package module
v0.0.0-...-51bb37a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 1 Imported by: 0

README

Go Harfbuzz bindings

[!NOTE] go-harfbuzz is currently work-in-progress. The current goal is to implement all Harfbuzz v8.3 methods and then start to support newer versions.

go-harfbuzz is a Golang binding to the Harfbuzz text shaping engine.

Requirements:

  • Having CGO enabled
  • Having pkg-config installed.
  • Having harfbuzz installed.
    • version: 8.3 or above.
    • dev version required. (pkg-config should find it)

Installation:

go get -u github.com/haashemi/go-harfbuzz@main

Usage:

Low-Level
package main

import (
	"fmt"

	"github.com/haashemi/go-harfbuzz/hb"
)

func main() {
	buf := hb.BufferCreate()
	defer hb.BufferDestroy(buf)

	hb.BufferAddUTF8(buf, "Hello World!")
	hb.BufferGuessSegmentProperties(buf)

	blob := hb.BlobCreateFromFile("path/to/font.ttf")
	defer hb.BlobDestroy(blob)

	face := hb.FaceCreate(blob, 0)
	defer hb.FaceDestroy(face)

	font := hb.FontCreate(face)
	defer hb.FontDestroy(font)

	hb.Shape(font, buf, nil)

	glyphsInfo := hb.BufferGetGlyphInfos(buf)
	glyphsPositions := hb.BufferGetGlyphPositions(buf)

	var cursorX, cursorY int32
	for i := 0; i < len(glyphsInfo); i++ {
		info := glyphsInfo[i]
		pos := glyphsPositions[i]

		fmt.Printf("index: %d\tinfo: %v\tpos: %v\n", i, info, pos)

		// glyphID := info.Codepoint
		// XOffset := pos.XOffset
		// YOffset := pos.YOffset
		// Draw the glyph here.

		cursorX += pos.XAdvance
		cursorY += pos.YAdvance
	}

	fmt.Println("X Advance:", cursorX)
	fmt.Println("Y Advance:", cursorY)
}

High-Level

Not implemented, yet.

Contributions

All types of contributions are highly appreciated.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

type Blob struct {
	// contains filtered or unexported fields
}

Blob holds the low-level Blob.

func NewBlob

func NewBlob(filename string) *Blob

NewBlob returns a new Blob from the data of file from path.

func NewBlobFromBytes

func NewBlobFromBytes(data []byte) *Blob

NewBlobFromBytes returns a new Blob from the data.

func (*Blob) Blob

func (b *Blob) Blob() hb.Blob

Blob returns the raw blob used for low-level operations

func (*Blob) Close

func (b *Blob) Close()

Close destroys the blob and frees the memory.

func (*Blob) Data

func (b *Blob) Data() []byte

Data returns the blob's data.

func (*Blob) Length

func (b *Blob) Length() uint32

Length returns the length of the blob's data.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL