Skip to content

Investigate RSyntaxTextArea for RUPS #155

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<itext.version>9.1.0</itext.version>
<jackson.version>2.18.3</jackson.version>
<logback.version>1.5.18</logback.version>
<rsyntaxtextarea.version>3.6.0</rsyntaxtextarea.version>
<rstaui.version>3.3.1</rstaui.version>

<!-- Test dependencies -->
<junit-jupiter-api.version>5.12.0</junit-jupiter-api.version>
Expand Down Expand Up @@ -134,6 +136,16 @@
<artifactId>flatlaf</artifactId>
<version>${flatlaf.version}</version>
</dependency>
<dependency>
<groupId>com.fifesoft</groupId>
<artifactId>rsyntaxtextarea</artifactId>
<version>${rsyntaxtextarea.version}</version>
</dependency>
<dependency>
<groupId>com.fifesoft</groupId>
<artifactId>rstaui</artifactId>
<version>${rstaui.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdftest</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/itextpdf/rups/Rups.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ This file is part of the iText (R) project.
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -94,6 +95,13 @@ public static void showBriefMessage(String message) {
*/
public static void startNewApplication(final List<File> files) {
SwingUtilities.invokeLater(() -> {
/*
* While we get the locale explicitly for our localized strings,
* some of the 3rd party Swings components use the default locale
* for string (ex. RSyntaxTextArea). So we need to change the
* default locale for everything to look consistent.
*/
Locale.setDefault(RupsConfiguration.INSTANCE.getUserLocale());
setLookandFeel();
final IRupsController rupsController = initApplication(new JFrame());
setOpenFileHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ This file is part of the iText (R) project.
import com.itextpdf.rups.view.itext.PdfObjectPanel;
import com.itextpdf.rups.view.itext.PdfTree;
import com.itextpdf.rups.view.itext.PlainText;
import com.itextpdf.rups.view.itext.stream.StreamPane;
import com.itextpdf.rups.view.itext.StructureTree;
import com.itextpdf.rups.view.itext.SyntaxHighlightedStreamPane;
import com.itextpdf.rups.view.itext.XRefTable;
import com.itextpdf.rups.view.itext.treenodes.PdfObjectTreeNode;

Expand Down Expand Up @@ -135,7 +135,7 @@ public class PdfReaderController implements IPdfObjectPanelEventListener, IRupsE
/**
* A panel that will show a stream.
*/
protected SyntaxHighlightedStreamPane streamPane;
protected StreamPane streamPane;

/**
* The factory producing tree nodes.
Expand Down Expand Up @@ -205,7 +205,7 @@ public PdfReaderController(TreeSelectionListener treeSelectionListener,

objectPanel = new PdfObjectPanel();
objectPanel.addEventListener(this);
streamPane = new SyntaxHighlightedStreamPane(this);
streamPane = new StreamPane(this);
JScrollPane debug = new JScrollPane(DebugView.getInstance().getTextArea());
editorTabs = new JTabbedPane();
editorTabs.addTab(Language.STREAM.getString(), null, streamPane, Language.STREAM.getString());
Expand Down Expand Up @@ -255,16 +255,6 @@ public JTabbedPane getEditorTabs() {
return editorTabs;
}

/**
* Getter for the object that holds the TextPane
* with the content stream of a PdfStream object.
*
* @return a SyntaxHighlightedStreamPane
*/
public SyntaxHighlightedStreamPane getStreamPane() {
return streamPane;
}

public PdfSyntaxParser getParser() {
return parser;
}
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/com/itextpdf/rups/model/PdfStreamUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
APRYSE GROUP. APRYSE GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://itextpdf.com/terms-of-use/

The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.

In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using iText.

You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the iText software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping iText with a closed
source product.

For more information, please contact iText Software Corp. at this
address: [email protected]
*/
package com.itextpdf.rups.model;

import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfStream;
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
import com.itextpdf.rups.view.Language;

import java.awt.image.BufferedImage;
import java.io.IOException;

/**
* Static utility class for getting information on PDF streams.
*/
public final class PdfStreamUtil {
private PdfStreamUtil() {
// static class
}

public static BufferedImage getAsImage(PdfStream stream) {
if (!isImage(stream)) {
return null;
}
final PdfImageXObject xObject = new PdfImageXObject(stream);
try {
return xObject.getBufferedImage();
} catch (IOException e) {
LoggerHelper.warn(Language.ERROR_PARSING_IMAGE.getString(), e, PdfStreamUtil.class);
return null;
}
}

public static boolean isImage(PdfStream stream) {
/*
* We will consider stream being an image, if it has /Width and
* /Height number fields present and /Subtype is /Image.
*
* This could skip thumbnail images, as those do not require the
* /Subtype field being there.
*/
return PdfName.Image.equals(stream.getAsName(PdfName.Subtype))
&& (stream.getAsNumber(PdfName.Width) != null)
&& (stream.getAsNumber(PdfName.Height) != null);
}

public static boolean isFont(PdfStream stream) {
/*
* For now just checking, that there is a /Length1 field present. It
* is required for Type 1 and TrueType fonts.
*/
return stream.containsKey(PdfName.Length1);
}
}
Loading