Skip to content

Commit

Permalink
(#116) Remove Resources from DefaultPage constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jan 16, 2024
1 parent 1d557c3 commit e6265d2
Show file tree
Hide file tree
Showing 29 changed files with 159 additions and 147 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/github/fabriciofx/cactoos/pdf/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.github.fabriciofx.cactoos.pdf;

import java.util.List;

/**
* Content.
*
Expand All @@ -37,4 +39,11 @@ public interface Content extends Object {
* @throws Exception if fails
*/
byte[] asStream() throws Exception;

/**
* Resource content.
*
* @return The resource if there is one
*/
List<Resource> resource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@

import com.github.fabriciofx.cactoos.pdf.Content;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Name;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import org.cactoos.io.OutputTo;
import org.cactoos.io.TeeInput;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.LengthOf;

/**
Expand Down Expand Up @@ -78,6 +81,11 @@ public byte[] asStream() throws Exception {
return baos.toByteArray();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/com/github/fabriciofx/cactoos/pdf/content/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@
import com.github.fabriciofx.cactoos.pdf.Content;
import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Format;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.resource.XObject;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
import org.cactoos.Scalar;
import org.cactoos.list.ListOf;
import org.cactoos.text.FormattedText;
import org.cactoos.text.UncheckedText;

Expand All @@ -44,15 +48,20 @@
*/
public final class Image implements Content {
/**
* Id.
* Number.
*/
private final int id;
private final int num;

/**
* Generation.
*/
private final int generation;

/**
* Id.
*/
private final Id id;

/**
* Image Format.
*/
Expand Down Expand Up @@ -96,6 +105,7 @@ public Image(
this(
id.increment(),
0,
id,
format,
posx,
posy,
Expand Down Expand Up @@ -126,6 +136,7 @@ public Image(
this(
id.increment(),
0,
id,
format,
posx,
posy,
Expand All @@ -137,8 +148,9 @@ public Image(
/**
* Ctor.
*
* @param id Id number
* @param num Object number
* @param generation Generation number
* @param id Id
* @param format Raw image format
* @param posx Position X
* @param posy Position Y
Expand All @@ -147,16 +159,18 @@ public Image(
* @checkstyle ParameterNumberCheck (10 lines)
*/
public Image(
final int id,
final int num,
final int generation,
final Id id,
final Format format,
final double posx,
final double posy,
final Scalar<Double> width,
final Scalar<Double> height
) {
this.id = id;
this.num = num;
this.generation = generation;
this.id = id;
this.fmt = format;
this.posx = posx;
this.posy = posy;
Expand All @@ -170,7 +184,7 @@ public Image(
* @return The image name
*/
public String name() {
return new UncheckedText(new FormattedText("I%d", this.id)).asString();
return new UncheckedText(new FormattedText("I%d", this.num)).asString();
}

@Override
Expand All @@ -186,13 +200,18 @@ public byte[] asStream() throws Exception {
).asString().getBytes(StandardCharsets.UTF_8);
}

@Override
public List<Resource> resource() {
return new ListOf<>(new XObject(this.id, this));
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
.add("Length", new Int(stream.length))
.with(new Stream(stream));
return new DefaultIndirect(this.id, this.generation, dictionary);
return new DefaultIndirect(this.num, this.generation, dictionary);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@

import com.github.fabriciofx.cactoos.pdf.Content;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.page.Format;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.cactoos.list.ListOf;
import org.cactoos.text.FormattedText;

/**
Expand Down Expand Up @@ -121,6 +124,11 @@ public byte[] asStream() throws Exception {
return stream.toString().getBytes(StandardCharsets.UTF_8);
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}

@Override
public Indirect indirect() throws Exception {
final Indirect indirect = this.origin.indirect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import com.github.fabriciofx.cactoos.pdf.Font;
import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.text.Escaped;
import com.github.fabriciofx.cactoos.pdf.text.Multiline;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
import org.cactoos.list.ListOf;
import org.cactoos.text.FormattedText;

/**
Expand Down Expand Up @@ -233,6 +236,11 @@ public byte[] asStream() throws Exception {
).asString().getBytes(StandardCharsets.UTF_8);
}

@Override
public List<Resource> resource() {
return new ListOf<>(this.typeface);
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Format;
import com.github.fabriciofx.cactoos.pdf.image.Header;
import com.github.fabriciofx.cactoos.pdf.image.Raw;
Expand All @@ -37,7 +38,9 @@
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import org.cactoos.Bytes;
import org.cactoos.list.ListOf;

/**
* PNG.
Expand Down Expand Up @@ -111,4 +114,9 @@ public Indirect indirect() throws Exception {
public byte[] asStream() throws Exception {
return this.raw.body().asStream();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Format;
import com.github.fabriciofx.cactoos.pdf.image.Header;
import com.github.fabriciofx.cactoos.pdf.image.Palette;
Expand All @@ -40,7 +41,9 @@
import com.github.fabriciofx.cactoos.pdf.type.Text;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import org.cactoos.Bytes;
import org.cactoos.list.ListOf;

/**
* PNG.
Expand Down Expand Up @@ -137,4 +140,9 @@ public Indirect indirect() throws Exception {
public byte[] asStream() throws Exception {
return this.raw.body().asStream();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Body;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.util.List;
import org.cactoos.Bytes;
import org.cactoos.list.ListOf;

/**
* JpegBody.
Expand Down Expand Up @@ -81,6 +84,11 @@ public byte[] asStream() throws Exception {
return this.bytes.asBytes();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@

import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Body;
import com.github.fabriciofx.cactoos.pdf.image.Flow;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import org.cactoos.Bytes;
import org.cactoos.Scalar;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.Sticky;

/**
Expand Down Expand Up @@ -114,6 +117,11 @@ public byte[] asStream() throws Exception {
return this.bytes.value();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@

import com.github.fabriciofx.cactoos.pdf.Id;
import com.github.fabriciofx.cactoos.pdf.Indirect;
import com.github.fabriciofx.cactoos.pdf.Resource;
import com.github.fabriciofx.cactoos.pdf.image.Flow;
import com.github.fabriciofx.cactoos.pdf.image.Palette;
import com.github.fabriciofx.cactoos.pdf.indirect.DefaultIndirect;
import com.github.fabriciofx.cactoos.pdf.type.Dictionary;
import com.github.fabriciofx.cactoos.pdf.type.Int;
import com.github.fabriciofx.cactoos.pdf.type.Stream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import org.cactoos.Bytes;
import org.cactoos.Scalar;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.Sticky;

/**
Expand Down Expand Up @@ -113,6 +116,11 @@ public byte[] asStream() throws Exception {
return this.bytes.value();
}

@Override
public List<Resource> resource() {
return new ListOf<>();
}

@Override
public Indirect indirect() throws Exception {
final byte[] stream = this.asStream();
Expand Down
Loading

0 comments on commit e6265d2

Please sign in to comment.