提交 9761b5f2 编写于 作者: S serge-rider

#649 SVG format: add SVG feature and Batik deps


Former-commit-id: 41ded4fc
上级 2307f34b
......@@ -2,7 +2,7 @@
<feature
id="org.jkiss.dbeaver.ext.office.feature"
label="%featureName"
version="1.1.0"
version="1.1.1"
provider-name="%providerName"
plugin="org.jkiss.dbeaver.data.office">
......
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.ext.ui.svg.feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>
bin.includes = feature.xml,\
feature.properties
featureName=DBeaver Office Extension
providerName=JKISS
description=DBeaver Office Extension
copyright=2017, Serge Rider
license=\
Apache License\n\
Version 2.0, January 2004\n\
http://www.apache.org/licenses/\n\
\n\
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\
\n\
1. Definitions.\n\
\n\
"License" shall mean the terms and conditions for use, reproduction,\n\
and distribution as defined by Sections 1 through 9 of this document.\n\
\n\
"Licensor" shall mean the copyright owner or entity authorized by\n\
the copyright owner that is granting the License.\n\
\n\
"Legal Entity" shall mean the union of the acting entity and all\n\
other entities that control, are controlled by, or are under common\n\
control with that entity. For the purposes of this definition,\n\
"control" means (i) the power, direct or indirect, to cause the\n\
direction or management of such entity, whether by contract or\n\
otherwise, or (ii) ownership of fifty percent (50%) or more of the\n\
outstanding shares, or (iii) beneficial ownership of such entity.\n\
\n\
"You" (or "Your") shall mean an individual or Legal Entity\n\
exercising permissions granted by this License.\n\
\n\
"Source" form shall mean the preferred form for making modifications,\n\
including but not limited to software source code, documentation\n\
source, and configuration files.\n\
\n\
"Object" form shall mean any form resulting from mechanical\n\
transformation or translation of a Source form, including but\n\
not limited to compiled object code, generated documentation,\n\
and conversions to other media types.\n\
\n\
"Work" shall mean the work of authorship, whether in Source or\n\
Object form, made available under the License, as indicated by a\n\
copyright notice that is included in or attached to the work\n\
(an example is provided in the Appendix below).\n\
\n\
"Derivative Works" shall mean any work, whether in Source or Object\n\
form, that is based on (or derived from) the Work and for which the\n\
editorial revisions, annotations, elaborations, or other modifications\n\
represent, as a whole, an original work of authorship. For the purposes\n\
of this License, Derivative Works shall not include works that remain\n\
separable from, or merely link (or bind by name) to the interfaces of,\n\
the Work and Derivative Works thereof.\n\
\n\
"Contribution" shall mean any work of authorship, including\n\
the original version of the Work and any modifications or additions\n\
to that Work or Derivative Works thereof, that is intentionally\n\
submitted to Licensor for inclusion in the Work by the copyright owner\n\
or by an individual or Legal Entity authorized to submit on behalf of\n\
the copyright owner. For the purposes of this definition, "submitted"\n\
means any form of electronic, verbal, or written communication sent\n\
to the Licensor or its representatives, including but not limited to\n\
communication on electronic mailing lists, source code control systems,\n\
and issue tracking systems that are managed by, or on behalf of, the\n\
Licensor for the purpose of discussing and improving the Work, but\n\
excluding communication that is conspicuously marked or otherwise\n\
designated in writing by the copyright owner as "Not a Contribution."\n\
\n\
"Contributor" shall mean Licensor and any individual or Legal Entity\n\
on behalf of whom a Contribution has been received by Licensor and\n\
subsequently incorporated within the Work.\n\
\n\
2. Grant of Copyright License. Subject to the terms and conditions of\n\
this License, each Contributor hereby grants to You a perpetual,\n\
worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\
copyright license to reproduce, prepare Derivative Works of,\n\
publicly display, publicly perform, sublicense, and distribute the\n\
Work and such Derivative Works in Source or Object form.\n\
\n\
3. Grant of Patent License. Subject to the terms and conditions of\n\
this License, each Contributor hereby grants to You a perpetual,\n\
worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\
(except as stated in this section) patent license to make, have made,\n\
use, offer to sell, sell, import, and otherwise transfer the Work,\n\
where such license applies only to those patent claims licensable\n\
by such Contributor that are necessarily infringed by their\n\
Contribution(s) alone or by combination of their Contribution(s)\n\
with the Work to which such Contribution(s) was submitted. If You\n\
institute patent litigation against any entity (including a\n\
cross-claim or counterclaim in a lawsuit) alleging that the Work\n\
or a Contribution incorporated within the Work constitutes direct\n\
or contributory patent infringement, then any patent licenses\n\
granted to You under this License for that Work shall terminate\n\
as of the date such litigation is filed.\n\
\n\
4. Redistribution. You may reproduce and distribute copies of the\n\
Work or Derivative Works thereof in any medium, with or without\n\
modifications, and in Source or Object form, provided that You\n\
meet the following conditions:\n\
\n\
(a) You must give any other recipients of the Work or\n\
Derivative Works a copy of this License; and\n\
\n\
(b) You must cause any modified files to carry prominent notices\n\
stating that You changed the files; and\n\
\n\
(c) You must retain, in the Source form of any Derivative Works\n\
that You distribute, all copyright, patent, trademark, and\n\
attribution notices from the Source form of the Work,\n\
excluding those notices that do not pertain to any part of\n\
the Derivative Works; and\n\
\n\
(d) If the Work includes a "NOTICE" text file as part of its\n\
distribution, then any Derivative Works that You distribute must\n\
include a readable copy of the attribution notices contained\n\
within such NOTICE file, excluding those notices that do not\n\
pertain to any part of the Derivative Works, in at least one\n\
of the following places: within a NOTICE text file distributed\n\
as part of the Derivative Works; within the Source form or\n\
documentation, if provided along with the Derivative Works; or,\n\
within a display generated by the Derivative Works, if and\n\
wherever such third-party notices normally appear. The contents\n\
of the NOTICE file are for informational purposes only and\n\
do not modify the License. You may add Your own attribution\n\
notices within Derivative Works that You distribute, alongside\n\
or as an addendum to the NOTICE text from the Work, provided\n\
that such additional attribution notices cannot be construed\n\
as modifying the License.\n\
\n\
You may add Your own copyright statement to Your modifications and\n\
may provide additional or different license terms and conditions\n\
for use, reproduction, or distribution of Your modifications, or\n\
for any such Derivative Works as a whole, provided Your use,\n\
reproduction, and distribution of the Work otherwise complies with\n\
the conditions stated in this License.\n\
\n\
5. Submission of Contributions. Unless You explicitly state otherwise,\n\
any Contribution intentionally submitted for inclusion in the Work\n\
by You to the Licensor shall be under the terms and conditions of\n\
this License, without any additional terms or conditions.\n\
Notwithstanding the above, nothing herein shall supersede or modify\n\
the terms of any separate license agreement you may have executed\n\
with Licensor regarding such Contributions.\n\
\n\
6. Trademarks. This License does not grant permission to use the trade\n\
names, trademarks, service marks, or product names of the Licensor,\n\
except as required for reasonable and customary use in describing the\n\
origin of the Work and reproducing the content of the NOTICE file.\n\
\n\
7. Disclaimer of Warranty. Unless required by applicable law or\n\
agreed to in writing, Licensor provides the Work (and each\n\
Contributor provides its Contributions) on an "AS IS" BASIS,\n\
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n\
implied, including, without limitation, any warranties or conditions\n\
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n\
PARTICULAR PURPOSE. You are solely responsible for determining the\n\
appropriateness of using or redistributing the Work and assume any\n\
risks associated with Your exercise of permissions under this License.\n\
\n\
8. Limitation of Liability. In no event and under no legal theory,\n\
whether in tort (including negligence), contract, or otherwise,\n\
unless required by applicable law (such as deliberate and grossly\n\
negligent acts) or agreed to in writing, shall any Contributor be\n\
liable to You for damages, including any direct, indirect, special,\n\
incidental, or consequential damages of any character arising as a\n\
result of this License or out of the use or inability to use the\n\
Work (including but not limited to damages for loss of goodwill,\n\
work stoppage, computer failure or malfunction, or any and all\n\
other commercial damages or losses), even if such Contributor\n\
has been advised of the possibility of such damages.\n\
\n\
9. Accepting Warranty or Additional Liability. While redistributing\n\
the Work or Derivative Works thereof, You may choose to offer,\n\
and charge a fee for, acceptance of support, warranty, indemnity,\n\
or other liability obligations and/or rights consistent with this\n\
License. However, in accepting such obligations, You may act only\n\
on Your own behalf and on Your sole responsibility, not on behalf\n\
of any other Contributor, and only if You agree to indemnify,\n\
defend, and hold each Contributor harmless for any liability\n\
incurred by, or claims asserted against, such Contributor by reason\n\
of your accepting any such warranty or additional liability.\n\
\n\
END OF TERMS AND CONDITIONS
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.jkiss.dbeaver.ext.ui.svg.feature"
label="%featureName"
version="1.0.0"
provider-name="%providerName"
plugin="org.jkiss.dbeaver.ext.ui.svg">
<description>
%description
</description>
<copyright>
%copyright
</copyright>
<license url="%licenseURL">
%license
</license>
<plugin
id="org.jkiss.dbeaver.ext.ui.svg"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.apache.xmlgraphics.batik-svggen"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>dbeaver</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.ext.office.feature</artifactId>
<version>1.1.0</version>
<packaging>eclipse-feature</packaging>
<groupId>org.jkiss.dbeaver</groupId>
</project>
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Office data formats support
Bundle-SymbolicName: org.jkiss.dbeaver.data.office;singleton:=true
Bundle-Version: 1.1.0
Bundle-Version: 1.1.1
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.jkiss.dbeaver.core,
org.jkiss.dbeaver.model,
......
......@@ -10,7 +10,7 @@
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.data.office</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>eclipse-plugin</packaging>
<!--
......
......@@ -18,7 +18,9 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Vendor: JKISS
Bundle-ClassPath: .
Bundle-Localization: plugin
Export-Package: org.jkiss.dbeaver.ext.erd.model,
org.jkiss.dbeaver.ext.erd.part,
org.jkiss.dbeaver.ext.erd.figres,
org.jkiss.dbeaver.ext.erd.export
Export-Package: org.jkiss.dbeaver.ext.erd,
org.jkiss.dbeaver.ext.erd.editor,
org.jkiss.dbeaver.ext.erd.export,
org.jkiss.dbeaver.ext.erd.figures,
org.jkiss.dbeaver.ext.erd.model,
org.jkiss.dbeaver.ext.erd.part
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.jkiss.dbeaver.ext.ui.svg</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SVG format support
Bundle-SymbolicName: org.jkiss.dbeaver.ext.ui.svg;singleton:=true
Bundle-Version: 1.0.0
Bundle-Vendor: JKISS
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.gef,
org.jkiss.dbeaver.core,
org.jkiss.dbeaver.ext.erd,
org.apache.xmlgraphics.batik-svggen;bundle-version="1.9.1",
org.apache.xmlgraphics.batik-awt-util;bundle-version="1.9.1"
Bundle-ActivationPolicy: lazy
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<plugin>
<extension point="org.jkiss.dbeaver.ext.erd.export.format">
<exportFormat ext="svg" label="SVG format" class="org.jkiss.dbeaver.ext.ui.svg.ERDExportSVG"/>
</extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>dbeaver</artifactId>
<version>1.0.0</version>
<relativePath>../../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.ext.ui.svg</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>
</project>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.ui.svg;
import org.apache.batik.svggen.SVGGraphics2D;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.Rectangle;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.erd.export.ERDExportFormatHandler;
import org.jkiss.dbeaver.ext.erd.model.EntityDiagram;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.runtime.ui.DBUserInterface;
import org.jkiss.utils.xml.XMLUtils;
import org.w3c.dom.Document;
import java.io.File;
/**
* SVG exporter
*/
public class ERDExportSVG implements ERDExportFormatHandler
{
private static final Log log = Log.getLog(ERDExportSVG.class);
@Override
public void exportDiagram(EntityDiagram diagram, IFigure diagramFigure, DiagramPart diagramPart, File targetFile) throws DBException {
try {
IFigure figure = diagramPart.getFigure();
Rectangle contentBounds = figure instanceof FreeformLayeredPane ? ((FreeformLayeredPane) figure).getFreeformExtent() : figure.getBounds();
String svgNS = "http://www.w3.org/2000/svg";
Document document = XMLUtils.createDocument();//domImpl.createDocument(svgNS, "svg", null);
document.createAttributeNS(svgNS, "svg");
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// We need a converter from Draw2D.Graphics (GEF) to awt.Graphics2D (Batik)
Graphics graphics = new GraphicsToGraphics2DAdaptor(svgGenerator);
// Reset origin to make it the top/left most part of the diagram
graphics.translate(contentBounds.x * -1, contentBounds.y * -1);
paintDiagram(graphics, figure);
svgGenerator.stream(targetFile.getAbsolutePath());
} catch (Exception e) {
DBUserInterface.getInstance().showError("Save ERD as SVG", null, e);
}
}
/** Paints the figure onto the given graphics */
public static void paintDiagram(Graphics g, IFigure figure)
{
// Store state, so modified state of Graphics (while painting children) can be easily restored
g.pushState();
try
{
IClippingStrategy clippingStrategy = figure.getClippingStrategy();
// Iterate over the children to check whether a child is a(nother) layer or an actual figure
// Not painting the layers themselves is likely to get rid of borders and graphics settings that are not
// supported (like Graphics#setTextAntiAliassing())
for (Object childObject : figure.getChildren())
{
if (childObject instanceof Layer)
{
// Found another layer, process it to search for actual figures
paintDiagram(g, (IFigure) childObject);
}
else
{
// Found something to draw
// Use same/similar method as being using in Figure#paintChildren() in order to get clipping right
IFigure child = (IFigure) childObject;
if (child.isVisible())
{
// determine clipping areas for child
Rectangle[] clipping = null;
if (clippingStrategy != null)
{
clipping = clippingStrategy.getClip(child);
}
else
{
// default clipping behaviour is to clip at bounds
clipping = new Rectangle[] { child.getBounds() };
}
// child may now paint inside the clipping areas
for (int j = 0; j < clipping.length; j++)
{
if (clipping[j].intersects(g.getClip(Rectangle.SINGLETON)))
{
g.clipRect(clipping[j]);
child.paint(g);
g.restoreState();
}
}
}
}
}
} finally
{
// Always pop the state again to prevent problems
g.popState();
}
}
}
/******************************************************************************
* Copyright (c) 2003, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* SAP AG - copied the class from GMF runtime since Graphiti can not have a dependency to GMF
****************************************************************************/
package org.jkiss.dbeaver.ext.ui.svg;
import java.awt.Font;
/**
* Represents a font on the system. There may be multiple fonts created in the system at any one time. The currently
* selected font can be retrieved from the DeviceContext.
*
* @author dhabib
*
*/
public class GdiFont
{
private int m_height = 12;
private boolean m_bItalic = false;
private boolean m_bUnderlined = false;
private boolean m_bBold = false;
private boolean m_bStrikeout = false;
private String m_faceName = "SanSerif"; //$NON-NLS-1$
private int m_escapement = 0;
/**
* Creates a default font.
*/
public GdiFont()
{
// Nothing to initialize.
}
/**
* Copy constructor
*
* @param font
*/
GdiFont(GdiFont font)
{
m_height = font.m_height;
m_bItalic = font.m_bItalic;
m_bBold = font.m_bBold;
m_faceName = font.m_faceName;
m_bUnderlined = font.m_bUnderlined;
m_escapement = font.m_escapement;
m_bStrikeout = font.m_bStrikeout;
}
/**
* Creates a font with the specified parameters.
*
* @param height Height of the font
* @param bItalic Whether or not the font is italic
* @param bUnderlined Whether or not the font is underlined
* @param bStrikeout Whether or not the font is a strikout font
* @param bBold Whether or not the font is bold
* @param faceName Name of the font
* @param escapement Font escapement (angle) of the text to be drawn.
*/
public GdiFont(int height, boolean bItalic, boolean bUnderlined, boolean bStrikeout, boolean bBold,
String faceName, int escapement)
{
m_height = height;
m_bItalic = bItalic;
m_bBold = bBold;
m_faceName = faceName;
m_bUnderlined = bUnderlined;
m_escapement = escapement;
m_bStrikeout = bStrikeout;
}
/**
* @return The Java font object that represents most of the attributes for drawing the font.
*/
public Font getFont()
{
int style = Font.PLAIN;
if (m_bItalic)
{
style = Font.ITALIC;
}
if (m_bBold)
{
style = Font.BOLD;
}
if (m_bItalic && m_bBold)
{
style = Font.ITALIC + Font.BOLD;
}
return new Font(m_faceName, style, m_height);
}
/**
* @return The angle at which to draw the font.
*/
public int getEscapement()
{
return m_escapement;
}
}
/******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* SAP AG - copied class from GMF runtime since Graphiti can not have a dependency to GMF
* uses GraphitiUiInternal.getWorkbenchService() instead of
* GMF's DisplayUtils
****************************************************************************/
package org.jkiss.dbeaver.ext.ui.svg;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
/**
* This is a helper class used to convert an SWT Image into an AWT BufferedImage.
*
* This class is originally from GMF and was adapted for Graphiti needs.
*
*/
public class ImageConverter
{
private static final PaletteData PALETTE_DATA = new PaletteData(0xFF0000, 0xFF00, 0xFF);
/**
* Converts an AWT based buffered image into an SWT <code>Image</code>. This will always return an
* <code>Image</code> that has 24 bit depth regardless of the type of AWT buffered image that is passed into the
* method.
*
* @param srcImage the {@link java.awt.image.BufferedImage} to be converted to an <code>Image</code>
* @return an <code>Image</code> that represents the same image data as the AWT <code>BufferedImage</code> type.
*/
public static Image convert(BufferedImage srcImage)
{
return new Image(Display.getCurrent(), convertToImageData(srcImage));
}
/**
* Converts an AWT based buffered image into an SWT <code>ImageData</code>. This will always return an
* <code>ImageData</code> that has 24 bit depth regardless of the type of AWT buffered image that is passed into the
* method.
*
* @param srcImage the {@link java.awt.image.BufferedImage} to be converted to an <code>Image</code>
* @return an <code>Image</code> that represents the same image data as the AWT <code>BufferedImage</code> type.
*
* @since 1.3.1
*/
public static ImageData convertToImageData(BufferedImage srcImage)
{
// We can force bitdepth to be 24 bit because BufferedImage getRGB
// allows us to always retrieve 24 bit data regardless of source color depth.
ImageData swtImageData = new ImageData(srcImage.getWidth(), srcImage.getHeight(), 24, PALETTE_DATA);
// ensure scansize is aligned on 32 bit.
int scansize = (((srcImage.getWidth() * 3) + 3) * 4) / 4;
WritableRaster alphaRaster = srcImage.getAlphaRaster();
byte[] alphaBytes = new byte[srcImage.getWidth()];
for (int y = 0; y < srcImage.getHeight(); y++)
{
int[] buff = srcImage.getRGB(0, y, srcImage.getWidth(), 1, null, 0, scansize);
swtImageData.setPixels(0, y, srcImage.getWidth(), buff, 0);
// check for alpha channel
if (alphaRaster != null)
{
int[] alpha = alphaRaster.getPixels(0, y, srcImage.getWidth(), 1, (int[]) null);
for (int i = 0; i < srcImage.getWidth(); i++)
alphaBytes[i] = (byte) alpha[i];
swtImageData.setAlphas(0, y, srcImage.getWidth(), alphaBytes, 0);
}
}
return swtImageData;
}
/**
* Converts an swt based image into an AWT <code>BufferedImage</code>. This will always return a
* <code>BufferedImage</code> that is of type <code>BufferedImage.TYPE_INT_ARGB</code> regardless of the type of swt
* image that is passed into the method.
*
* @param srcImage the {@link org.eclipse.swt.graphics.Image} to be converted to a <code>BufferedImage</code>
* @return a <code>BufferedImage</code> that represents the same image data as the swt <code>Image</code>
*/
public static BufferedImage convert(Image srcImage)
{
return convertFromImageData(srcImage.getImageData());
}
/**
* Converts an swt based image data into an AWT <code>BufferedImage</code>. This will always return a
* <code>BufferedImage</code> that is of type <code>BufferedImage.TYPE_INT_ARGB</code> regardless of the type of swt
* image that is passed into the method.
*
* @param imageData the {@link org.eclipse.swt.graphics.Image} to be converted to a <code>BufferedImage</code>
* @return a <code>BufferedImage</code> that represents the same image data as the swt <code>Image</code>
*
* @since 1.3.1
*/
public static BufferedImage convertFromImageData(ImageData imageData)
{
int width = imageData.width;
int height = imageData.height;
ImageData maskData = null;
int alpha[] = new int[1];
if (imageData.alphaData == null)
maskData = imageData.getTransparencyMask();
// now we should have the image data for the bitmap, decompressed in
// imageData[0].data.
// Convert that to a Buffered Image.
BufferedImage image = new BufferedImage(imageData.width, imageData.height, BufferedImage.TYPE_INT_ARGB);
WritableRaster alphaRaster = image.getAlphaRaster();
// loop over the imagedata and set each pixel in the BufferedImage to
// the appropriate color.
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
RGB color = imageData.palette.getRGB(imageData.getPixel(x, y));
image.setRGB(x, y, new java.awt.Color(color.red, color.green, color.blue).getRGB());
// check for alpha channel
if (alphaRaster != null)
{
if (imageData.alphaData != null)
{
alpha[0] = imageData.getAlpha(x, y);
alphaRaster.setPixel(x, y, alpha);
}
else
{
// check for transparency mask
if (maskData != null)
{
alpha[0] = maskData.getPixel(x, y) == 0 ? 0 : 255;
alphaRaster.setPixel(x, y, alpha);
}
}
}
}
}
return image;
}
}
......@@ -40,4 +40,8 @@
<category name="org.jkiss.dbeaver.external"/>
</feature>
<feature id="org.jkiss.dbeaver.ext.ui.svg.feature">
<category name="org.jkiss.dbeaver.external"/>
</feature>
</site>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册