Skip to content

Appearance (X resource) unification #4704

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 22 commits into from
Jan 20, 2022
Merged

Appearance (X resource) unification #4704

merged 22 commits into from
Jan 20, 2022

Conversation

skef
Copy link
Contributor

@skef skef commented Apr 14, 2021

Including:

For historical reasons the UI knobs in FontForge are supplied in X Resource format. There may still be some minimal compatibility with that system but given that its mostly supplied via GDK now that's not very important.

At some point a handy resource editing dialog was added so that less technical users could customize the UI. There was some effort put into unifying the initialization and the editing at that time but mostly in the form of new APIs (mainly GResEditFind()). For the most part variables were still initialized via individual calls to GResourceFindColor(), GResourceFindString() and so on.

The bulk of this PR finishes the unification, so that initialization and editing are two uses of the same data structure. It is now easier to add new directives -- usually just a matter of declaring the static variable with an appropriate default value, adding one line to a struct resed initializer, and a corresponding line to the tango/resources.in file (if needed).

In addition to that it does the following:

  1. Default font families for sans, serif, and mono are now defined in one place in BuildUtils.cmake and can be overridden by CMake flags. They are broken down by OS type (APPLE, WIN32 OR CYGWIN, and "other"). The current values are not final -- part of the reason I'm starting this PR as a draft is that we should discuss the best options.
  2. Font directives can now be specified relative to other font directives as described in the included documentation changes. The supplied resource files now do this. Because most of the UI is sized in relation to fonts you can now adjust the whole UI scale by changing the (new) View.DefaultFont point size. Another result is that families are specified once in each resource file (as long as they are kept consistent with the supplied file) and therefore the UI is much more uniform in presentation.
  3. I went through pretty much the whole UI to eliminate hard-coded colors, either by giving them new appearance directives or mapping them to either the GGadget FG or BG or the GDraw FG or BG. (GDrawGetDefaultForeground() and ...Background() now return a static value and ignore the display argument, as that generality wasn't used and mostly caused updating problems.) This allows a number of issues to be closed and means that true "dark" themes (and the like) are now possible.
  4. Since the GDK backend already switched away from ScreenWidth directives in favor of ScreenResolution I did that on the X side for consistency.
  5. The image cache has been restructured to minimize image path names relative to the ImagePath immediately, rather than having this happen "at the edges". The modified GResImage definition now stores the bucket instead of the file for additional flexibility.
  6. I've changed (or occasionally de-emphasized) the "X Resource" terminology in favor of "Appearance".
  7. The docs have been updated.

In addition to reviewing the changes this has a todo list:

  1. Decide on font families for each OS appropriate for contemporary use
  2. Decide what to do with the "Keyboard" resource (I think it should become a preference)

Ideally this work would be paired with a later PR that

  1. Figures out how to pick among images (menu icons, pointers, palette icons) scaled at different sizes.
  2. Come up with a full set of sources (probably in SVG) that can be attractively scaled that way
  3. Modify the editing system so that tracks both a "theme" file and a user file, and only stores what is different in the latter.

Then FontForge would support proper themes, which I imagine being added through a python API hook and distributed as python packages, given that the plugin interface is already integrated.

Closes #4454
Closes #4391
Closes #4238
Closes #3844
Closes #3835
Closes #3051
Closes #1031
Closes #863
Closes #4274

@ctrlcctrlv
Copy link
Member

Wow, amazing work. This took a ton of effort. Kudos.

@lgtm-com
Copy link

lgtm-com bot commented Apr 14, 2021

This pull request introduces 1 alert when merging e94c104 into a2f0e7d - view on LGTM.com

new alerts:

  • 1 for Function declared in block

Copy link
Contributor

@jtanx jtanx left a comment

Choose a reason for hiding this comment

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

On the added images, they're a fair way larger than the others, is this a colourspace difference and/or need to run through pngcrush/similar?

#define IC_SIZE 127
static struct image_bucket *imagecache[IC_SIZE];
static GImageCacheBucket *imagecache[IC_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

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

Geez, implementing our own hash table is rough.

gdisp->twobmouse_win = tbf;
gdisp->macosx_cmd = mxc;
GDrawResourceFind();
gdisp->bs.double_time = _GDraw_res_multiclicktime;
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've expressed this elsewhere, but not really a fan of these random/externed variables for preferences (not saying though that that needs to change for this pr, just longer term goals for how preferences should be managed).

In that sense imo the old approach (or the interface at least) was cleaner/makes more sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I suppose I added some more of that but it's still fairly modest.

In this case the "old approach" suffered from code duplication and a lack of an editing interface. It seemed strange to add the whole block to both back-ends.

It would certainly be easy enough to shove them all into a struct and give it a proper header if you think that would help.

@skef
Copy link
Contributor Author

skef commented Apr 14, 2021

On the added images, they're a fair way larger than the others, is this a colourspace difference and/or need to run through pngcrush/similar?

I think the only image I added was downarrow_disabled.png. The rest were copied from tango into 2012 because I wasn't sure what else to do (unlike the menu and palette icons those don't have hard-coded defaults).

@skef
Copy link
Contributor Author

skef commented Apr 14, 2021

@jtanx by the way when switching between 2012 and tango (I know .. why?) the install process isn't very good at identifying what files need to be replaced in (the equivalent of) /usr/share/fontforge/pixmaps. Not a huge deal but a little annoying.

@jtanx
Copy link
Contributor

jtanx commented Apr 14, 2021

As in ninja install skips copying sometimes? I didn't think the install process did any dependency tracking for that.

@skef
Copy link
Contributor Author

skef commented Apr 14, 2021

As in ninja install skips copying sometimes? I didn't think the install process did any dependency tracking for that.

Yeah, that's all I mean.

@skef
Copy link
Contributor Author

skef commented Apr 14, 2021

One thing I didn't put much thought into is whether more of the existing or added color parameters should have an alpha channel. (Having said that, it does seem that most of the colors don't overlap with others besides the pertinent background so there's no need for it.)

If folks have opinions on this let me know and I can make the changes.

@skef
Copy link
Contributor Author

skef commented Apr 15, 2021

I just played around with fonts a tiny bit on Arch to see how the support looks.

Arch has a mainstream package with the original bdf unifont files (https://archlinux.org/packages/extra/any/bdf-unifont/) and a user-supplied package with the ttf adaptation: https://aur.archlinux.org/packages/ttf-unifont/ . As far as I can tell the bdf fonts don't work with FontForge, at least with typical compilation flags. That's consistent with this note about about Arch pango support.

Arch is bleeding-edge so other distros may still work.

The ttf-unifont versions work pretty well as a backstop (although I guess there's little or nothing to be done past the BMP).

This may put us in a bit of a tricky situation as I'm not sure there's a mainstream outline font addressing the problem that bdf-unifont was intended to solve.

This leads me to the following initial thoughts:

  1. Presumably the Sans family list should start with one to several fonts with reasonably good coverage and that we know work well WRT lineheight and other metrics. DejaVu Sans seems to do well on that front, although to go beyond LCG it seems like you'll need a mass of font names. Maybe we should leave CJK to the users?
  2. After that we could put what we think is the best font that ships with the OS.
  3. Then behind that "unifont,sans".
  4. The burden on Serif and Mono is lower, as those just relate to the user's language rather than all code points. So skip "unifont". Otherwise the requirements are similar.
  5. On the Mac and Windows we should have some documentation somewhere suggesting fonts to install that match our choices, and how to make other choices.
  6. On *nix we can point to the same document but there's also more that the distro can do to help things out. We should explain the need and the relevant cmake flags and maybe encourage mainstream adoption of the ttf unifont so it can be a proper dependency.

@skef
Copy link
Contributor Author

skef commented Apr 15, 2021

Ah, there's also https://aur.archlinux.org/packages/otb-unifont/ , which repackages the BDF as OTB (using ... FontForge!) That could be another direction we encourage.

There are some unifont line height issues we may or may not want to think about (in FontView).

@ctrlcctrlv
Copy link
Member

The ttf-unifont versions work pretty well as a backstop (although I guess there's little or nothing to be done past the BMP).

@skef I'm writing to make you aware of Unifont Upper, if you are not already.

Unifont Upper supports a lot of SMP glyphs. See the codechart: http://unifoundry.com/pub/unifont/unifont-13.0.06/unifont_plane1-13.0.06.bmp

You can confirm it by comparing glyph shapes to https://en.wikipedia.org/wiki/Linear_B_Syllabary, the first encoded script in the SMP.

Unifont Upper's SMP support isn't perfect, but it encodes a lot of emoji, maths glyphs, and some rare scripts. I guess it's up to me to contribute Deseret, as I note that's missing, but for FontForge's users, I think it's not a problem for us to specify:

Unifont, Unifont Upper

@ctrlcctrlv
Copy link
Member

[…]

Unifont, Unifont Upper

@skef Did you see the above?

@skef
Copy link
Contributor Author

skef commented May 30, 2021

Yes, I did. It seems like all of these PRs are on indefinite hold for lack of review resources. I guess stuff will happen when it happens.

@ctrlcctrlv
Copy link
Member

Unfortunately. I'd trust Jeremy or Frank to merge this, but I haven't worked on the project recently enough or at this deep of a level to really do a thorough review.

@ghost
Copy link

ghost commented Sep 28, 2021

It seems like all of these PRs are on indefinite hold for lack of review resources. I guess stuff will happen when it happens.

I'd trust Jeremy or Frank to merge this.

Any progress on this pull review?

@jtanx
Copy link
Contributor

jtanx commented Oct 5, 2021

(pure rebase to master to fix conflicts)

@@ -79,6 +80,9 @@
#define SMDE_WIDTH 200
#define SMDE_HEIGHT (SMD_DIRDROP+200)

GResFont statemachine_font = GRESFONT_INIT("400 12pt " MONO_UI_FAMILIES);
extern Color kernclass_classfgcol; // Yes this is cheating
Copy link
Contributor

Choose a reason for hiding this comment

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

Cheating - meaning it doesn't have its own?

Choose a reason for hiding this comment

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

Yeah - I reused a few colors for more obscure cases when I was fairly confident no one would mind them being the same.

@@ -788,7 +784,7 @@ static void _GResourceFindImage(const char *fname, GResImage *img) {
if ( fname!=NULL ) {
t = _GGadgetImageCache(fname, false);
if ( t==NULL || t->image==NULL ) {
GDrawError("Could not find image corresponding to '%s', using default", fname);
Copy link
Contributor

Choose a reason for hiding this comment

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

This was pretty noisy when I was running, I think it makes sense to move these to traces

Choose a reason for hiding this comment

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

I'm fine with that. Want me to do it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah, I've already moved them to traces

@jtanx
Copy link
Contributor

jtanx commented Oct 9, 2021

Given the size of the pr it's hard to give too in-depth of a review but I did go over all of it and I don't spot anything obviously wrong, so I'll just mostly trust that it's doing the right thing.

In terms of outstanding actions:

Decide on font families for each OS appropriate for contemporary use

Is this just wrt what gets set in CMakeLists.txT?

Decide what to do with the "Keyboard" resource (I think it should become a preference)

Is this wrt GResourceFindString("Keyboard") - or what in particular?

@jtanx jtanx self-assigned this Oct 9, 2021
@iterumllc
Copy link

Is this just wrt what gets set in CMakeLists.txT?

I think it's in BuildUtils.cmake but yes.

I guess this is pretty simple; it seems like there are three levels: We might think there's a font that makes FontForge look nice and/or go with the project's "branding", which would presumably go up front. Next we probably want a font with reasonably good Unicode coverage that ships with the system, and is therefore likely different for Mac, Windows, and Linux. That's the research part of the problem. Then we might want to add some flavor of unifont and encourage its installation. (Probably either an outline version or OpenType-wrapped bitmaps, as those seem to be the only bitmap format working reliably now).

It's also possible that the project would prefer a different font for menus and dialogs and such compared with glyph labels. That would be easy enough to change in the standard theme.

Is this wrt GResourceFindString("Keyboard") - or what in particular?

Yeah, it doesn't really fit in with "appearance" and (in my view) the reasons it got lumped in with the X Resource framework don't apply anymore. (There's no reason that a theme you choose for FontForge should set it, for example). It should become a preference.

@skef
Copy link
Contributor Author

skef commented Oct 9, 2021

Font-wise I suppose we can also punt the decision and add a version of the old choices as defaults. However, some of those choices just don't seem to make sense now, so even a few hours of research or asking for input on fontforge-users seems preferable.

@skef
Copy link
Contributor Author

skef commented Jan 20, 2022

I think even if there are holes in my approach it's on the way to a better solution, so yeah, I'm not inclined to pursue further fixes for now but also not inclined to revert that work (assuming that's permissible).

I've worked through the rebase problems without squashing and am currently trying to test the askmulti dialog in the rebased version. Once I've done that I'll force-push.

@skef
Copy link
Contributor Author

skef commented Jan 20, 2022

Ok, I think I have everything put back together post-rebase. Akwardly, with the rebase process most of the changes to gflowbox.c and gsdroll1box.c got rolled in to the initial commit, so you'll have to look at them there if you want to.

@jtanx
Copy link
Contributor

jtanx commented Jan 20, 2022

Alright, I've pushed my changes. I looked further into the menu patches you made and yeah they're fine, I fixed that issue I talked about with 2fb3480.

With that I think we're good to merge.

@jtanx jtanx merged commit 0be7ca8 into fontforge:master Jan 20, 2022
@ghost
Copy link

ghost commented Jan 20, 2022

@jtanx @skef, thanks!

The only suggestion here — there should be one more change in "About" dialog:

  • "About" dialog (canvas) BG color should follow "View > Bakground" color;
  • "About" dialog (text, version number, etc.) FG color should follow "Font View > Glyph FG Color".

Here is screenshot of FontForge-2022-01-20-0be7ca8-x86_64.AppImage with myself modified @ASIDEdesignlab's "zDarkTheme":

Screenshot_2022-01-20_16-49-51

@skef
Copy link
Contributor Author

skef commented Jan 20, 2022

@Symbian9 Unfortunately I doubt there is going to be a sophisticated hierarchy of color settings analogous to what has been added for UI fonts. Theme designers are just going to have to go through and change the settings themselves. That said, those colors should be settable with Fontforge.Splash.Foreground and Fontforge.Splash.Background or in the Splash Screen tab of the Appearance dialog. If one of those doesn't work let me know and I'll take a look.

@skef
Copy link
Contributor Author

skef commented Jan 20, 2022

If you or any theme designer wants help tracking down settings open a "Discussion" in this repo and I'll try to help you.

@Finii
Copy link
Contributor

Finii commented Jan 21, 2022

This breaks fontforge if not used with dark theme:

image

Already the first commit does it:

$ cd build
$ git checkout 22e86b7e7c
$ git cherry-pick 78915690b35
$ rm -Rf * && cmake -GNinja ..
$ ninja
$ bin/fontforge ~/Downloads/ttf-iosevka-11.2.3/iosevka-bold.ttf

@jtanx
Copy link
Contributor

jtanx commented Jan 21, 2022

Running straight from the bin folder in the build directory doesn't have the theme files in the right place unless if you manually copy them into the right place.

If you ran ninja install and ran that, everything would work ok. So that is more of a dev inconvenience, but I guess for that alone it might be nice choosing a less-inconvenient default

@Finii
Copy link
Contributor

Finii commented Jan 21, 2022

The default defaults seem to be wrong...

Did

mv ~.config/fontforge{,_}

And get still the same black background with black text/glyphs.

It does work after I changed the global background color
image

But changing it there does not change the background for already open windows ;-)

Trying the install step now, thank you 👍

@jtanx
Copy link
Contributor

jtanx commented Jan 21, 2022

From your screenshot alone I can tell it's not loading any theme.

The default preferences expect the theme to be in the share folder. For local dev where I want it to load the default theme, I normally do something like this:

DESTDIR=a ninja install
cp -rP a/<prefix>/share .

@Finii
Copy link
Contributor

Finii commented Jan 21, 2022

Your hint with installing into a fake DESTDIR and copying into the build dir works fine!

Thank you!!

Might be worth mentioning in the INSTALL.md.

@Finii
Copy link
Contributor

Finii commented Jan 21, 2022

And/or here in the cmake for fontforge quickstart.

@ctrlcctrlv ctrlcctrlv mentioned this pull request Jan 27, 2022
Omnikron13 pushed a commit to Omnikron13/fontforge that referenced this pull request May 31, 2022
Appearance (X resource) unification
@skef skef mentioned this pull request Jan 2, 2024
4 tasks
@u2fly
Copy link

u2fly commented Aug 23, 2024

@ASIDEdesignlab's "zDarkTheme"

This dark theme is unavailable now, but here is a backup:
zDarkTheme-main@ASIDEdesignlab.zip

Archived project page: http://web.archive.org/web/20220309004744/https://github.com/ASIDEdesignlab/zDarkTheme

Author's post on Dribbble: https://dribbble.com/shots/15935800-zDarkTheme-FontForge-Theme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants