Skip to content

Conversation

@ptziegler
Copy link
Contributor

@ptziegler ptziegler commented Oct 10, 2025

This adds a new getTextUtilities() method to the IFigure interface. The method is overriden by the RootFigure and returns an object of type DrawableTextUtilities, which is created for the canvas hooked to the LWS.

When using this method, users are guaranteed that the font sizes returned calculated by this instance match the zoom level of the monitor they are painted on.

Comment on lines 181 to 190
/**
* @since 3.21
*/
public static TextUtilities getTextUtilities(IFigure figure) {
if (getRoot(figure) instanceof LightweightSystem.RootFigure rootFigure) {
return rootFigure.getTextUtilities();
}
return TextUtilities.INSTANCE;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure where to put this. In principle, it might also be directly added to the IFigure?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I figure sounds like a very good place for this. Should we also move the getRoot there? Or better add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also move the getRoot there? Or better add?

I think that makes sense. The way it is currently done is by using something like, for e.g. the font and colors:

public Object xyz() {
	if (getParent() != null) {
		return getParent().xyz();
	}
	return null;
}

So that I'd do as a separate PR, together with cleaning up all of the other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, I don't think the getRoot() method is a good idea. In principle, any parent can override the getTextUtilities() method and provide its own implementation. This is how it's done for all other methods that are overridden by the root figure.

Changing this here feels odd. There are also several figures that access TextUtilities.INSTANCE or the static FigureUtilities methods directly. This I'd address with a separate PR.

return TextUtilities.INSTANCE;
}

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly enough, increasing the visibility doesn't break binary compatibility, but may cause source-incompatibilities if overridden by subclasses.

https://github.com/eclipse-platform/eclipse.platform/blob/master/docs/Evolving-Java-based-APIs-2.md#evolving-api-classes---api-methods-and-constructors

This adds a new getTextUtilities() method to the IFigure interface. The
method is overriden by the RootFigure and returns an object of type
DrawableTextUtilities, which is created for the canvas hooked to the
LWS.

When using this method, users are guaranteed that the font sizes
returned calculated by this instance match the zoom level of the monitor
they are painted on.
@ptziegler
Copy link
Contributor Author

I also just noticed that the fix for #816 is not applied to the DrawableFigureUtilities. Even if the GC is disposed together with the canvas, you may still have a resource leak if you constantly update the font on the same canvas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants