Skip to content

DM-7765 Render the text defined as the 'text' property value of a region on PNG #195

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

Merged
merged 2 commits into from
Sep 30, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.Font;
import java.util.List;

/**
Expand Down Expand Up @@ -302,6 +303,19 @@ private void makeText(RegionText rt) throws ProjectionException {
fo.setShowPoint(false);
fo.setTargetName(rt.getOptions().getText());
StringShape ss= fo.getDrawer().getStringShape();
int fStyle = Font.PLAIN;
if (rt.getOptions().getFont().isBold()) {
if (rt.getOptions().getFont().isItalic()) {
fStyle = Font.BOLD + Font.ITALIC;
} else {
fStyle = Font.BOLD;
}
} else if (rt.getOptions().getFont().isItalic()) {
fStyle = Font.ITALIC;
}

ss.setFont(new Font(rt.getOptions().getFont().getName(),
fStyle, (int)rt.getOptions().getFont().getPt()));
ss.setDrawWithBackground(false);
ss.setUseRegionCalc(true);
ss.setOffsetDirection(StringShape.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void setOffsetDirection(int offsetDir) {
public void setOffsetDistance(int offsetDist) { _offsetDist= offsetDist; }
public void setColor(Color c) { _color= c; }
public Color getColor() { return _color; }
public Font getFont() { return _font; }
public void setFont(Font f) { _font = f; }

public void draw(Graphics2D g2,
ImageWorkSpacePt ipt,
Expand Down
8 changes: 4 additions & 4 deletions src/firefly/js/ui/FitsDownloadDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ function resultsSuccess(request, plot) {
plotState.getWorkingFitsFileStr(band) :
plotState.getOriginalFitsFileStr(band);

var getRegionsDes = () => {
var getRegionsDes = (bSeperateText) => {
var regionDes;

regionDes = makeRegionsFromPlot(plot);
regionDes = makeRegionsFromPlot(plot, bSeperateText);
return `[${regionDes.join(STRING_SPLIT_TOKEN)}]`;
};

Expand All @@ -356,7 +356,7 @@ function resultsSuccess(request, plot) {
download(url);
} else if (ext && ext.toLowerCase() === 'png') {

getImagePng(plotState, getRegionsDes()).then((result) => {
getImagePng(plotState, getRegionsDes(true)).then((result) => {
var imgFile = get(result, 'ImageFileName');

if (imgFile) {
Expand All @@ -371,7 +371,7 @@ function resultsSuccess(request, plot) {

} else if (ext && ext.toLowerCase() === 'reg') {

saveDS9RegionFile(getRegionsDes()).then( (result ) => {
saveDS9RegionFile(getRegionsDes(false)).then( (result ) => {
var rgFile = get(result, 'RegionFileName');

if (rgFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/firefly/js/visualize/draw/DirectionArrowDrawObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function toRegion(startPt,endPt,plot,drawParams,renderOptions) {

if (text) {
des += setRegionPropertyDes(regionPropsList.TEXT, text) +
setRegionPropertyDes(regionPropsList.FONT, {name: 'helvetica', size: 9, weight: 'normal', style: 'normal'} );
setRegionPropertyDes(regionPropsList.FONT, {name: 'helvetica', size: 9, weight: 'normal', slant: 'normal'} );
}
des = endRegionDes(des);

Expand Down
3 changes: 2 additions & 1 deletion src/firefly/js/visualize/draw/PointDataObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function makeTextLocationPoint(drawObj, plot, textLoc, fontSize) {
if (!area) return null;

var {centerPt, width, height} = area;
var fHeight = fontHeight(fontSize) + 4;
var fHeight = fontHeight(fontSize);
var opt;

switch(textLoc) {
Expand Down Expand Up @@ -319,6 +319,7 @@ function drawXY(ctx, drawTextAry, pt, plot, drawObj, drawParams,renderOptions, o
if (textOffset && (textOffset.x !== 0.0 || textOffset.y !== 0.0)) {
drawText(drawObj, drawTextAry, plot, vpt, drawParams);
} else {
drawObj.textWorldLoc = plot.getImageCoords(vpt);
DrawUtil.drawText(drawTextAry, text, vpt.x, vpt.y, color, renderOptions,
fontName, fontSize, fontWeight, fontStyle);
}
Expand Down
15 changes: 11 additions & 4 deletions src/firefly/js/visualize/draw/ShapeToRegion.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export function addTextRelatedProps(drawObj, drawParams) {


/**
* create text region seperate from the region of any shape in case there exit non default textloc or textoffset
* create text region seperate from the region of any shape in case there exists non default textloc or textoffset or
* a seperate request.
* @param drawObj
* @param drawParams
* @param regionType
Expand All @@ -169,7 +170,7 @@ export function addTextRelatedProps(drawObj, drawParams) {
*/
export function createTextRegionFromShape(drawObj, drawParams, regionType, cc) {
var {textLoc}= drawParams;
var {text, textOffset}= drawObj;
var {text, textOffset, bSeperateText = false}= drawObj;

var des = '';
var searchTextLoc = () => {
Expand All @@ -186,14 +187,20 @@ export function createTextRegionFromShape(drawObj, drawParams, regionType, cc) {
if (!text) return des;

// check if text location is default as defined and no offset involved
if ((!textLoc || textLoc === DEFAULT_TEXTLOC[regionType.key]) &&
if ((!bSeperateText) &&
(!textLoc || textLoc === DEFAULT_TEXTLOC[regionType.key]) &&
(!textOffset || (textOffset.x === 0.0 && textOffset.y === 0.0))) return des;

// adapt the computed text location if there is or recompute the text location
var textWorldLoc = get(drawObj, 'textWorldLoc', searchTextLoc());
if (!textWorldLoc) return des;

return makeTextRegion(cc.getWorldCoords(textWorldLoc), cc, drawObj, drawParams);
var textReg = makeTextRegion(cc.getWorldCoords(textWorldLoc), cc, drawObj, drawParams);
if (isEmpty(textReg)) {
return des;
} else {
return textReg[0];
}
}

/**
Expand Down
Loading