-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Not using ScaledGraphics class degrades quality at higher zoom #637
Comments
I'm beginning to think that Draw2d uses What we could do is copy |
Another solution is to re-instate https://www.eclipse.org/forums/index.php?t=msg&th=154575&goto=487928&#msg_487928 fTextFlow = new TextFlow() {
@Override
protected void paintFigure(Graphics g) {
g.setClip(getBounds().getCopy().resize((int)(g.getAbsoluteScale()*3), 0));
super.paintFigure(g);
}
}; |
No because it doesn't solves the issue (rendering is also ugly and text is still truncated in several cases)
That's simply because we don't set a borderwidth, ScaledGraphics was introducing an issue that Archi adressed in drawing figures by substracting one pixel out of dimensions, but in fact the real fix is to shrink
Are we sure that the underlying graphics is configured as "advanced" and uses antialias ? FWIW, If I have to choose, I prefer having a non smooth font at 800% than a smooth but truncated one.
For relationships, that's in fact exactly the same in SVG output (at least on Linux), so this makes me think that the real issue lies in the figure drawing code, not the graphics itself (it was just invisible when using ScaledGraphics, but I guess for bad reasons)
I have to look at this one in detail, but this might be acceptable in the short/mid terme to explain that sideloading fonts is an experimental figure with known limitations which should be hopefuly solved in future release. |
If we edit
Draw2D is doing the drawing on the underlying graphics for figures, not us. But yes they are on. Also, for fonts, I think
I tried different things for connection Figures, but it still looks the same. |
I don't know what to do about this any more. I tried to improve the figures by adjusting the bounds of the each figure but can never get a solution. Here's an Application Component as it is now (no And here's the SVG export: Here it is with some x, y, width, height adjustments made in the figure to compensate: But here's the SVG export: |
It seems that |
I wondered whether Modelio uses protected void paintClientArea(Graphics graphics) {
if (getChildren().isEmpty()) {
return;
} else if (getScale() == 1.0) {
super.paintClientArea(graphics);
} else {
boolean optimizeClip = getBorder() == null || getBorder().isOpaque();
if (!optimizeClip) {
graphics.clipRect(getBounds().getShrinked(getInsets()));
}
graphics.scale(getScale());
graphics.pushState();
paintChildren(graphics);
graphics.popState();
graphics.restoreState();
}
} And they also have a comment in that code:
|
Modelio have a class public void paint(IFigure figure, Graphics graphics, Insets insets) {
AbstractBorder.tempRect.setBounds(getPaintRectangle(figure, insets));
if (getWidth() % 2 != 0) {
AbstractBorder.tempRect.width--;
AbstractBorder.tempRect.height--;
}
AbstractBorder.tempRect.shrink(getWidth() / 2, getWidth() / 2);
ZoomDrawer.setLineWidth(graphics, getWidth());
graphics.setLineStyle(getStyle());
if (getColor() != null) {
graphics.setForegroundColor(getColor());
}
graphics.drawRectangle(AbstractBorder.tempRect);
} |
Aha! I remembered something in /**
* JB fix - decrease width and height by 1 pixel
*/
@Override
public void fillRectangle(int x, int y, int width, int height) {
Rectangle2D rect = new Rectangle2D.Float(x + transX, y + transY, width - 1, height - 1);
checkState();
getGraphics2D().setPaint(getColor(getSWTGraphics().getBackgroundColor()));
getGraphics2D().fill(rect);
}
/**
* JB fix - decrease width and height by 1 pixel
*/
@Override
public void fillRoundRectangle(Rectangle rect, int arcWidth, int arcHeight) {
RoundRectangle2D roundRect = new RoundRectangle2D.Float(rect.x + transX, rect.y + transY, rect.width - 1, rect.height - 1, arcWidth,
arcHeight);
checkState();
getGraphics2D().setPaint(getColor(getSWTGraphics().getBackgroundColor()));
getGraphics2D().fill(roundRect);
} These are not needed now. |
It looks like most of the Figures will have to be re-done. |
I've created a branch |
I've done some more fixes for some Figures in the For simple shapes like rectangles and rounded rectangles this was simply a case of shortening the width and height of a rectangle by 1 pixel both for the fill and for the outline (when we used ScaledGraphics we only did that for the outline). However, I can't fix where we've used a For example, The |
In most of your attempts and test, borderwidth is not set, this is mostly why there are issues when zooming. In fact without a bordersidth set, there are several issues because the physical linewith on the screen is always 1 pixel and never zoomed while it should be. So the only way I see to fix this is:
And for an easier way to manage code, I would make sure that we have a private method to draw the figure which does is strictly based on a Rectangle (no shrinking), and then have the public draw method creating a Rectangle based on getting the figure dimensions shrinked by 1 and then calling the private method. This should then allow us to easily change the borderwith by using another value instead of 1 for shrinking (this value being related to the wanted borderwidth). I did some experiments some weeks ago (which led me to the "BTW I find a way to fix the borderwidth issue" comment) and I was able to adjust borderwidth without impact on zoom (but I did test only on Business Actor at that time). I'm a bit overloaded atm so can't test or contribute unfortunately :-( |
IMHO, such anti-aliasing issues are not a big deal. I think it is preferable (and hardly noticeable at zoom factors less than 200%) than having truncated text at most zoom factors. |
I didn't had this when I did test. Is it visible even at 100% ? So you experience clipping if you don't shrink ? |
Not really, but it is in SVG. |
I've made progress on the Figures. I want to get us to where we were before removing
The key is to use Here's an example of And this one uses I wrote a utility method to convert the co-ordinates of By doing this we can draw with more accuracy. All of this is in the I'll release another beta. |
Damn. I've just tested on Mac/Linux and there is a difference in how lines are drawn on Mac/Linux now that we are not using When we used This means that Mac/Linux users will see an uneven outline in the figures. (Edited to include Linux) |
Does this happen only when zooming? Can you do a screenshot of a figure at 100%, 200% and 300%.
This as no borderwidth. Do you means that even with a borderwidth defined, ScaledGraphics was drawing this ? For me what you get is the "usual" issue: when drawn, the border is centered on the defined coordinate, thus it spans accross clipping area. Let's say you have a figure from (10,10) to (20,20). When drawing a 3px border, it ends up being drawn (thats an example and not perfectly accurate information) from (9,9) to (21,21) because there are 3px to draw the inner part of the box will be (11,11) to (19,19). TBH, it seems that draw2d always put the bottom & right borders inside the clipping area while the top & left borders are "on" the limit of the clipping area. So we have to see when (which borders) to remove what (my guess is |
I have found a method to draw a rectangle with a specified line width that doesn't require any shrinking. Again, it means that we must do all drawing using bounds.width--;
bounds.height--;
float lineWidth = 1;
float offSet = lineWidth / 2;
graphics.setLineWidthFloat(lineWidth);
Path path = new Path(null);
path.moveTo(bounds.x + offSet, bounds.y + offSet);
path.lineTo(bounds.x + bounds.width - offSet, bounds.y + offSet);
path.lineTo(bounds.x + bounds.width - offSet, bounds.y + bounds.height - offSet);
path.lineTo(bounds.x + offSet, bounds.y + bounds.height - offSet);
path.lineTo(bounds.x + offSet, bounds.y);
graphics.drawPath(path);
path.dispose();
In the case of a line width of 1, the offset is 0.5. This works for all line widths. And we don't need to use |
I've committed the changes to Try it for rectangle figures. It works on Windows and Mac. |
So it seems to me that if we are going to dispense with using Drawing operations that use |
However, I don't think it will be possible to do this for figures other than rectangles. For example, there is no equivalent |
Fuck! I may have found the solution.... (look at the SWTGraphics source code...) |
Where there's Math & Geometry there's a way... with me ;-)
But where ????????? |
|
Seems like you want to |
Yes. The problem is that in most cases we want x and y to be 0.5 pixel indented. With Check out rectangle and rounded rectangle figures in the latest commit in |
So far, this seems to be working. So hopefully we'll be able to achieve our goal of setting line width... |
Cancel all of those last three messages (which I have deleted) and slap me round the head. I had hard coded a "1" for line width somewhere... |
Right then. I've re-written the code for all of the Figures (yes, it was a pain in the butt). All figures are now drawn with a line width of 1. It also works when setting the line width to 2 or 3 (any more than that looks silly.) I've tested all of them at different zoom levels and exporting to SVG. Let's test this and hope there are no more issues... All in the |
Great. I'll test tonight ! |
Bear in mind a few small caveats. These are things that we are going to have to accept as a small compromise. The thing is, though, as we are no longer using So our choices are:
Caveat:
Here's the code that does it: bounds.width -= lineWidth;
bounds.height -= lineWidth;
graphics.setLineWidthFloat(lineWidth);
graphics.translate(lineWidth / 2, lineWidth / 2); |
Even without having tested this latest version, I choose option 3 as it is for me what should have been the right behavior from the begining if we didn't had to cope with eclipse/ScaledGraphics issues. |
It only took 10 years... ;-) |
Actually, this is a 4th choice:
I only mention it to point out that the line width fix using |
Yes... but no ;-) because it is (almost) impossible to fix the font clipping issue.
That's good new though. |
(I'm not advocating for some of these choices, I just want to record them here so we know why we made these decisions) BTW - you can actually set line widths to floats like 1.5 and 2.5 and it works. Suggest this:
|
Everything we do should work with or without protected void paintClientArea(Graphics graphics) {
if (getChildren().isEmpty())
return;
if (scale == 1.0) {
super.paintClientArea(graphics);
} else {
ScaledGraphics g = new ScaledGraphics(graphics); |
I've just tested and everything seems ok. Good ! |
You can even set the line width to 0 and we are back to how it was before. Of course, line width of 0 doesn't work on Mac or Linux so it would have to be Windows only... (Edited to include Linux) |
It was truncated before. The fill problem is because it is drawing an outline and a fill and they do not line up. I created a new class But connections need further investigation as you say. |
Let's close this and open individual issues for each individual case. |
A follow up to this. Not using scaled graphics in Archi 4.7 has made an improvement to connections that have dots/dashes when exporting to an image at scales greater than 100%, In Archi 4.6 the dots/dashes didn't scale when exporting at higher scales. Here's an image export at 200% from Archi 4.6: And here's the same image export at 200% from Archi 4.7: |
In order to fix #621 we removed the use of the
org.eclipse.draw2d.ScaledGraphics
class. However, looking closer at some zoomed diagrams there are now new issues:Display#loadFont()
are not scaled and rendered correctly (see Issues using additional fonts in user fonts folders (SVG/Loading/Rendering) #628)The text was updated successfully, but these errors were encountered: