/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" kryStyle::kryStyle() : m_prefix(NULL), m_font_anglex(0), m_font_angley(0), m_font_anglez(0), m_font_size(18), m_font_scaley(100), m_font_scalex(100), m_font_spacing(0), m_color_primary(0x00FFFFFF), m_color_secondary(0x0000FFFF), m_color_tertiary(0x0000FFFF), m_color_outline(0x00000000), m_color_shadow(0x00000000), m_color_back(0x00000000), m_bold(0), m_italic(0), m_border_style((enum border_style) 0), m_shadow_size(3), m_border_size(2), m_alignment(2), m_margin_left(20), m_margin_right(20), m_margin_top(20), m_margin_bottom(20), m_alpha_level(0), m_charset(0), m_strikethrough(0), m_underline(0), m_blur(0), m_relative(0), m_type(KRY_STYLE_SSA), m_refcount(1) { m_name = kry_strdup("Default"); m_font_name = kry_strdup("Arial"); } kryStyle::~kryStyle() { kry_free(this->m_font_name); kry_free(this->m_name); if(this->m_prefix) kry_free(this->m_prefix); } kryStyle *kryStyle::Copy() { kryStyle *newStyle = new kryStyle(); kry_free(newStyle->m_font_name); kry_free(newStyle->m_name); *newStyle = *this; newStyle->m_font_name = kry_strdup(this->m_font_name); newStyle->m_name = kry_strdup(this->m_name); if(this->m_prefix) newStyle->m_prefix = kry_strdup(this->m_prefix); newStyle->m_refcount = 1; return newStyle; } gboolean kryStyle::Compare(kryStyle *s2) { return this->m_alignment == s2->m_alignment && this->m_alpha_level == s2->m_alpha_level && this->m_blur == s2->m_blur && this->m_border_size == s2->m_border_size && this->m_border_style == s2->m_border_style && this->m_charset == s2->m_charset && this->m_color_outline == s2->m_color_outline && this->m_color_primary == s2->m_color_primary && this->m_color_secondary == s2->m_color_secondary && this->m_color_shadow == s2->m_color_shadow && this->m_font_anglex == s2->m_font_anglex && this->m_font_angley == s2->m_font_angley && this->m_font_anglez == s2->m_font_anglez && !strcmp(this->m_font_name, s2->m_font_name) && this->m_font_scalex == s2->m_font_scalex && this->m_font_scaley == s2->m_font_scaley && this->m_font_size == s2->m_font_size && this->m_font_spacing == s2->m_font_spacing && this->m_italic == s2->m_italic && this->m_margin_bottom == s2->m_margin_bottom && this->m_margin_left == s2->m_margin_left && this->m_margin_right == s2->m_margin_right && this->m_margin_top == s2->m_margin_top && this->m_relative == s2->m_relative && this->m_shadow_size == s2->m_shadow_size && this->m_strikethrough == s2->m_strikethrough && this->m_underline == s2->m_underline && this->m_bold == s2->m_bold; } double kryStyle::GetFontSize() { return this->m_font_size; } double kryStyle::GetFontSizeStatic(kryStyle *style) { return style->GetFontSize(); } int kryStyle::GetCharset() { return this->m_charset; } int kryStyle::GetCharsetStatic(kryStyle *style) { return style->GetCharset(); } void kryStyle::SetStrikethrough(gboolean val) { this->m_strikethrough = val; } void kryStyle::SetStrikethroughStatic(kryStyle *style, gboolean val) { style->SetStrikethrough(val); } void kryStyle::SetUnderline(gboolean val) { this->m_underline = val; } void kryStyle::SetUnderlineStatic(kryStyle *style, gboolean underline) { style->SetUnderline(underline); } void kryStyle::SetItalic(gboolean val) { this->m_italic = val; } void kryStyle::SetItalicStatic(kryStyle *style, gboolean italic) { style->SetItalic(italic); } void kryStyle::SetBold(gboolean val) { this->m_bold = val; } void kryStyle::SetBoldStatic(kryStyle *style, gboolean bold) { style->SetBold(bold); } void kryStyle::SetFontName(char *name) { if(this->m_font_name) { kry_free(this->m_font_name); this->m_font_name = NULL; } if(!name) return; this->m_font_name = kry_strdup(name); } void kryStyle::SetFontNameStatic(kryStyle *style, char *fontname) { style->SetFontName(fontname); } void kryStyle::SetFontSize(double size) { this->m_font_size = size; } void kryStyle::SetFontSizeStatic(kryStyle *style, double size) { style->SetFontSize(size); } gboolean kryStyle::GetStrikethrough() { return this->m_strikethrough; } gboolean kryStyle::GetStrikethroughStatic(kryStyle *style) { return style->GetStrikethrough(); } gboolean kryStyle::GetUnderline() { return this->m_underline; } gboolean kryStyle::GetUnderlineStatic(kryStyle *style) { return style->GetUnderline(); } gboolean kryStyle::GetItalic() { return this->m_italic; } gboolean kryStyle::GetItalicStatic(kryStyle *style) { return style->GetItalic(); } gboolean kryStyle::GetBold() { return this->m_bold; } gboolean kryStyle::GetBoldStatic(kryStyle *style) { return style->GetBold(); } char *kryStyle::GetFontName() { return this->m_font_name; } char *kryStyle::GetFontNameStatic(kryStyle *style) { return style->GetFontName(); } void kryStyle::SetAlignment(int alignment) { this->m_alignment = alignment; } void kryStyle::SetAlignmentStatic(kryStyle *style, int alignment) { style->SetAlignment(alignment); } int kryStyle::GetAlignment() { return this->m_alignment; } int kryStyle::GetAlignmentStatic(kryStyle *style) { return style->GetAlignment(); } int kryStyle::GetAlphaLevel() { return this->m_alpha_level; } int kryStyle::GetAlphaLevelStatic(kryStyle *style) { return style->GetAlphaLevel(); } void kryStyle::SetAlphaLevel(int alpha) { this->m_alpha_level = alpha; } void kryStyle::SetAlphaLevelStatic(kryStyle *style, int level) { style->SetAlphaLevel(level); } enum style_type kryStyle::GetType() { return this->m_type; } void kryStyle::SetType(enum style_type type) { this->m_type = type; } void kryStyle::SetName(char *name) { if(this->m_name) { kry_free(this->m_name); this->m_name = NULL; } if(!name) return; this->m_name = kry_strdup(name); } void kryStyle::SetNameStatic(kryStyle *style, char *name) { style->SetName(name); } char *kryStyle::GetName() { return this->m_name; } char *kryStyle::GetNameStatic(kryStyle *style) { return style->GetName(); } double kryStyle::GetFontScaleX() { return this->m_font_scalex; } double kryStyle::GetFontScaleXStatic(kryStyle *style) { return style->GetFontScaleX(); } void kryStyle::SetFontScaleX(double scale) { this->m_font_scalex = scale; } void kryStyle::SetFontScaleXStatic(kryStyle *style, double scale) { style->SetFontScaleX(scale); } double kryStyle::GetFontScaleY() { return this->m_font_scaley; } double kryStyle::GetFontScaleYStatic(kryStyle *style) { return style->GetFontScaleY(); } void kryStyle::SetFontScaleY(double scale) { this->m_font_scaley = scale; } void kryStyle::SetFontScaleYStatic(kryStyle *style, double scale) { style->SetFontScaleY(scale); } double kryStyle::GetFontSpacing() { return this->m_font_spacing; } double kryStyle::GetFontSpacingStatic(kryStyle *style) { return style->GetFontSpacing(); } void kryStyle::SetFontSpacing(double spacing) { this->m_font_spacing = spacing; } void kryStyle::SetFontSpacingStatic(kryStyle *style, double spacing) { style->SetFontSpacing(spacing); } double kryStyle::GetFontAngleX() { return this->m_font_anglex; } double kryStyle::GetFontAngleY() { return this->m_font_angley; } double kryStyle::GetFontAngleZ() { return this->m_font_anglez; } double kryStyle::GetFontAngleZStatic(kryStyle *style) { return style->GetFontAngleZ(); } void kryStyle::SetFontAngleX(double angle) { this->m_font_anglex = angle; } void kryStyle::SetFontAngleY(double angle) { this->m_font_angley = angle; } void kryStyle::SetFontAngleZ(double angle) { this->m_font_anglez = angle; } void kryStyle::SetFontAngleZStatic(kryStyle *style, double angle) { style->SetFontAngleZ(angle); } double kryStyle::GetBorderSize() { return this->m_border_size; } double kryStyle::GetBorderSizeStatic(kryStyle *style) { return style->GetBorderSize(); } void kryStyle::SetBorderSize(double size) { this->m_border_size = size; } void kryStyle::SetBorderSizeStatic(kryStyle *style, double size) { style->SetBorderSize(size); } double kryStyle::GetShadowSize() { return this->m_shadow_size; } double kryStyle::GetShadowSizeStatic(kryStyle *style) { return style->GetShadowSize(); } void kryStyle::SetShadowSize(double size) { this->m_shadow_size = size; } void kryStyle::SetShadowSizeStatic(kryStyle *style, double size) { style->SetShadowSize(size); } int kryStyle::GetMarginLeft() { return this->m_margin_left; } int kryStyle::GetMarginLeftStatic(kryStyle *style) { return style->GetMarginLeft(); } void kryStyle::SetMarginLeft(int margin) { this->m_margin_left = margin; } void kryStyle::SetMarginLeftStatic(kryStyle *style, int margin) { style->SetMarginLeft(margin); } int kryStyle::GetMarginRight() { return this->m_margin_right; } int kryStyle::GetMarginRightStatic(kryStyle *style) { return style->GetMarginRight(); } void kryStyle::SetMarginRight(int margin) { this->m_margin_right = margin; } void kryStyle::SetMarginRightStatic(kryStyle *style, int margin) { style->SetMarginRight(margin); } int kryStyle::GetMarginTop() { return this->m_margin_top; } int kryStyle::GetMarginBottom() { return this->m_margin_top; } int kryStyle::GetMarginTopStatic(kryStyle *style) { return style->GetMarginTop(); } void kryStyle::SetMarginTop(int margin) { this->m_margin_top = margin; } void kryStyle::SetMarginBottom(int margin) { this->m_margin_bottom = margin; } void kryStyle::SetMarginVertical(int margin) { this->m_margin_bottom = this->m_margin_top = margin; } void kryStyle::SetMarginVerticalStatic(kryStyle *style, int margin) { style->SetMarginVertical(margin); } void kryStyle::SetBorderStyle(enum border_style style) { this->m_border_style = style; } void kryStyle::SetBorderStyleStatic(kryStyle *style, enum border_style type) { style->SetBorderStyle(type); } enum border_style kryStyle::GetBorderStyle() { return this->m_border_style; } enum border_style kryStyle::GetBorderStyleStatic(kryStyle *style) { return style->GetBorderStyle(); } void kryStyle::SetColorPrimary(unsigned int color) { this->m_color_primary = color; } void kryStyle::SetColorPrimaryStatic(kryStyle *style, unsigned int color) { style->SetColorPrimary(color); } void kryStyle::SetColorSecondary(unsigned int color) { this->m_color_secondary = color; } void kryStyle::SetColorSecondaryStatic(kryStyle *style, unsigned int color) { style->SetColorSecondary(color); } void kryStyle::SetColorTertiary(unsigned int color) { this->m_color_tertiary = color; } void kryStyle::SetColorTertiaryStatic(kryStyle *style, unsigned int color) { style->SetColorTertiary(color); } void kryStyle::SetColorOutline(unsigned int color) { this->m_color_outline = color; this->m_color_back = color; } void kryStyle::SetColorOutlineStatic(kryStyle *style, unsigned int color) { style->SetColorOutline(color); } void kryStyle::SetColorShadowStatic(kryStyle *style, unsigned int color) { style->SetColorShadow(color); } void kryStyle::SetColorShadow(unsigned int color) { this->m_color_shadow = color; } void kryStyle::SetColorBack(unsigned int color) { this->m_color_back = color; this->SetColorShadow(color); this->SetColorOutline(color); } void kryStyle::SetColorBackStatic(kryStyle *style, unsigned int color) { style->SetColorBack(color); } unsigned int kryStyle::GetColorPrimary() { return this->m_color_primary; } unsigned int kryStyle::GetColorPrimaryStatic(kryStyle *style) { return style->GetColorPrimary(); } unsigned int kryStyle::GetColorSecondary() { return this->m_color_secondary; } unsigned int kryStyle::GetColorSecondaryStatic(kryStyle *style) { return style->GetColorSecondary(); } unsigned int kryStyle::GetColorTertiary() { return this->m_color_tertiary; } unsigned int kryStyle::GetColorTertiaryStatic(kryStyle *style) { return style->GetColorTertiary(); } unsigned int kryStyle::GetColorOutline() { return this->m_color_outline; } unsigned int kryStyle::GetColorOutlineStatic(kryStyle *style) { return style->GetColorOutline(); } unsigned int kryStyle::GetColorShadow() { return this->m_color_shadow; } unsigned int kryStyle::GetColorShadowStatic(kryStyle *style) { return style->GetColorShadow(); } unsigned int kryStyle::GetColorBack() { return this->m_color_back; } unsigned int kryStyle::GetColorBackStatic(kryStyle *style) { return style->GetColorShadow(); } unsigned int *kryStyle::GetColorPrimaryPtr() { return &this->m_color_primary; } unsigned int *kryStyle::GetColorSecondaryPtr() { return &this->m_color_secondary; } unsigned int *kryStyle::GetColorOutlinePtr() { return &this->m_color_outline; } unsigned int *kryStyle::GetColorShadowPtr() { return &this->m_color_shadow; } void kryStyle::SetBlur(int blur) { this->m_blur = blur; } int kryStyle::GetBlur() { return this->m_blur; } void kryStyle::SetCharset(int charset) { this->m_charset = charset; } void kryStyle::SetCharsetStatic(kryStyle *style, int charset) { style->SetCharset(charset); } int kryStyle::GetRelative() { return this->m_relative; } void kryStyle::Ref() { this->m_refcount++; } void kryStyle::Unref() { this->m_refcount--; if(this->m_refcount == 0) { KRY_UTP(this); delete this; } } void kryStyle::DestroyStatic(kryStyle *style) { delete style; } #ifdef _WINDOWS void kryStyle::LoadIntoLogfont(LOGFONTW *logfonta) { HDC hDC = GetDC(NULL); logfonta->lfCharSet = this->GetCharset(); logfonta->lfItalic = this->GetItalic(); logfonta->lfStrikeOut = this->GetStrikethrough(); logfonta->lfUnderline = this->GetUnderline(); logfonta->lfWeight = this->GetBold() ? 700 : 400; gunichar2 *font_utf16 = g_utf8_to_utf16(this->GetFontName(), -1, NULL, NULL, NULL); wcsncpy(logfonta->lfFaceName, font_utf16, LF_FACESIZE); g_free(font_utf16); logfonta->lfHeight = -MulDiv((int)(this->GetFontSize()+0.5), GetDeviceCaps(hDC, LOGPIXELSY), 72); ReleaseDC(NULL, hDC); } #endif char *kryStyle::GetPrefix() { return this->m_prefix; } void kryStyle::SetPrefix(char *text) { if(this->m_prefix) kry_free(this->m_prefix); this->m_prefix = kry_strdup(text); }