Skip to content

Commit

Permalink
release: 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aramperes committed Aug 22, 2023
1 parent afe6c7d commit 4ac49cd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'dev.poire.buzz4j'
version '1.0.0-SNAPSHOT'
version '1.0.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/poire/buzz4j/HarfBuzz.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Java bindings for HarfBuzz.
*/
public class HarfBuzz {

private static final int GLYPH_LENGTH = 5;
Expand All @@ -20,6 +23,14 @@ public class HarfBuzz {
System.loadLibrary("buzz4j");
}

/**
* Apply text-shaping to an input string. The result is an array of glyphs, with their drawing dimensions.
*
* @param fontPath Path to the font
* @param text Input text
* @return Array of {@link ShapeGlyph} (glyph information returned by HarfBuzz)
* @throws IOException Invalid font file
*/
public static ShapeGlyph[] shapeString(Path fontPath, String text) throws IOException {
if (fontPath == null || !Files.isRegularFile(fontPath))
throw new IOException(String.format("Font path provided is not a file: %s", fontPath));
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/dev/poire/buzz4j/ShapeGlyph.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,76 @@

import java.util.Objects;

/**
* Represents a glyph with drawing information returned from HarfBuzz.
*/
public final class ShapeGlyph {
private final int glyphId;
private final int advanceX;
private final int advanceY;
private final int offsetX;
private final int offsetY;

public ShapeGlyph(int glyphId, int advanceX, int advanceY, int offsetX, int offsetY) {
ShapeGlyph(int glyphId, int advanceX, int advanceY, int offsetX, int offsetY) {
this.glyphId = glyphId;
this.advanceX = advanceX;
this.advanceY = advanceY;
this.offsetX = offsetX;
this.offsetY = offsetY;
}

/**
* The integer ID of the glpyh.
* @return the integer ID
*/
public int glyphId() {
return glyphId;
}

/**
* By how much the glyph advances the text shape on the X axis
* @return the advance on X axis
*/
public int advanceX() {
return advanceX;
}

/**
* By how much the glyph advances the text shape on the Y axis
* @return the advance on Y axis
*/
public int advanceY() {
return advanceY;
}

/**
* By how much the glyph should be offseted on the X axis
* @return the offset on X axis
*/
public int offsetX() {
return offsetX;
}

/**
* By how much the glyph should be offseted on the Y axis
* @return the offset on Y axis
*/
public int offsetY() {
return offsetY;
}

/**
* The effective width of the glyph.
* @return the sum of offset and advance
*/
public int effectiveWidth() {
return advanceX + offsetX;
}

/**
* The effective height of the glyph.
* @return the sum of offset and advance
*/
public int effectiveHeight() {
return advanceY + offsetY;
}
Expand Down

0 comments on commit 4ac49cd

Please sign in to comment.