Skip to content

Read 12-digit tag colors as 16 bits per channel - #1567

Merged
DavidMStraub merged 1 commit into
gramps-project:mainfrom
giang17:fix/tag-color-hex12
Oct 19, 2026
Merged

DavidMStraub merged 1 commit into
gramps-project:mainfrom
giang17:fix/tag-color-hex12

Conversation

@giang17

@giang17 giang17 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Closes #1566

What this changes

  • hex12ToCss() and hex12ToHex6() in src/color.js parse each 4-digit group as hexadecimal and divide by 257 (new helper hex4To8Bit()), and accept only hex digits.
  • hex6ToHex12() writes the same format (#ff0000 → #ffff00000000). It is only used in tests.
  • hex12ToHex6() no longer needs the range check, since a 4-digit hex group always maps to 0–255.

How it was tested

  • test/unit/color.test.js: 4 new tests with the values from the example tree (#076780873bf0 → rgb(7, 128, 60), #efb60c280c28 → rgb(239, 12, 12)), white and black, the picker value (#07803c), the written format and non-hex digits. All 4 fail on main; the existing round-trip tests did not catch the bug because both directions used base 32. npm run lint and npm test (63 files, 1180 tests) pass.
  • Dev container with the example tree, Administration → Tags: complete is shown in green, rgb(7, 128, 60), instead of rgb(29, 255, 255), and its edit dialog opens with #07803c instead of #1f77b4.

Before / after:

Tags before the change: the tag complete is turquoise

Tags after the change: the tag complete is green

Drafted with an AI assistant.


  • I have read CONTRIBUTING.md
  • This was discussed in an issue first, or it is small enough not to need one
  • I wrote this myself, or used an AI assistant and have reviewed every line

Gramps 3.4 and 4.0 stored tag colors with Gdk.Color.to_string(), i.e.
#RRRRGGGGBBBB with four hex digits per channel, and Tag still defaults
to #000000000000. hex12ToCss() and hex12ToHex6() parsed each group in
base 32 and divided by 255, so such colors were shown wrongly (the
example tree's green tag "complete" as turquoise) and the edit dialog
fell back to #1f77b4, which was saved together with any other change.

Parse each group as hexadecimal and divide by 257; hex6ToHex12() writes
the same format.

Fixes gramps-project#1566
@DavidMStraub

Copy link
Copy Markdown
Member

Thanks!

@DavidMStraub
DavidMStraub merged commit 58654f4 into gramps-project:main Oct 19, 2026
1 check passed
@giang17
giang17 deleted the fix/tag-color-hex12 branch October 20, 2026 10:09
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.

[Bug] Tag colors with 12 hex digits (older Gramps versions) are shown wrongly and reset when the tag is edited

2 participants