Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Christnowx
Gephi
提交
963e25ee
G
Gephi
项目概览
Christnowx
/
Gephi
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gephi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
963e25ee
编写于
12月 15, 2015
作者:
M
Mathieu Bastian
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1224 from jersub/png-margin-regression
Fix the PNG margin regression
上级
b41acdc5
27fb3e3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
70 deletion
+96
-70
modules/PreviewAPI/src/main/java/org/gephi/preview/G2DRenderTargetBuilder.java
...c/main/java/org/gephi/preview/G2DRenderTargetBuilder.java
+58
-50
modules/PreviewExport/src/main/java/org/gephi/io/exporter/preview/PNGExporter.java
.../main/java/org/gephi/io/exporter/preview/PNGExporter.java
+38
-20
未找到文件。
modules/PreviewAPI/src/main/java/org/gephi/preview/G2DRenderTargetBuilder.java
浏览文件 @
963e25ee
...
...
@@ -149,7 +149,7 @@ public class G2DRenderTargetBuilder implements RenderTargetBuilder {
}
@Override
public
void
refresh
()
{
public
synchronized
void
refresh
()
{
if
(
graphics
!=
null
)
{
graphics
.
refresh
(
previewModel
,
this
);
}
...
...
@@ -183,32 +183,39 @@ public class G2DRenderTargetBuilder implements RenderTargetBuilder {
}
public
void
refresh
(
PreviewModel
m
,
RenderTarget
target
)
{
if
(
m
!=
null
)
{
background
=
m
.
getProperties
()
.
getColorValue
(
PreviewProperty
.
BACKGROUND_COLOR
);
initAppletLayout
(
m
);
g2
.
clearRect
(
0
,
0
,
width
,
height
);
g2
.
setTransform
(
new
AffineTransform
());
if
(
background
!=
null
)
{
g2
.
setColor
(
background
);
g2
.
fillRect
(
0
,
0
,
width
,
height
);
}
// user zoom
Vector
center
=
new
Vector
(
width
/
2
f
,
height
/
2
f
);
Vector
scaledCenter
=
Vector
.
mult
(
center
,
scaling
);
Vector
scaledTrans
=
Vector
.
sub
(
center
,
scaledCenter
);
g2
.
translate
(
scaledTrans
.
x
,
scaledTrans
.
y
);
g2
.
scale
(
scaling
,
scaling
);
// user move
g2
.
translate
(
trans
.
x
,
trans
.
y
);
//Draw target
previewController
.
render
(
target
);
if
(
m
==
null
)
{
return
;
}
if
(!
inited
)
{
CanvasSize
cs
=
getSheetCanvasSize
(
m
);
scaling
=
computeDefaultScaling
(
cs
);
fit
(
cs
);
inited
=
true
;
}
g2
.
clearRect
(
0
,
0
,
width
,
height
);
g2
.
setTransform
(
new
AffineTransform
());
background
=
m
.
getProperties
()
.
getColorValue
(
PreviewProperty
.
BACKGROUND_COLOR
);
if
(
background
!=
null
)
{
g2
.
setColor
(
background
);
g2
.
fillRect
(
0
,
0
,
width
,
height
);
}
// user zoom
Vector
center
=
new
Vector
(
width
/
2
F
,
height
/
2
F
);
Vector
scaledCenter
=
Vector
.
mult
(
center
,
scaling
);
Vector
scaledTrans
=
Vector
.
sub
(
center
,
scaledCenter
);
g2
.
translate
(
scaledTrans
.
x
,
scaledTrans
.
y
);
g2
.
scale
(
scaling
,
scaling
);
// user move
g2
.
translate
(
trans
.
x
,
trans
.
y
);
//Draw target
previewController
.
render
(
target
);
}
public
Vector
getTranslate
()
{
...
...
@@ -243,32 +250,33 @@ public class G2DRenderTargetBuilder implements RenderTargetBuilder {
inited
=
false
;
}
/**
* Initializes the preview applet layout according to the graph's
* dimension.
*/
private
void
initAppletLayout
(
PreviewModel
m
)
{
// graphSheet.setMargin(MARGIN);
if
(!
inited
)
{
private
CanvasSize
getSheetCanvasSize
(
PreviewModel
m
)
{
CanvasSize
cs
=
m
.
getGraphicsCanvasSize
();
float
marginPercentage
=
m
.
getProperties
()
.
getFloatValue
(
PreviewProperty
.
MARGIN
);
float
marginWidth
=
cs
.
getWidth
()
*
marginPercentage
/
100
F
;
float
marginHeight
=
cs
.
getHeight
()
*
marginPercentage
/
100
F
;
return
new
CanvasSize
(
cs
.
getX
()
-
marginWidth
,
cs
.
getY
()
-
marginHeight
,
cs
.
getWidth
()
+
2
F
*
marginWidth
,
cs
.
getHeight
()
+
2
F
*
marginHeight
);
}
// initializes zoom
CanvasSize
cs
=
m
.
getGraphicsCanvasSize
();
Vector
box
=
new
Vector
(
cs
.
getWidth
(),
cs
.
getHeight
());
float
ratioWidth
=
width
/
box
.
x
;
float
ratioHeight
=
height
/
box
.
y
;
scaling
=
ratioWidth
<
ratioHeight
?
ratioWidth
:
ratioHeight
;
// initializes move
Vector
semiBox
=
Vector
.
div
(
box
,
2
);
Vector
topLeft
=
new
Vector
(
cs
.
getX
(),
cs
.
getY
());
Vector
center
=
new
Vector
(
width
/
2
F
,
height
/
2
F
);
Vector
scaledCenter
=
Vector
.
add
(
topLeft
,
semiBox
);
trans
.
set
(
center
);
trans
.
sub
(
scaledCenter
);
// lastMove.set(trans);
private
float
computeDefaultScaling
(
CanvasSize
cs
)
{
float
ratioWidth
=
width
/
cs
.
getWidth
();
float
ratioHeight
=
height
/
cs
.
getHeight
();
return
ratioWidth
<
ratioHeight
?
ratioWidth
:
ratioHeight
;
}
inited
=
true
;
}
private
void
fit
(
CanvasSize
cs
)
{
Vector
box
=
new
Vector
(
cs
.
getWidth
(),
cs
.
getHeight
());
Vector
semiBox
=
Vector
.
div
(
box
,
2
F
);
Vector
topLeft
=
new
Vector
(
cs
.
getX
(),
cs
.
getY
());
Vector
center
=
new
Vector
(
width
/
2
F
,
height
/
2
F
);
Vector
scaledCenter
=
Vector
.
add
(
topLeft
,
semiBox
);
trans
.
set
(
center
);
trans
.
sub
(
scaledCenter
);
}
}
}
modules/PreviewExport/src/main/java/org/gephi/io/exporter/preview/PNGExporter.java
浏览文件 @
963e25ee
...
...
@@ -50,6 +50,7 @@ import org.gephi.io.exporter.spi.ByteExporter;
import
org.gephi.io.exporter.spi.VectorExporter
;
import
org.gephi.preview.api.G2DTarget
;
import
org.gephi.preview.api.PreviewController
;
import
org.gephi.preview.api.PreviewModel
;
import
org.gephi.preview.api.PreviewProperties
;
import
org.gephi.preview.api.PreviewProperty
;
import
org.gephi.preview.api.RenderTarget
;
...
...
@@ -72,34 +73,27 @@ public class PNGExporter implements VectorExporter, ByteExporter, LongTask {
private
int
width
=
1024
;
private
int
height
=
1024
;
private
boolean
transparentBackground
=
false
;
private
int
margin
=
4
;
private
int
margin
=
4
;
//FIXME Use a float instead to avoid extra cast
private
G2DTarget
target
;
private
Color
oldColor
;
@Override
public
boolean
execute
()
{
Progress
.
start
(
progress
);
PreviewController
controller
=
Lookup
.
getDefault
().
lookup
(
PreviewController
.
class
);
controller
.
getModel
(
workspace
).
getProperties
().
putValue
(
PreviewProperty
.
VISIBILITY_RATIO
,
1.0
);
PreviewController
ctrl
=
Lookup
.
getDefault
().
lookup
(
PreviewController
.
class
);
PreviewModel
m
=
ctrl
.
getModel
(
workspace
);
PreviewProperties
props
=
controller
.
getModel
(
workspace
).
getProperties
();
props
.
putValue
(
"width"
,
width
);
props
.
putValue
(
"height"
,
height
);
Color
oldColor
=
props
.
getColorValue
(
PreviewProperty
.
BACKGROUND_COLOR
);
if
(
transparentBackground
)
{
props
.
putValue
(
PreviewProperty
.
BACKGROUND_COLOR
,
new
Color
(
255
,
255
,
255
,
0
));
//White transparent
}
props
.
putValue
(
PreviewProperty
.
MARGIN
,
new
Float
((
float
)
margin
));
controller
.
refreshPreview
(
workspace
);
target
=
(
G2DTarget
)
controller
.
getRenderTarget
(
RenderTarget
.
G2D_TARGET
,
workspace
);
setExportProperties
(
m
);
ctrl
.
refreshPreview
(
workspace
);
target
=
(
G2DTarget
)
ctrl
.
getRenderTarget
(
RenderTarget
.
G2D_TARGET
,
workspace
);
if
(
target
instanceof
LongTask
)
{
((
LongTask
)
target
).
setProgressTicket
(
progress
);
}
//Fix bug caused by keeping width and height in the workspace preview properties.
//When a .gephi file is loaded later with these properties PGraphics will be created instead of a PApplet
props
.
removeSimpleValue
(
"width"
);
props
.
removeSimpleValue
(
"height"
);
props
.
removeSimpleValue
(
PreviewProperty
.
MARGIN
);
try
{
target
.
refresh
();
...
...
@@ -111,12 +105,12 @@ public class PNGExporter implements VectorExporter, ByteExporter, LongTask {
img
.
getGraphics
().
drawImage
(
sourceImg
,
0
,
0
,
null
);
ImageIO
.
write
(
img
,
"png"
,
stream
);
stream
.
close
();
props
.
putValue
(
PreviewProperty
.
BACKGROUND_COLOR
,
oldColor
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
discardExportProperties
(
m
);
Progress
.
finish
(
progress
);
return
!
cancel
;
...
...
@@ -169,6 +163,7 @@ public class PNGExporter implements VectorExporter, ByteExporter, LongTask {
this
.
stream
=
stream
;
}
@Override
public
boolean
cancel
()
{
cancel
=
true
;
if
(
target
instanceof
LongTask
)
{
...
...
@@ -177,7 +172,30 @@ public class PNGExporter implements VectorExporter, ByteExporter, LongTask {
return
true
;
}
@Override
public
void
setProgressTicket
(
ProgressTicket
progressTicket
)
{
this
.
progress
=
progressTicket
;
}
private
synchronized
void
setExportProperties
(
PreviewModel
m
)
{
PreviewProperties
props
=
m
.
getProperties
();
props
.
putValue
(
PreviewProperty
.
VISIBILITY_RATIO
,
1.0
F
);
props
.
putValue
(
"width"
,
width
);
props
.
putValue
(
"height"
,
height
);
oldColor
=
props
.
getColorValue
(
PreviewProperty
.
BACKGROUND_COLOR
);
if
(
transparentBackground
)
{
props
.
putValue
(
PreviewProperty
.
BACKGROUND_COLOR
,
new
Color
(
255
,
255
,
255
,
0
));
//White transparent
}
props
.
putValue
(
PreviewProperty
.
MARGIN
,
new
Float
(
margin
));
}
private
synchronized
void
discardExportProperties
(
PreviewModel
m
)
{
PreviewProperties
props
=
m
.
getProperties
();
props
.
removeSimpleValue
(
"width"
);
props
.
removeSimpleValue
(
"height"
);
props
.
removeSimpleValue
(
PreviewProperty
.
MARGIN
);
props
.
putValue
(
PreviewProperty
.
BACKGROUND_COLOR
,
oldColor
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录