Skip to content

Commit 083848c

Browse files
SnipxiText-CI
authored andcommitted
OTF: Support GposLookupType7 format (subtable format 2)
DEVSIX-4631 Autoported commit. Original commit hash: [c62f83b89]
1 parent 6f7d1ce commit 083848c

18 files changed

+727
-139
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using System.Collections.Generic;
25+
using iText.IO.Font;
26+
using iText.IO.Util;
27+
using iText.Test;
28+
29+
namespace iText.IO.Font.Otf {
30+
public class GposLookupType7Test : ExtendedITextTest {
31+
private static readonly String RESOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
32+
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/GposLookupType7Test/";
33+
34+
[NUnit.Framework.Test]
35+
public virtual void VerifyXAdvanceIsAppliedForContextualPositioning() {
36+
TrueTypeFont fontProgram = (TrueTypeFont)FontProgramFactory.CreateFont(RESOURCE_FOLDER + "NotoSansMyanmar-Regular.ttf"
37+
);
38+
GlyphPositioningTableReader gposTableReader = fontProgram.GetGposTable();
39+
GposLookupType7 lookup = (GposLookupType7)gposTableReader.GetLookupTable(28);
40+
IList<Glyph> glyphs = JavaUtil.ArraysAsList(fontProgram.GetGlyphByCode(25), fontProgram.GetGlyphByCode(174
41+
), fontProgram.GetGlyphByCode(5), fontProgram.GetGlyphByCode(411));
42+
GlyphLine gl = new GlyphLine(glyphs);
43+
NUnit.Framework.Assert.AreEqual(0, gl.Get(1).GetXAdvance());
44+
NUnit.Framework.Assert.IsTrue(lookup.TransformLine(gl));
45+
NUnit.Framework.Assert.AreEqual(219, gl.Get(1).GetXAdvance());
46+
}
47+
48+
[NUnit.Framework.Test]
49+
public virtual void VerifyXAdvanceIsNotAppliedForUnsatisfiedContextualPositioning() {
50+
TrueTypeFont fontProgram = (TrueTypeFont)FontProgramFactory.CreateFont(RESOURCE_FOLDER + "NotoSansMyanmar-Regular.ttf"
51+
);
52+
GlyphPositioningTableReader gposTableReader = fontProgram.GetGposTable();
53+
GposLookupType7 lookup = (GposLookupType7)gposTableReader.GetLookupTable(28);
54+
IList<Glyph> glyphs = JavaUtil.ArraysAsList(fontProgram.GetGlyphByCode(1), fontProgram.GetGlyphByCode(174)
55+
, fontProgram.GetGlyphByCode(5), fontProgram.GetGlyphByCode(411));
56+
GlyphLine gl = new GlyphLine(glyphs);
57+
NUnit.Framework.Assert.IsFalse(lookup.TransformLine(gl));
58+
for (int i = 0; i < gl.Size(); i++) {
59+
NUnit.Framework.Assert.AreEqual(0, gl.Get(i).GetXAdvance());
60+
NUnit.Framework.Assert.AreEqual(0, gl.Get(i).GetYAdvance());
61+
}
62+
}
63+
}
64+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
This Font Software is licensed under the SIL Open Font License,
2+
Version 1.1.
3+
4+
This license is copied below, and is also available with a FAQ at:
5+
http://scripts.sil.org/OFL
6+
7+
-----------------------------------------------------------
8+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9+
-----------------------------------------------------------
10+
11+
PREAMBLE
12+
The goals of the Open Font License (OFL) are to stimulate worldwide
13+
development of collaborative font projects, to support the font
14+
creation efforts of academic and linguistic communities, and to
15+
provide a free and open framework in which fonts may be shared and
16+
improved in partnership with others.
17+
18+
The OFL allows the licensed fonts to be used, studied, modified and
19+
redistributed freely as long as they are not sold by themselves. The
20+
fonts, including any derivative works, can be bundled, embedded,
21+
redistributed and/or sold with any software provided that any reserved
22+
names are not used by derivative works. The fonts and derivatives,
23+
however, cannot be released under any other type of license. The
24+
requirement for fonts to remain under this license does not apply to
25+
any document created using the fonts or their derivatives.
26+
27+
DEFINITIONS
28+
"Font Software" refers to the set of files released by the Copyright
29+
Holder(s) under this license and clearly marked as such. This may
30+
include source files, build scripts and documentation.
31+
32+
"Reserved Font Name" refers to any names specified as such after the
33+
copyright statement(s).
34+
35+
"Original Version" refers to the collection of Font Software
36+
components as distributed by the Copyright Holder(s).
37+
38+
"Modified Version" refers to any derivative made by adding to,
39+
deleting, or substituting -- in part or in whole -- any of the
40+
components of the Original Version, by changing formats or by porting
41+
the Font Software to a new environment.
42+
43+
"Author" refers to any designer, engineer, programmer, technical
44+
writer or other person who contributed to the Font Software.
45+
46+
PERMISSION & CONDITIONS
47+
Permission is hereby granted, free of charge, to any person obtaining
48+
a copy of the Font Software, to use, study, copy, merge, embed,
49+
modify, redistribute, and sell modified and unmodified copies of the
50+
Font Software, subject to the following conditions:
51+
52+
1) Neither the Font Software nor any of its individual components, in
53+
Original or Modified Versions, may be sold by itself.
54+
55+
2) Original or Modified Versions of the Font Software may be bundled,
56+
redistributed and/or sold with any software, provided that each copy
57+
contains the above copyright notice and this license. These can be
58+
included either as stand-alone text files, human-readable headers or
59+
in the appropriate machine-readable metadata fields within text or
60+
binary files as long as those fields can be easily viewed by the user.
61+
62+
3) No Modified Version of the Font Software may use the Reserved Font
63+
Name(s) unless explicit written permission is granted by the
64+
corresponding Copyright Holder. This restriction only applies to the
65+
primary font name as presented to the users.
66+
67+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68+
Software shall not be used to promote, endorse or advertise any
69+
Modified Version, except to acknowledge the contribution(s) of the
70+
Copyright Holder(s) and the Author(s) or with their explicit written
71+
permission.
72+
73+
5) The Font Software, modified or unmodified, in part or in whole,
74+
must be distributed entirely under this license, and must not be
75+
distributed under any other license. The requirement for fonts to
76+
remain under this license does not apply to any document created using
77+
the Font Software.
78+
79+
TERMINATION
80+
This license becomes null and void if any of the above conditions are
81+
not met.
82+
83+
DISCLAIMER
84+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92+
OTHER DEALINGS IN THE FONT SOFTWARE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This software uses the following test resources under the following licenses:
2+
| NotoSansMyanmar-Regular.ttf | OFL-1.1 | LICENSE-OFL.txt |

itext/itext.io/itext/io/LogMessageConstant.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public const String ENCRYPTED_PAYLOAD_FILE_SPEC_SHALL_HAVE_AFRELATIONSHIP_FILED_
160160

161161
public const String FORM_FIELD_WAS_FLUSHED = "A form field was flushed. There's no way to create this field in the AcroForm dictionary.";
162162

163+
public const String GPOS_LOOKUP_SUBTABLE_FORMAT_NOT_SUPPORTED = "Subtable format {0} of GPOS Lookup Type {1} is not supported yet";
164+
163165
public const String GRAPHICS_STATE_WAS_DELETED = "Graphics state is always deleted after event dispatching. If you want to preserve it in renderer info, use preserveGraphicsState method after receiving renderer info.";
164166

165167
public const String IF_PATH_IS_SET_VERTICES_SHALL_NOT_BE_PRESENT = "If Path key is set, Vertices key shall not be present. Remove Vertices key before setting Path";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
namespace iText.IO.Font.Otf {
24+
public abstract class ContextualPositionRule : ContextualRule {
25+
/// <summary>Retrieves the position lookup records.</summary>
26+
/// <remarks>
27+
/// Retrieves the position lookup records. Each record specifies a position in the context glyph
28+
/// sequence and a LookupListIndex to the position lookup that is applied at that position.
29+
/// </remarks>
30+
/// <returns>
31+
/// an array of
32+
/// <see cref="PosLookupRecord"/>.
33+
/// </returns>
34+
public abstract PosLookupRecord[] GetPosLookupRecords();
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
namespace iText.IO.Font.Otf {
24+
public abstract class ContextualPositionTable : ContextualTable<ContextualPositionRule> {
25+
protected internal ContextualPositionTable(OpenTypeFontTableReader openReader, int lookupFlag)
26+
: base(openReader, lookupFlag) {
27+
}
28+
}
29+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
namespace iText.IO.Font.Otf {
24+
public abstract class ContextualRule {
25+
/// <summary>Gets the length of the context glyph sequence defined by this rule</summary>
26+
/// <returns>length of the context</returns>
27+
public abstract int GetContextLength();
28+
29+
/// <summary>Checks if glyph line element matches element from input sequence of the rule.</summary>
30+
/// <remarks>
31+
/// Checks if glyph line element matches element from input sequence of the rule.
32+
/// <br /><br />
33+
/// NOTE: rules do not contain the first element of the input sequence, the first element is defined by rule
34+
/// position in substitution table. Therefore atIdx shall not be 0.
35+
/// </remarks>
36+
/// <param name="glyphId">glyph code id</param>
37+
/// <param name="atIdx">
38+
/// index in the rule sequence. Shall be: 0 &lt; atIdx &lt;
39+
/// <see cref="GetContextLength()"/>
40+
/// </param>
41+
/// <returns>
42+
///
43+
/// <see langword="true"/>
44+
/// if glyph matches element
45+
/// </returns>
46+
public abstract bool IsGlyphMatchesInput(int glyphId, int atIdx);
47+
48+
/// <summary>Gets the length of the lookahead context glyph sequence defined by this rule</summary>
49+
/// <returns>length of the lookahead context</returns>
50+
public virtual int GetLookaheadContextLength() {
51+
return 0;
52+
}
53+
54+
/// <summary>Gets the length of the backtrack context glyph sequence defined by this rule</summary>
55+
/// <returns>length of the backtrack context</returns>
56+
public virtual int GetBacktrackContextLength() {
57+
return 0;
58+
}
59+
60+
/// <summary>Checks if glyph line element matches element from lookahead sequence of the rule.</summary>
61+
/// <param name="glyphId">glyph code id</param>
62+
/// <param name="atIdx">
63+
/// index in rule sequence. Shall be: 0 &lt;= atIdx &lt;
64+
/// <see cref="GetLookaheadContextLength()"/>
65+
/// </param>
66+
/// <returns>
67+
///
68+
/// <see langword="true"/>
69+
/// if glyph matches element from lookahead sequence
70+
/// </returns>
71+
public virtual bool IsGlyphMatchesLookahead(int glyphId, int atIdx) {
72+
return false;
73+
}
74+
75+
/// <summary>Checks if glyph line element matches element from backtrack sequence of the rule.</summary>
76+
/// <param name="glyphId">glyph code id</param>
77+
/// <param name="atIdx">
78+
/// index in rule sequence. Shall be: 0 &lt;= atIdx &lt;
79+
/// <see cref="GetBacktrackContextLength()"/>
80+
/// </param>
81+
/// <returns>
82+
///
83+
/// <see langword="true"/>
84+
/// if glyph matches element from backtrack sequence
85+
/// </returns>
86+
public virtual bool IsGlyphMatchesBacktrack(int glyphId, int atIdx) {
87+
return false;
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)