Closed benoitkugler closed 5 months ago
It introduces backward incompatible changes, the more subtle one being that
font.Font
andfont.Face
are now struct types, not pointers.
Can you comment on why this change was made? How is the new way better, for example? Just keen to understand as this is quite a wide hitting change.
It introduces backward incompatible changes, the more subtle one being that
font.Font
andfont.Face
are now struct types, not pointers.Can you comment on why this change was made? How is the new way better, for example? Just keen to understand as this is quite a wide hitting change.
It is better in the sense it removes indirection in the packages structure. Right now, font
is just used as a shortcut to opentype/api/font
, and, if we glance at the repository tree, we find both font
and opentype
, which is quite akward. Since we now are in control of the font library, it is simpler to remove this indirection.
Said otherwise, if we would write the font library from scratch, we would rather directly write the code in the font
package, right ?
I'm not pretending this solves serious issues. It is more about overall coherence and cleaning up things. Let's say I would be a bit annoyed if I had to justify the current structure to, say, new users or developers (again, putting the historical reason apart).
I see, I guess I didn't find the bit where "font.Face" was changed from a pointer, only the impact - can you remember which file it was?
So, in our current version, font.Face
is defined here : https://github.com/go-text/typesetting/blob/48cc05a56658160c485cbdbe274907ec430f8025/font/font.go#L16
With this PR, font.Face
would now be the actual struct, defined here : https://github.com/go-text/typesetting/blob/52dad1cb99a5193721a91810d78c4be9e8dfdf4d/font/font.go#L487
(Same goes for font.Font
)
Thanks, that makes it quite plain. I guess in the future we should avoid aliasing to a different type to avoid this sort of need to break.
I can see why this is desirable (and in many parts it was discussed before) but I think we need to discuss in the channel what to do regarding a break this big - as it will probably break any code using this API.
Fixes #116
I'm afraid this PR will not be very pleasant to review, due to the numbers of files changed, but most changes are just renaming.
As proposed, it contains the following refactors :
opentype/api/font
andopentype/api/metadata
. While at it, I've addressed #113 by adding two methods toFont
:Font.Describe() Description
andFont.IsMonospace() bool
. We still have the efficientDescribe(ld *ot.Loader, buffer []byte) (Description, []byte)
used byfontscan
to only fetch metadata without loading the whole font.opentype
intofont
: the low level packages are nowfont/cff/..
andfont/opentype/...
andfont
directly contains the implementation of font parsing and glyph loadingUsers should now be able to mostly use
font
as entry point.As stated in #116 , this PR does not solve an actual issue, but makes our module a lot more coherent, so that new users should have an easier time discovering and understanding its logic.
It introduces backward incompatible changes, the more subtle one being that
font.Font
andfont.Face
are now struct types, not pointers.