Skip to content

Commit

Permalink
Add new exported ColorMappingType used for color transformation
Browse files Browse the repository at this point in the history
Using `ColorMappingType` color transformation types enumeration for tab color index, ref #1285
  • Loading branch information
xuri committed Aug 6, 2022
1 parent 4a029f7 commit e07dac5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
21 changes: 2 additions & 19 deletions sheetpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ type (
OutlineSummaryBelow bool
)

const (
TabColorThemeLight1 int = iota // Inverted compared to the spec because that's how Excel maps them
TabColorThemeDark1
TabColorThemeLight2
TabColorThemeDark2
TabColorThemeAccent1
TabColorThemeAccent2
TabColorThemeAccent3
TabColorThemeAccent4
TabColorThemeAccent5
TabColorThemeAccent6
TabColorThemeHyperlink
TabColorThemeFollowedHyperlink

TabColorUnsetValue int = -1
)

// setSheetPrOption implements the SheetPrOption interface.
func (o OutlineSummaryBelow) setSheetPrOption(pr *xlsxSheetPr) {
if pr.OutlinePr == nil {
Expand Down Expand Up @@ -165,7 +148,7 @@ func (o TabColorIndexed) setSheetPrOption(pr *xlsxSheetPr) {
// TabColor Indexed. Defaults to -1 if no indexed has been set.
func (o *TabColorIndexed) getSheetPrOption(pr *xlsxSheetPr) {
if pr == nil || pr.TabColor == nil {
*o = TabColorIndexed(TabColorUnsetValue)
*o = TabColorIndexed(ColorMappingTypeUnset)
return
}
*o = TabColorIndexed(pr.TabColor.Indexed)
Expand Down Expand Up @@ -206,7 +189,7 @@ func (o TabColorTheme) setSheetPrOption(pr *xlsxSheetPr) {
// TabColor Theme. Defaults to -1 if no theme has been set.
func (o *TabColorTheme) getSheetPrOption(pr *xlsxSheetPr) {
if pr == nil || pr.TabColor == nil {
*o = TabColorTheme(TabColorUnsetValue)
*o = TabColorTheme(ColorMappingTypeUnset)
return
}
*o = TabColorTheme(pr.TabColor.Theme)
Expand Down
6 changes: 3 additions & 3 deletions sheetpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ = []SheetPrOption{
FitToPage(true),
TabColorIndexed(42),
TabColorRGB("#FFFF00"),
TabColorTheme(TabColorThemeLight2),
TabColorTheme(ColorMappingTypeLight2),
TabColorTint(0.5),
AutoPageBreaks(true),
OutlineSummaryBelow(true),
Expand Down Expand Up @@ -45,7 +45,7 @@ func ExampleFile_SetSheetPrOptions() {
FitToPage(true),
TabColorIndexed(42),
TabColorRGB("#FFFF00"),
TabColorTheme(TabColorThemeLight2),
TabColorTheme(ColorMappingTypeLight2),
TabColorTint(0.5),
AutoPageBreaks(true),
OutlineSummaryBelow(false),
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestSheetPrOptions(t *testing.T) {
{new(FitToPage), FitToPage(true)},
{new(TabColorIndexed), TabColorIndexed(42)},
{new(TabColorRGB), TabColorRGB("FFFF00")},
{new(TabColorTheme), TabColorTheme(TabColorThemeLight2)},
{new(TabColorTheme), TabColorTheme(ColorMappingTypeLight2)},
{new(TabColorTint), TabColorTint(0.5)},
{new(AutoPageBreaks), AutoPageBreaks(true)},
{new(OutlineSummaryBelow), OutlineSummaryBelow(false)},
Expand Down
20 changes: 20 additions & 0 deletions xmlDrawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ const (
pivotTableVersion = 3
)

// ColorMappingType is the type of color transformation.
type ColorMappingType byte

// Color transformation types enumeration.
const (
ColorMappingTypeLight1 ColorMappingType = iota
ColorMappingTypeDark1
ColorMappingTypeLight2
ColorMappingTypeDark2
ColorMappingTypeAccent1
ColorMappingTypeAccent2
ColorMappingTypeAccent3
ColorMappingTypeAccent4
ColorMappingTypeAccent5
ColorMappingTypeAccent6
ColorMappingTypeHyperlink
ColorMappingTypeFollowedHyperlink
ColorMappingTypeUnset int = -1
)

// supportedImageTypes defined supported image types.
var supportedImageTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png", ".tif": ".tiff", ".tiff": ".tiff", ".emf": ".emf", ".wmf": ".wmf"}

Expand Down

0 comments on commit e07dac5

Please sign in to comment.