-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd9aad8
commit c87a68b
Showing
4 changed files
with
267 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/github/fabriciofx/cactoos/pdf/page/Rotate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (C) 2023 Fabrício Barros Cabral | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package com.github.fabriciofx.cactoos.pdf.page; | ||
|
||
import com.github.fabriciofx.cactoos.pdf.Page; | ||
import com.github.fabriciofx.cactoos.pdf.Pages; | ||
import com.github.fabriciofx.cactoos.pdf.content.Contents; | ||
import com.github.fabriciofx.cactoos.pdf.resource.Resources; | ||
import java.io.ByteArrayOutputStream; | ||
import org.cactoos.text.FormattedText; | ||
import org.cactoos.text.UncheckedText; | ||
|
||
/** | ||
* Rotate a Page in a angle. | ||
* | ||
* @since 0.0.1 | ||
*/ | ||
public final class Rotate implements Page { | ||
/** | ||
* The Page. | ||
*/ | ||
private final Page origin; | ||
|
||
/** | ||
* Angle. | ||
*/ | ||
private final int angle; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param page The Page | ||
* @param angle The angle | ||
*/ | ||
public Rotate(final Page page, final int angle) { | ||
this.origin = page; | ||
this.angle = angle; | ||
} | ||
|
||
@Override | ||
public String reference() { | ||
return this.origin.reference(); | ||
} | ||
|
||
@Override | ||
public String dictionary(final Pages parent) { | ||
return new UncheckedText( | ||
new FormattedText( | ||
"%s /Rotate %d", | ||
this.origin.dictionary(parent), | ||
this.angle | ||
) | ||
).asString(); | ||
} | ||
|
||
@Override | ||
public Resources resources() { | ||
return this.origin.resources(); | ||
} | ||
|
||
@Override | ||
public Contents contents() { | ||
return this.origin.contents(); | ||
} | ||
|
||
@Override | ||
public byte[] with(final Pages parent) throws Exception { | ||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
baos.write( | ||
new FormattedText( | ||
"%s obj\n<< %s >>\nendobj\n", | ||
this.origin.reference().replaceAll(" R", ""), | ||
this.dictionary(parent) | ||
).asString().getBytes() | ||
); | ||
baos.write(this.resources().asBytes()); | ||
baos.write(this.contents().asBytes()); | ||
return baos.toByteArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters