module Xlsxrb::Colors
ECMA-376 Part 4 §18.8.27 Standard Indexed Color Palette and utilities.
Constants
- INDEXED_COLORS
-
Standard ECMA-376 indexed colors (indices 0 through 63 as 6-character RRGGBB hex strings). Indices 8 through 63 represent the classic 56-color palette.
Public Class Methods
(untyped index, ?alpha: bool) → String?
Source
# File lib/xlsxrb/colors.rb, line 88 def self.palette_color(index, alpha: false) return nil unless index.is_a?(Integer) && index >= 0 && index < INDEXED_COLORS.size hex = INDEXED_COLORS[index] alpha ? "FF#{hex}" : hex end
Resolves a palette index (0..63) to an RRGGBB hex string (or AARRGGBB if alpha: true).
@example
Xlsxrb::Colors.palette_color(12) #=> "0000FF" Xlsxrb::Colors.palette_color(12, alpha: true) #=> "FF0000FF"
@param index [Object, nil] Palette index (0..63). @param alpha [Boolean] Whether to prefix “FF” alpha channel. @return [String, nil] @api public
(Integer | String | Symbol | nil color, ?alpha: bool) → String?
Source
# File lib/xlsxrb/colors.rb, line 110 def self.to_hex(color, alpha: false) return nil if color.nil? return palette_color(color, alpha: alpha) if color.is_a?(Integer) && color >= 0 && color < INDEXED_COLORS.size StyleBuilder.normalize_color(color, alpha: alpha) end
Converts any supported color representation (palette index 0..63, CSS name, #RGB, #RRGGBB, #AARRGGBB, integer RGB) to a normalized hex string.
@example
Xlsxrb::Colors.to_hex(12) #=> "0000FF" Xlsxrb::Colors.to_hex(12, alpha: true) #=> "FF0000FF" Xlsxrb::Colors.to_hex(:navy) #=> "000080" Xlsxrb::Colors.to_hex("#FF0000") #=> "FF0000" Xlsxrb::Colors.to_hex(0xFF0000) #=> "FF0000"
@param color [Integer, String, Symbol, nil] @param alpha [Boolean] Whether to include the alpha channel (default false -> “RRGGBB”). @return [String, nil] @api public