From de0250eef06265fee296f8d22d7ccd4aeff98c48 Mon Sep 17 00:00:00 2001 From: dice-liner Date: Tue, 5 May 2026 19:57:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20HWPX=20ColorRef=20=EC=83=81=EC=9C=84=20?= =?UTF-8?q?=EB=B0=94=EC=9D=B4=ED=8A=B8=20=EB=B3=B4=EC=A1=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser/hwpx/utils.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/parser/hwpx/utils.rs b/src/parser/hwpx/utils.rs index af17c36f..fa0a11d8 100644 --- a/src/parser/hwpx/utils.rs +++ b/src/parser/hwpx/utils.rs @@ -51,7 +51,7 @@ pub fn parse_i32(attr: &quick_xml::events::attributes::Attribute) -> i32 { attr_str(attr).parse().unwrap_or(0) } -/// "#RRGGBB" 또는 "#AARRGGBB" 형식의 색상을 HWP ColorRef(0x00BBGGRR)로 변환 +/// "#RRGGBB" 또는 "#AARRGGBB" 형식의 색상을 HWP ColorRef로 변환 pub fn parse_color(attr: &quick_xml::events::attributes::Attribute) -> u32 { let s = attr_str(attr); parse_color_str(&s) @@ -72,12 +72,14 @@ pub fn parse_color_str(s: &str) -> u32 { return b << 16 | g << 8 | r; } } else if hex.len() == 8 { - // AARRGGBB → 0x00BBGGRR (alpha 무시) + // AARRGGBB → 0xAABBGGRR + // 상위 바이트는 HWP ColorRef의 확장/특수값 판별에 쓰이므로 보존한다. if let Ok(v) = u32::from_str_radix(hex, 16) { + let a = (v >> 24) & 0xFF; let r = (v >> 16) & 0xFF; let g = (v >> 8) & 0xFF; let b = v & 0xFF; - return b << 16 | g << 8 | r; + return a << 24 | b << 16 | g << 8 | r; } } 0x00000000 // 검정 @@ -135,7 +137,9 @@ mod tests { #[test] fn test_parse_color_str_with_alpha() { - // AARRGGBB — alpha 무시 - assert_eq!(parse_color_str("#80FF0000"), 0x000000FF); + // AARRGGBB — RGB는 BGR로 바꾸되 상위 바이트는 보존 + assert_eq!(parse_color_str("#80FF0000"), 0x800000FF); + assert_eq!(parse_color_str("#FF000000"), 0xFF000000); + assert_eq!(parse_color_str("#FFFFFFFF"), 0xFFFFFFFF); } }