PowerBuilder Font Changer

Bruce Armstrong
CODE AUTHOR
Posts: 65
 1 week 6 days ago #711 by Bruce Armstrong
Bruce Armstrong created the code: PowerBuilder Font Changer

PowerBuilder Font Changer

Changes the font of every control and every DataWindow object in a PowerBuilder target or project to one installed font, then brings the compiled code up to date so you don't have to do it in the IDE.

The source is on GitHub: https://github.com/bruce-armstrong/PBFontChanger

Pick a workspace target (workspace mode) or a solution project (solution mode), pick a font from the list of fonts installed on the computer, and press Change Font. The utility rewrites the font in the source:

Where What changes
Windows, user objects, visual user objects (.srw .sru) string facename = "..." in each control's type block, with its fontfamily and fontpitch
Menus (.srm) this.facename = "..." in each item's create script
Graph controls TitleDispAttr.FaceName="..." and the other text attributes in the create script
DataWindow objects (.srd) font.face="..." of every text, column, computed field, button, group box and graph text (title.dispattr.font.face and so on), with font.family and font.pitch

The family and pitch are set to the new font's (Consolas, for instance, is modern and fixed pitch), so the font maps the same way PowerBuilder's painters would map it. Size, weight, style and character set are kept.

Left alone, and reported in the log:

  • Symbol and icon fonts (Wingdings, Webdings, Symbol, Marlett, Segoe MDL2 Assets...), which draw pictures rather than letters. Clear Leave symbol fonts as they are to change them too.
  • Fonts set by a DataWindow expression (font.face="0~tif(...)").
  • Fonts set in scripts at run time (dw_1.Modify("t_1.Font.Face=..."), st_1.FaceName = ...): each object whose scripts mention a font gets a WARNING line so you can look at it.

After the change

Workspace mode works on the source the IDE exports to the workspace's ws_objects folder when the workspace is in source control. It doesn't export source from the PBLs, so the workspace must be in source control (with ws_objects up to date). After changing the source the utility:

  1. Refreshes the target's PBLs from ws_objects with PBAutoBuild (a build file with only a Merging step, the same as the IDE's refresh).
  2. Builds the target incrementally (pbautobuild250 /pbc /c target.pbt /i for PowerBuilder 2025, pbc220 /c target.pbt /i for 2022).

This needs PowerBuilder 2022 or later and its PBAutoBuild installed (with the IDE, or the separate PowerBuilder Utilities). PowerBuilder 2019's compiler can't refresh PBLs, so for a 2019 workspace the utility changes the source and tells you to refresh the target and do an incremental build in the IDE.

Solution mode changes the source files in the project's .pbl folders, then builds the project incrementally (pbautobuild250 /pbc /c project.pbproj /i).

The version comes from the application object's appruntimeversion. The utility looks for PBAutoBuild in Program Files (x86)\Appeon\PowerBuilder nn.0 and PowerBuilderUtilities nn.0. Both steps need PowerBuilder closed, because the IDE keeps the PBLs and build files open; the utility checks and asks you to close it.

Requirements

  • PowerBuilder 2025 R2 (runtime 25.1.0.6430) to build and run the utility.
  • To refresh and build: PowerBuilder 2022 or later, matching the target or project's version, on the same computer.

Building

Open PBFontChanger.pbsln in the IDE and deploy p_pbfontchanger_exe, or from the command line:

pbautobuild250.exe /pbc /d PBFontChanger.pbproj /o pbfontchanger.exe /f /x 64

Usage

Run pbfontchanger.exe without arguments for the window. It remembers the last workspace or solution and font.

Only report what would change is a dry run: the log lists every file and setting that would change, and nothing is written.

The log is shown in the window and written to %TEMP%\PBFontChanger\pbfontchanger.log, with PBAutoBuild's build file and logs beside it.

Command line

The same change runs without the window when arguments are given, for scripts:

pbfontchanger file /font=name [/target=name] [/dryrun] [/nobuild] [/nodatawindows] [/nocontrols] [/changesymbols] [/log=file] [/quiet]
pbfontchanger /listfonts [/log=file]
Option Meaning
file A workspace (.pbw), solution (.pbsln) or project (.pbproj).
/font=name The font to change to. It must be installed; /listfonts lists the names.
/target=name The target or project (also /project=). Defaults to the workspace's or solution's default.
/dryrun Report what would change without writing any files.
/nobuild Don't refresh or build afterwards.
/nodatawindows Leave DataWindow objects alone.
/nocontrols Leave windows, user objects and menus alone.
/changesymbols Change symbol fonts too.
/log=file The log file. Defaults to %TEMP%\PBFontChanger\pbfontchanger.log.
/quiet Show no messages; results go to the log only.

For example:

pbfontchanger "C:\src\pfc\PFC.pbw" "/target=peat demo app" "/font=Segoe UI" /quiet

Before changing a code base

  • Commit first, or work on a branch, so you can review the diff and revert. Files are changed in place.
  • A target or project's libraries are often shared with others (PFC's libraries are). The change applies to every target or project that uses them; refresh and build those too.
  • Fonts differ in width. Text that fit in MS Sans Serif may not fit in Segoe UI at the same size: run the application and look at the windows and reports.
  • The IDE keeps its own compiled state, so it may still do an incremental build when it next opens the workspace or solution. That is harmless.

Tested on

PFC (PowerBuilder Foundation Classes) on copies of its workspaces and solution:

  • PowerBuilder 2025 workspace, target peat demo app (11 libraries): 587 font settings in 99 of 605 files (MS Sans Serif, Tahoma, Arial and System) changed to Segoe UI, 2 Wingdings buttons kept. The PBLs were refreshed and the target built, and no other font was left in the target's source.
  • PowerBuilder 2025 solution, project smtp demo: 403 font settings changed to Consolas, with family and pitch changed to modern and fixed. Built incrementally.
  • PowerBuilder 2022 workspace, target security scanner: refreshed with pbautobuild220 and built with pbc220.
  • PowerBuilder 2019 workspace: source changed, with the message to refresh and build in the IDE.

The utility was run as both a 32-bit and a 64-bit executable.

License

PowerBuilder Font Changer is released under the MIT License; see LICENSE.txt.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

Ramón San Félix Ramón
Posts: 54
 1 week 3 days ago #714 by Ramón San Félix Ramón
Ramón San Félix Ramón replied the code: PowerBuilder Font Changer

 Hi Bruce,

  Thanks again, this time for the Font Changer. It came at just the right moment: our ERP is meant to be all Arial 8,
  and every now and then the IDE slips in a Tahoma when a control is created. Your utility made me finally look, and
  there were more than I thought: Tahoma in 103 objects, almost all of it Tahoma 10.

  We've added it to pbAID, the browser IDE I told you about with the Syntax Updater, but we split it into two steps:

  - A "Fonts by object" report. For every DataWindow, window, user object and menu: which fonts and sizes it has
    written, and in which controls. It works as a lint: you see what doesn't follow the house font before changing
    anything.
  - "Change font…", a find and replace for fonts. You choose the new font and, optionally, the size, plus an "only if
    it's currently…" filter (for example Tahoma → Arial 8), the object types and the libraries. It first opens a preview
    tab with every control that would change, how it is now and how it will be, and nothing is written until you apply.
    After applying, pbAID compiles the pcode and tells you if any error mentions an object it just changed.

  We keep the same rules as you (symbol fonts, expressions and fonts set in scripts are left alone, and the scripts are
  reported), plus three things we ran into:

  - Only what is written in the file. An inherited control that doesn't write its facename takes it from its ancestor,
    so it isn't touched: it changes when the ancestor changes. The same goes for an inherited textsize: if you ask for a
    new size, that control changes font but not size. Writing the size there would break its inheritance.
  - Family and pitch. We first planned to take them from Windows, but the data didn't match. In our ERP's DataWindows,
    Courier New is saved with font.family="1", while Windows reports it as modern (3). Terminal shows a similar
    mismatch. So pbAID copies the family and pitch that the painter already wrote for the target font elsewhere in the
    same solution. If the font isn't used anywhere yet, it leaves them as they are and says so.
  - Menus with sizes in pixels. A few of our menus had this.textsize = 8, a positive value, so pixels rather than
    points. Asking for "8" writes -8, and the preview shows them separately so they don't go unnoticed.

  pbAID is at pbaid.rsrsystem.com (Spanish and English), in case you're curious to see your two
  ideas running side by side.

  Thanks for sharing your work; your utilities keep giving us good ideas.

Please Log in or Create an account to join the conversation.