Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept for advanced glyph layout (2nd try) #143

Open
wants to merge 38 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4254201
Merge alternate OpenType Advanced Typographic Table (ATT) support.
skynavga Jul 14, 2021
c15eac6
Merge branch 'trunk' into pr/126
danfickle Oct 9, 2021
257394a
Very early work in getting advanced glyph layout working.
danfickle Oct 13, 2021
10c5a6b
Merge remote-tracking branch 'upstream/trunk' into advance_opentype
danfickle Oct 13, 2021
4f231e4
Width is now matching displayed text.
danfickle Oct 13, 2021
440b51f
Use our own classes rather than feature flags everywhere.
danfickle Oct 15, 2021
3f1e7a4
Started example for DIN91379 Sequences
Oct 17, 2021
eb82152
Started example for DIN91379 Sequences
Oct 17, 2021
c998ee8
Started example for DIN91379 Sequences
Oct 17, 2021
a674930
Merge remote-tracking branch 'origin/advance_opentype' into advance_o…
Oct 17, 2021
ead2883
Started example for DIN91379 Sequences
Oct 17, 2021
3c44502
Started example for DIN91379 Sequences
Oct 17, 2021
485e7c1
Started example for DIN91379 Sequences
Oct 17, 2021
16afe86
Started example for DIN91379 Sequences
Oct 17, 2021
884f9f5
Started example for DIN91379 Sequences
Oct 17, 2021
d06efa2
Started example for DIN91379 Sequences
Oct 17, 2021
90da59b
Started example for DIN91379 Sequences
Oct 17, 2021
9a2e6fc
Started example for DIN91379 Sequences
Oct 18, 2021
26f7abe
Update AdvancedTextLayoutSequencesDin91379.java
vk-github18 Nov 26, 2021
a802ef7
Adopt patch for FOP-2704
May 26, 2022
4c4349c
Adopt patch for FOP-2704
May 27, 2022
db0bfd2
Adopt patch for FOP-2704
May 27, 2022
3c34ce4
Proof of concept for glyph positioning
May 27, 2022
261c78c
Proof of concept for glyph positioning
May 27, 2022
f644bbf
Merge remote-tracking branch 'origin/advance_opentype' into advance_o…
May 27, 2022
5bf6c6f
Proof of concept for glyph positioning
May 27, 2022
f777f20
Cleaning up
May 28, 2022
b1b125b
Added comments about glyph vectors
May 28, 2022
1a7c52c
cleaning up
May 28, 2022
931001e
cleaning up
May 28, 2022
8134c72
corrections
May 28, 2022
fc7def8
use reordering of glyphs
May 29, 2022
76ef1da
use reordering of glyphs
May 29, 2022
675861d
for positioning width of font characters is needed
May 29, 2022
0b5e98d
Copy Fix for FOP-2969
May 31, 2022
520e52f
Set gdef of AdvancedTypographicTable in GlyphPositioningTable
Jun 2, 2022
ff633e4
Merge branch 'trunk' into advance_opentype
vk-github18 Jun 2, 2022
0aa46a7
Copy fix for FOP-3077: Use all rulesets for glyph substitution
Sep 18, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pdfbox.examples.pdmodel;

import java.io.IOException;

import org.apache.fontbox.ttf.OTFParser;
import org.apache.fontbox.ttf.OpenTypeFont;
import org.apache.fontbox.ttf.advanced.GlyphVectorAdvanced;
import org.apache.fontbox.ttf.advanced.api.AdvancedOTFParser;
import org.apache.fontbox.ttf.advanced.api.AdvancedOpenTypeFont;
import org.apache.fontbox.ttf.advanced.api.GlyphVector;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.util.Matrix;

/**
* An example of using an embedded OpenType font with advanced glyph layout.
*
* @author Daniel Fickling
*/
public final class AdvancedTextLayout
{
private AdvancedTextLayout()
{
}

private static float getAdvance(float startX, GlyphVector vector, float fontSize) {
return (((vector.getWidth() / 1000f) * fontSize) + startX);
}

private static Matrix createMatrix(float translateX, float translateY) {
return Matrix.getTranslateInstance(translateX, translateY);
}

public static void main(String[] args) throws IOException
{
try (PDDocument document = new PDDocument())
{
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);

//String dir = "C:\\Users\\daniel\\Desktop\\fonts\\";
//String fontFile = "./pdfbox/src/main/resources/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf";
//String fontFile = dir + "IndieFlower-Regular.ttf";
//String fontFile = dir + "SourceSansPro-Regular.ttf";
String dir = "/home/volker/work/";
String fontFile = dir + "NotoSans-Regular.ttf";


AdvancedOTFParser fontParser = new AdvancedOTFParser();
AdvancedOpenTypeFont otFont = fontParser.parse(fontFile);
PDFont font = PDType0Font.load(document, otFont, true);

GlyphVector vector = null;
float x = 10;

try (PDPageContentStream stream = new PDPageContentStream(document, page))
{
float fontSize = 20;
stream.beginText();
stream.setFont(font, fontSize);

vector = otFont.createGlyphVector("PDFBox's Unicode with Embedded OpenType Font", (int)fontSize);
stream.setTextMatrix(createMatrix(x, 200));
stream.showGlyphVector(vector);
x = getAdvance(10, vector, fontSize);

vector = otFont.createGlyphVector("|AFTER (SIMPLE)", (int)fontSize);
stream.setTextMatrix(createMatrix(x, 200));
stream.showGlyphVector(vector);
x = 10;

String complex = "A̋L̦ a̋ N̂N̦B ўў 1/2";

vector = otFont.createGlyphVector(complex, (int)fontSize);
stream.setTextMatrix(createMatrix(x, 100));
stream.showGlyphVector(vector);
x = getAdvance(10, vector, fontSize);

vector = otFont.createGlyphVector("|AFTER (COMPLEX)", (int)fontSize);
stream.setTextMatrix(createMatrix(x, 100));
stream.showGlyphVector(vector);

stream.setTextMatrix(Matrix.getTranslateInstance(10, 160));
stream.showText(complex);
stream.setTextMatrix(Matrix.getTranslateInstance(10 + (font.getStringWidth(complex) / 1000f * fontSize), 160));
stream.showText("|AFTER (BAD)");

stream.endText();
}

document.save("advanced-text.pdf");
}
}
}
Loading