mod builder;
mod create;
mod stylemap;
pub use builder::*;
pub use create::*;
pub use stylemap::*;
use crate::attrmap2::AttrMap2;
use crate::color::Rgb;
use crate::style::units::{
Angle, FontSize, FontStyle, FontVariant, FontWeight, FormatSource, Length, LetterSpacing,
LineMode, LineStyle, LineType, LineWidth, Percent, RotationScale, TextCombine, TextCondition,
TextDisplay, TextEmphasize, TextEmphasizePosition, TextPosition, TextRelief, TextTransform,
TransliterationStyle,
};
use crate::style::AnyStyleRef;
use crate::style::ParseStyleAttr;
use crate::style::{
color_string, shadow_string, text_position, StyleOrigin, StyleUse, TextStyleRef,
};
use crate::{OdsError, ValueType};
use core::borrow::Borrow;
use get_size2::GetSize;
use icu_locale_core::subtags::{Language, Region, Script};
use icu_locale_core::{LanguageIdentifier, Locale};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
style_ref2!(ValueFormatRef);
pub trait ValueFormatTrait {
fn format_ref(&self) -> ValueFormatRef;
fn set_name<S: Into<String>>(&mut self, name: S);
fn name(&self) -> &String;
fn value_type(&self) -> ValueType;
fn set_origin(&mut self, origin: StyleOrigin);
fn origin(&self) -> StyleOrigin;
fn set_styleuse(&mut self, styleuse: StyleUse);
fn styleuse(&self) -> StyleUse;
fn attrmap(&self) -> &AttrMap2;
fn attrmap_mut(&mut self) -> &mut AttrMap2;
fn textstyle(&self) -> &AttrMap2;
fn textstyle_mut(&mut self) -> &mut AttrMap2;
fn push_part(&mut self, part: FormatPart);
fn push_parts(&mut self, partvec: &mut Vec<FormatPart>);
fn parts(&self) -> &Vec<FormatPart>;
fn parts_mut(&mut self) -> &mut Vec<FormatPart>;
fn push_stylemap(&mut self, stylemap: ValueStyleMap);
fn stylemaps(&self) -> Option<&Vec<ValueStyleMap>>;
fn stylemaps_mut(&mut self) -> &mut Vec<ValueStyleMap>;
}
valueformat!(ValueFormatBoolean, ValueType::Boolean);
impl ValueFormatBoolean {
part_boolean!();
push_boolean!();
}
valueformat!(ValueFormatNumber, ValueType::Number);
impl ValueFormatNumber {
part_fill_character!();
part_fraction!();
part_number!();
part_scientific!();
part_text!();
push_fraction!();
push_number!();
push_number_fix!();
push_scientific!();
push_text!();
}
valueformat!(ValueFormatPercentage, ValueType::Percentage);
impl ValueFormatPercentage {
part_fill_character!();
part_number!();
part_text!();
push_number!();
push_number_fix!();
push_text!();
}
valueformat!(ValueFormatCurrency, ValueType::Currency);
impl ValueFormatCurrency {
number_automatic_order!(attr);
part_currency!();
part_fill_character!();
part_number!();
part_text!();
push_currency_symbol!();
push_number!();
push_number_fix!();
push_text!();
}
valueformat!(ValueFormatText, ValueType::Text);
impl ValueFormatText {
part_fill_character!();
part_text!();
part_text_content!();
push_text!();
push_text_content!();
}
valueformat!(ValueFormatDateTime, ValueType::DateTime);
impl ValueFormatDateTime {
number_automatic_order!(attr);
number_format_source!(attr);
part_am_pm!();
part_day!();
part_day_of_week!();
part_era!();
part_fill_character!();
part_hours!();
part_minutes!();
part_month!();
part_quarter!();
part_seconds!();
part_text!();
part_week_of_year!();
part_year!();
push_am_pm!();
push_day!();
push_day_of_week!();
push_era!();
push_hours!();
push_minutes!();
push_month!();
push_quarter!();
push_seconds!();
push_text!();
push_week_of_year!();
push_year!();
}
valueformat!(ValueFormatTimeDuration, ValueType::TimeDuration);
impl ValueFormatTimeDuration {
number_format_source!(attr);
number_truncate_on_overflow!(attr);
part_am_pm!();
part_fill_character!();
part_hours!();
part_minutes!();
part_seconds!();
part_text!();
push_am_pm!();
push_hours!();
push_minutes!();
push_seconds!();
push_text!();
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, GetSize)]
#[allow(missing_docs)]
pub enum FormatPartType {
Number,
FillCharacter,
ScientificNumber,
Fraction,
CurrencySymbol,
Day,
Month,
Year,
Era,
DayOfWeek,
WeekOfYear,
Quarter,
Hours,
Minutes,
Seconds,
AmPm,
Boolean,
Text,
TextContent,
}
#[derive(Debug, Clone, GetSize)]
pub struct FormatPart {
part_type: FormatPartType,
attr: AttrMap2,
position: Option<i32>,
content: Option<String>,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum FormatNumberStyle {
Short,
Long,
}
impl Display for FormatNumberStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
FormatNumberStyle::Short => write!(f, "short"),
FormatNumberStyle::Long => write!(f, "long"),
}
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum FormatCalendarStyle {
Gregorian,
Gengou,
Roc,
Hanja,
Hijri,
Jewish,
Buddhist,
}
impl Display for FormatCalendarStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
FormatCalendarStyle::Gregorian => write!(f, "gregorian"),
FormatCalendarStyle::Gengou => write!(f, "gengou"),
FormatCalendarStyle::Roc => write!(f, "ROC"),
FormatCalendarStyle::Hanja => write!(f, "hanja"),
FormatCalendarStyle::Hijri => write!(f, "hijri"),
FormatCalendarStyle::Jewish => write!(f, "jewish"),
FormatCalendarStyle::Buddhist => write!(f, "buddhist"),
}
}
}
impl FormatPart {
pub fn new(ftype: FormatPartType) -> Self {
FormatPart {
part_type: ftype,
attr: Default::default(),
position: None,
content: None,
}
}
pub fn set_part_type(&mut self, p_type: FormatPartType) {
self.part_type = p_type;
}
pub fn part_type(&self) -> FormatPartType {
self.part_type
}
pub(crate) fn attrmap(&self) -> &AttrMap2 {
&self.attr
}
pub(crate) fn attrmap_mut(&mut self) -> &mut AttrMap2 {
&mut self.attr
}
pub fn set_attr(&mut self, name: &str, value: String) {
self.attr.set_attr(name, value);
}
pub fn attr_def<'a, 'b, S>(&'a self, name: &'b str, default: S) -> &'a str
where
S: Into<&'a str>,
{
self.attr.attr_def(name, default)
}
pub fn set_position(&mut self, pos: i32) {
self.position = Some(pos);
}
pub fn clear_position(&mut self) {
self.position = None;
}
pub fn position(&self) -> Option<i32> {
self.position
}
pub fn set_content<S: Into<String>>(&mut self, content: S) {
self.content = Some(content.into());
}
pub fn append_content<S: AsRef<str>>(&mut self, content: S) {
match &mut self.content {
None => {
self.content = Some(content.as_ref().to_string());
}
Some(v) => {
v.push_str(content.as_ref());
}
}
}
pub fn clear_content(&mut self) {
self.content = None;
}
pub fn content(&self) -> Option<&String> {
self.content.as_ref()
}
}