Set Attribute for the character set: AttributeOnly with CharSet

An AttributeOnly field's CharSet is sent as a Set Attribute (type 0x43)
for the characters after it, and DefaultCharSet sets it back: programmed
symbols from more than one set, and in their own colors, within a field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
This commit is contained in:
Claude committed 2026-10-16 02:41:02 +00:00
1 parent 6c4a4ee0bb
commit aeb7581efa
2 files changed
+28 -1

No files matched your search

+17
View File
@@ -399,3 +399,20 @@ func TestImagePictures(t *testing.T) {
}
}
}
// TestAttributeCharSet: an AttributeOnly field's character set is a Set
// Attribute (0x43), and DefaultCharSet sets it back; none otherwise.
func TestAttributeCharSet(t *testing.T) {
for _, c := range []struct {
f Field
want []byte
}{
{Field{AttributeOnly: true, Color: Red, CharSet: 0xc2}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0xf2, 0x28, 0x43, 0xc2}},
{Field{AttributeOnly: true, DefaultCharSet: true}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0, 0x28, 0x43, 0}},
{Field{AttributeOnly: true, Color: Blue}, []byte{0x28, 0x41, 0, 0x28, 0x42, 0xf1}},
} {
if got := buildField(c.f); !bytes.Equal(got, c.want) {
t.Errorf("%+v: % x, want % x", c.f, got, c.want)
}
}
}
+11 -1
View File
@@ -87,9 +87,14 @@ type Field struct {
// CharSet is the local ID of the character set the field is shown in:
// 0 for the default; a programmed symbol set's LCID (see LoadPS). It is
// sent as an extended field attribute (SFE type 0x43), so it ends with
// the field.
// the field; with AttributeOnly, as a Set Attribute (SA type 0x43),
// which lasts until another changes it (see DefaultCharSet).
CharSet byte
// DefaultCharSet, with AttributeOnly, sets the character set back to
// the default (SA type 0x43, 0) for the characters after it.
DefaultCharSet bool
// Raw, if not nil, is sent as the field's content as it is, instead of
// Content encoded in the code page: the code points of programmed
// symbols (0x41 to 0xFE) in a CharSet field. Values in the values map do
@@ -410,6 +415,11 @@ func buildField(f Field) []byte {
buf.WriteByte(0x28) // sa - "set attribute"
buf.WriteByte(0x42)
buf.WriteByte(byte(f.Color))
if f.CharSet != 0 || f.DefaultCharSet {
buf.WriteByte(0x28) // sa - "set attribute"
buf.WriteByte(0x43)
buf.WriteByte(f.CharSet)
}
return buf.Bytes()
}