From 358db6050163de36095bacb47f87c6f9528b8491 Mon Sep 17 00:00:00 2001 From: habbisify Date: Thu, 18 Mar 2021 11:23:42 +0200 Subject: [PATCH 01/23] Implement convertUnit functionality. --- .../pdmodel/PDAbstractContentStream.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index a919475fbf6..088a760ff16 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1674,4 +1674,40 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea return glyphIdsAfterGsub; } + + /** + * Set the text rise value, i.e. move the baseline up or down. This is useful for drawing + * superscripts or subscripts. + * + * @param items + * @param unit_type + * @throws IllegalArgumentException + */ + public List convertUnit(List items, String unit_type) + { + float multiplier = 1; + if (unit_type == "mm") + { + multiplier = 1 / (10 * 2.54f) * 72; + } + else if (unit_type == "inch") + { + multiplier = 72; + } + else + { + throw new IllegalArgumentException( + "could not find the unit type: " + unit_type); + } + List items_new = new ArrayList(); + Iterator it = items.iterator(); + while(it.hasNext()) + { + Float item = it.next(); + item *= multiplier; + items_new.add(item); + } + + return items_new; + } } From b0948061b90d0746578280f763a9fe5b98c2f321 Mon Sep 17 00:00:00 2001 From: Pannimaa Date: Wed, 24 Mar 2021 13:30:55 +0200 Subject: [PATCH 02/23] Documentation for convertUnit() implemented and added "import java.util.Iterator;". --- .../pdfbox/pdmodel/PDAbstractContentStream.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 088a760ff16..07ce3ed82b3 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -29,6 +29,7 @@ import java.util.Deque; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -1676,12 +1677,12 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea } /** - * Set the text rise value, i.e. move the baseline up or down. This is useful for drawing - * superscripts or subscripts. + * Does a length unit conversion from points to millimeters or inches depending on user choice. * - * @param items - * @param unit_type - * @throws IllegalArgumentException + * @param items Items that needs to be converted. + * @param unit_type Specifies desired length unit (mm or inch). + * @throws IllegalArgumentException If desired length unit is not supported. + * @return Items converted to desired unit. */ public List convertUnit(List items, String unit_type) { From 5f047676206a4613fa1378fbd0fb2fb081e39586 Mon Sep 17 00:00:00 2001 From: habbisify Date: Wed, 24 Mar 2021 22:07:31 +0200 Subject: [PATCH 03/23] Comply with coding conventions Use spaces after control flow keywords --- .../java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 07ce3ed82b3..390f42e6b3c 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1702,7 +1702,7 @@ else if (unit_type == "inch") } List items_new = new ArrayList(); Iterator it = items.iterator(); - while(it.hasNext()) + while (it.hasNext()) { Float item = it.next(); item *= multiplier; From 7043519a6465954f6e04a2c0c1d211b82a03f224 Mon Sep 17 00:00:00 2001 From: habbisify Date: Wed, 24 Mar 2021 22:53:44 +0200 Subject: [PATCH 04/23] Comply with the coding conventions Prefer switch statements over multi-clause if-then statements. --- .../pdmodel/PDAbstractContentStream.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 390f42e6b3c..a4ee04304f5 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1687,18 +1687,16 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea public List convertUnit(List items, String unit_type) { float multiplier = 1; - if (unit_type == "mm") - { - multiplier = 1 / (10 * 2.54f) * 72; - } - else if (unit_type == "inch") - { - multiplier = 72; - } - else - { - throw new IllegalArgumentException( - "could not find the unit type: " + unit_type); + switch (unit_type) { + case "mm": + multiplier = 1 / (10 * 2.54f) * 72; + break; + case "inch": + multiplier = 72; + break; + default: + throw new IllegalArgumentException( + "could not find the unit type: " + unit_type); } List items_new = new ArrayList(); Iterator it = items.iterator(); From 73ac4710dad1db7816ed297aa2c6de94aeeafbb7 Mon Sep 17 00:00:00 2001 From: habbisify Date: Wed, 24 Mar 2021 22:55:29 +0200 Subject: [PATCH 05/23] Modify units in-place instead of creating a new list. --- .../pdfbox/pdmodel/PDAbstractContentStream.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index a4ee04304f5..98faade2849 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1684,7 +1684,7 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea * @throws IllegalArgumentException If desired length unit is not supported. * @return Items converted to desired unit. */ - public List convertUnit(List items, String unit_type) + public static final void convertUnit(List items, String unit_type) { float multiplier = 1; switch (unit_type) { @@ -1698,15 +1698,9 @@ public List convertUnit(List items, String unit_type) throw new IllegalArgumentException( "could not find the unit type: " + unit_type); } - List items_new = new ArrayList(); - Iterator it = items.iterator(); - while (it.hasNext()) - { - Float item = it.next(); - item *= multiplier; - items_new.add(item); - } - return items_new; + for (int i=0; i < items.size(); i++) { + items.set(i, items.get(i) * multiplier); + } } } From fbf8b79439e5a8988c958011c22f877a38ddd523 Mon Sep 17 00:00:00 2001 From: habbisify Date: Thu, 25 Mar 2021 10:11:41 +0200 Subject: [PATCH 06/23] Update documentation to correspond the updated implementation. --- .../java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 98faade2849..96f14ce10e8 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -29,7 +29,6 @@ import java.util.Deque; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -1682,7 +1681,6 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea * @param items Items that needs to be converted. * @param unit_type Specifies desired length unit (mm or inch). * @throws IllegalArgumentException If desired length unit is not supported. - * @return Items converted to desired unit. */ public static final void convertUnit(List items, String unit_type) { From 03c8d918b3de0661749d736293ffa351ebbf6966 Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 25 Mar 2021 10:25:33 +0200 Subject: [PATCH 07/23] Add CI/CD --- .github/build.yml | 16 ++++++++++++++ .github/sonar.yml | 22 +++++++++++++++++++ .../pdfbox/pdfwriter/COSWriterTest.java | 3 +++ sonar-project.properties | 2 ++ 4 files changed, 43 insertions(+) create mode 100644 .github/build.yml create mode 100644 .github/sonar.yml create mode 100644 sonar-project.properties diff --git a/.github/build.yml b/.github/build.yml new file mode 100644 index 00000000000..910eb2cf6ab --- /dev/null +++ b/.github/build.yml @@ -0,0 +1,16 @@ +name: Maven build + +on: [push] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build and test with Maven + run: mvn clean install diff --git a/.github/sonar.yml b/.github/sonar.yml new file mode 100644 index 00000000000..fb76dd3b1e2 --- /dev/null +++ b/.github/sonar.yml @@ -0,0 +1,22 @@ +name: Sonarcloud analyze + +on: [push] +jobs: + sonarcloud: + runs-on: ubuntu-latest + environment: sonarcloud + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up JDK 1.11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - name: clean + run: mvn clean + - name: SonarCloud + run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -DskipTests + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java index 2457f5de75f..80fa2e51eea 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java @@ -22,6 +22,9 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.junit.jupiter.api.Test; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + class COSWriterTest { diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000000..0f95e8c1670 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,2 @@ +sonar.organization=habbisify +sonar.projectKey=habbisify_pdfbox From dabb8558d97b66438f27ae09c332f338482a6344 Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 25 Mar 2021 10:30:16 +0200 Subject: [PATCH 08/23] Fix pipeline --- .github/{ => workflows}/build.yml | 0 .github/{ => workflows}/sonar.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/build.yml (100%) rename .github/{ => workflows}/sonar.yml (100%) diff --git a/.github/build.yml b/.github/workflows/build.yml similarity index 100% rename from .github/build.yml rename to .github/workflows/build.yml diff --git a/.github/sonar.yml b/.github/workflows/sonar.yml similarity index 100% rename from .github/sonar.yml rename to .github/workflows/sonar.yml From 1d4037bd45a5dcb55fabd74b88246d8508686048 Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 25 Mar 2021 10:35:54 +0200 Subject: [PATCH 09/23] Fix build --- .../test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java index 80fa2e51eea..2457f5de75f 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java @@ -22,9 +22,6 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.junit.jupiter.api.Test; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - class COSWriterTest { From 5b995c811e3ada730242f6e9b47077cec2ea63fa Mon Sep 17 00:00:00 2001 From: habbisify Date: Thu, 25 Mar 2021 10:59:15 +0200 Subject: [PATCH 10/23] Refactor based on SonarCloud issues. --- .../java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 96f14ce10e8..374a63a92e6 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1682,7 +1682,7 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea * @param unit_type Specifies desired length unit (mm or inch). * @throws IllegalArgumentException If desired length unit is not supported. */ - public static final void convertUnit(List items, String unit_type) + public static final void convertUnit(List items, String unitType) { float multiplier = 1; switch (unit_type) { From e280df222184977fdbc7c53b24b714359cedbb3e Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Wed, 31 Mar 2021 22:44:34 +0300 Subject: [PATCH 11/23] Test commit --- .../pdmodel/TestPDPageContentStream.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index d197a7ae864..a2acf91123e 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; +import java.util.Arrays; import java.util.List; import org.apache.pdfbox.contentstream.operator.Operator; import org.apache.pdfbox.contentstream.operator.OperatorName; @@ -167,4 +168,21 @@ void testCloseContract() throws IOException contentStream.close(); } } + + @Test + void testUnitConversion() throws IOException + { + try (PDDocument doc = new PDDocument()) + { + PDPage page = new PDPage(); + doc.addPage(page); + PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, true); + List items = Arrays.asList(1.0f, 2.4f); + List compareItems = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); + + contentStream.convertUnit(items, "mm"); + assertEquals(compareItems, items); + + } + } } From d8028b2555815935a175108c942079ded41c075e Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Wed, 31 Mar 2021 22:49:42 +0300 Subject: [PATCH 12/23] Fix bug --- .../org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index 374a63a92e6..e16e4f278ba 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1685,7 +1685,7 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea public static final void convertUnit(List items, String unitType) { float multiplier = 1; - switch (unit_type) { + switch (unitType) { case "mm": multiplier = 1 / (10 * 2.54f) * 72; break; @@ -1694,7 +1694,7 @@ public static final void convertUnit(List items, String unitType) break; default: throw new IllegalArgumentException( - "could not find the unit type: " + unit_type); + "could not find the unit type: " + unitType); } for (int i=0; i < items.size(); i++) { From 902d62da4d743de0e7deb22eb27e0da5f4bac32e Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Wed, 31 Mar 2021 22:53:27 +0300 Subject: [PATCH 13/23] Add new testcase --- .../pdfbox/pdmodel/TestPDPageContentStream.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index a2acf91123e..3d6fdff1b61 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -177,11 +177,15 @@ void testUnitConversion() throws IOException PDPage page = new PDPage(); doc.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, true); - List items = Arrays.asList(1.0f, 2.4f); - List compareItems = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); - - contentStream.convertUnit(items, "mm"); - assertEquals(compareItems, items); + List itemsMm = Arrays.asList(1.0f, 2.4f); + List itemsInch = Arrays.asList(1.0f, 2.4f); + List itemsInMm = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); + List itemsInInch = Arrays.asList(1.0f * 72, 2.4f * 72); + + contentStream.convertUnit(itemsMm, "mm"); + contentStream.convertUnit(itemsInch, "inc"); + assertEquals(itemsInMm, itemsMm); + assertEquals(itemsInInch, itemsInch); } } From 371f38fda7ddf4690f4263dfd9ff62b75f0e537c Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 1 Apr 2021 10:45:07 +0300 Subject: [PATCH 14/23] Fix sonarcloud --- .github/workflows/sonar.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index fb76dd3b1e2..13df3422e07 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -16,7 +16,8 @@ jobs: - name: clean run: mvn clean - name: SonarCloud - run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -DskipTests + run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} + # -DskipTests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 2552f94391907bf09265627994cf9ca92220b1aa Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 1 Apr 2021 10:49:48 +0300 Subject: [PATCH 15/23] Fix sonarcloud --- .github/workflows/sonar.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 13df3422e07..fb76dd3b1e2 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -16,8 +16,7 @@ jobs: - name: clean run: mvn clean - name: SonarCloud - run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} - # -DskipTests + run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -DskipTests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 428371115b082d6b2ca556ab76b2d5f6a2896f98 Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Thu, 1 Apr 2021 10:51:26 +0300 Subject: [PATCH 16/23] Test sonarcloud --- .../org/apache/pdfbox/pdmodel/TestPDPageContentStream.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index 3d6fdff1b61..5e332a379bf 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -179,13 +179,13 @@ void testUnitConversion() throws IOException PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, true); List itemsMm = Arrays.asList(1.0f, 2.4f); List itemsInch = Arrays.asList(1.0f, 2.4f); - List itemsInMm = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); + List items_in_Mm = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); List itemsInInch = Arrays.asList(1.0f * 72, 2.4f * 72); contentStream.convertUnit(itemsMm, "mm"); contentStream.convertUnit(itemsInch, "inc"); - assertEquals(itemsInMm, itemsMm); - assertEquals(itemsInInch, itemsInch); + // assertEquals(itemsInMm, itemsMm); + // assertEquals(itemsInInch, itemsInch); } } From 7297e98db851d03fdfaa99b620e4e9452422a38d Mon Sep 17 00:00:00 2001 From: habbisify Date: Thu, 1 Apr 2021 10:55:35 +0300 Subject: [PATCH 17/23] Add documentation to test case --- .../org/apache/pdfbox/pdmodel/TestPDPageContentStream.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index 5e332a379bf..96327566763 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -169,6 +169,11 @@ void testCloseContract() throws IOException } } + /** + * PDFBOX-4073: test implemented choosable coordinate-unitsystem + * + * @throws IOException + */ @Test void testUnitConversion() throws IOException { From 671701240f736e61a85020f8628d73117fc5578d Mon Sep 17 00:00:00 2001 From: Pannimaa <78901870+Pannimaa@users.noreply.github.com> Date: Thu, 1 Apr 2021 11:15:00 +0300 Subject: [PATCH 18/23] Update PDAbstractContentStream.java Documentation fix for convertUnit(). --- .../java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index e16e4f278ba..d8652a38998 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1676,7 +1676,7 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea } /** - * Does a length unit conversion from points to millimeters or inches depending on user choice. + * Does a length unit conversion from millimeters or inches (depending on user choice) to points. * * @param items Items that needs to be converted. * @param unit_type Specifies desired length unit (mm or inch). From 0ccdb18031877b78599d7c86bc39018b56b7fd81 Mon Sep 17 00:00:00 2001 From: DiisseliJoe <47569620+DiisseliJoe@users.noreply.github.com> Date: Thu, 1 Apr 2021 11:36:27 +0300 Subject: [PATCH 19/23] Update PDAbstractContentStream.java --- .../java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java index d8652a38998..6c1a98b1b7d 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDAbstractContentStream.java @@ -1679,7 +1679,7 @@ private List applyGSUBRules(GsubWorker gsubWorker, ByteArrayOutputStrea * Does a length unit conversion from millimeters or inches (depending on user choice) to points. * * @param items Items that needs to be converted. - * @param unit_type Specifies desired length unit (mm or inch). + * @param unit_type Specifies desired length unit (mm or inch) for conversion. * @throws IllegalArgumentException If desired length unit is not supported. */ public static final void convertUnit(List items, String unitType) From 00c4ca1a2a2eeb3d1f9c6ff7ccdbb1283df579f4 Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Sat, 10 Apr 2021 13:37:53 +0300 Subject: [PATCH 20/23] Rewrite the test for unit conversion --- .github/workflows/build.yml | 2 +- .../pdmodel/TestPDPageContentStream.java | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 910eb2cf6ab..958e08da6ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,4 +13,4 @@ jobs: with: java-version: 1.8 - name: Build and test with Maven - run: mvn clean install + run: mvn clean install -DfailIfNoTests=false diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index 96327566763..f611ed2f4c0 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -17,6 +17,7 @@ package org.apache.pdfbox.pdmodel; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.Arrays; @@ -171,27 +172,26 @@ void testCloseContract() throws IOException /** * PDFBOX-4073: test implemented choosable coordinate-unitsystem - * - * @throws IOException + * Checks that unitconversion is done right. + * Arguably the test could be also in some other file */ @Test - void testUnitConversion() throws IOException + void testUnitConversion() { - try (PDDocument doc = new PDDocument()) - { - PDPage page = new PDPage(); - doc.addPage(page); - PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, true); - List itemsMm = Arrays.asList(1.0f, 2.4f); - List itemsInch = Arrays.asList(1.0f, 2.4f); - List items_in_Mm = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); - List itemsInInch = Arrays.asList(1.0f * 72, 2.4f * 72); - - contentStream.convertUnit(itemsMm, "mm"); - contentStream.convertUnit(itemsInch, "inc"); - // assertEquals(itemsInMm, itemsMm); - // assertEquals(itemsInInch, itemsInch); - - } + List itemsMm = Arrays.asList(1.0f, 2.4f); + List itemsInch = Arrays.asList(1.0f, 2.4f); + List itemsInMm = Arrays.asList(1.0f /(10 * 2.54f) * 72, 2.4f /(10 * 2.54f) * 72); + List itemsInInch = Arrays.asList(1.0f * 72, 2.4f * 72); + + PDAbstractContentStream.convertUnit(itemsMm, "mm"); + PDAbstractContentStream.convertUnit(itemsInch, "inc"); + // Should be converted to millimeters + assertEquals(itemsInMm, itemsMm); + // Should be converted to inches + assertEquals(itemsInInch, itemsInch); + // Should throw IllegalArgumentException if the unit is not valid + assertThrows(IllegalArgumentException.class, () -> { + PDAbstractContentStream.convertUnit(itemsMm, "invalid_unit"); + }); } } From 5cbd52b2117043cb1eec3912a3e053f29adb3ada Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Sat, 10 Apr 2021 14:12:13 +0300 Subject: [PATCH 21/23] Improve pipelines --- .github/workflows/build.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 958e08da6ea..0ea9f4d80b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Maven build on: [push] jobs: - build-and-test: + build: runs-on: ubuntu-latest steps: @@ -12,5 +12,19 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 - - name: Build and test with Maven - run: mvn clean install -DfailIfNoTests=false + - name: Build with Maven + run: mvn clean install -DskipTests + + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Test with Maven + run: mvn test + + \ No newline at end of file From f7e858bb3acb0b6e50ef83f39dc5bdf3e3197f8a Mon Sep 17 00:00:00 2001 From: Vilho Aaltonen Date: Sat, 10 Apr 2021 14:25:06 +0300 Subject: [PATCH 22/23] Fix typo --- .../java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java index f611ed2f4c0..0c19c521e66 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java @@ -184,7 +184,7 @@ void testUnitConversion() List itemsInInch = Arrays.asList(1.0f * 72, 2.4f * 72); PDAbstractContentStream.convertUnit(itemsMm, "mm"); - PDAbstractContentStream.convertUnit(itemsInch, "inc"); + PDAbstractContentStream.convertUnit(itemsInch, "inch"); // Should be converted to millimeters assertEquals(itemsInMm, itemsMm); // Should be converted to inches From 05e88d74877fc9b2b30ab8584ad793de637e6c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20Sepp=C3=A4l=C3=A4?= Date: Sat, 10 Apr 2021 16:50:55 +0300 Subject: [PATCH 23/23] Remove irrelevant files from the pr. --- .github/workflows/build.yml | 30 ------------------------------ .github/workflows/sonar.yml | 22 ---------------------- sonar-project.properties | 2 -- 3 files changed, 54 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/sonar.yml delete mode 100644 sonar-project.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 0ea9f4d80b5..00000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Maven build - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Build with Maven - run: mvn clean install -DskipTests - - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Test with Maven - run: mvn test - - \ No newline at end of file diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml deleted file mode 100644 index fb76dd3b1e2..00000000000 --- a/.github/workflows/sonar.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Sonarcloud analyze - -on: [push] -jobs: - sonarcloud: - runs-on: ubuntu-latest - environment: sonarcloud - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Set up JDK 1.11 - uses: actions/setup-java@v1 - with: - java-version: 1.11 - - name: clean - run: mvn clean - - name: SonarCloud - run: mvn -B verify sonar:sonar -Dsonar.projectKey=habbisify_pdfbox -Dsonar.organization=habbisify -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -DskipTests - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 0f95e8c1670..00000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,2 +0,0 @@ -sonar.organization=habbisify -sonar.projectKey=habbisify_pdfbox