Пример #1
0
    private static Color GetThemedColor(int colorThemeIndex, double tintAndShade, Document doc)
    {
        // translate from wdThemeColorIndex to MsoThemeColorSchemeIndex
        MsoThemeColorSchemeIndex colorSchemeIndex = ThemeIndexToSchemeIndex(colorThemeIndex);
        // get color scheme by this index and take its RGB property, but this RGB still OLE RGB - i.e. BGR -> need to convert it to real RGB, i.e. use ColorTranslator.FromOle() and ToArgb after
        OfficeTheme      theme  = doc.DocumentTheme;
        ThemeColorScheme scheme = theme.ThemeColorScheme;
        ThemeColor       color  = scheme.Colors(colorSchemeIndex);
        int colorSchemeRGB      = ColorTranslator.FromOle(color.RGB).ToArgb();

        Marshal.ReleaseComObject(color);
        Marshal.ReleaseComObject(scheme);
        Marshal.ReleaseComObject(theme);

        // do RGB -> HSL translation to apply tint/shade
        HSL colorSchemeHSL = RGBtoHSL(colorSchemeRGB);

        // apply it
        if (tintAndShade > 0)
        {
            colorSchemeHSL.L += (1 - colorSchemeHSL.L) * tintAndShade;
        }
        else
        {
            colorSchemeHSL.L *= 1 - Math.Abs(tintAndShade);
        }

        // do backward HSL -> RGB translation
        int tintedAndShadedRGB = HSLtoRGB(colorSchemeHSL);

        return(Color.FromArgb(tintedAndShadedRGB));
    }
Пример #2
0
        public void Demo()
        {
            #region radspreadsheet-model-features-styling-document-themes_0
            ThemeColorScheme colorScheme = new ThemeColorScheme(
                "Mine",
                Colors.Black,     // background 1
                Colors.Blue,      // text 1
                Colors.Brown,     // background 2
                Colors.Cyan,      // text 2
                Colors.DarkGray,  // accent 1
                Colors.Gray,      // accent 2
                Colors.Green,     // accent 3
                Colors.LightGray, // accent 4
                Colors.Magenta,   // accent 5
                Colors.Orange,    // accent 6
                Colors.Purple,    // hyperlink
                Colors.Red);      // followedHyperlink
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_1
            ThemableColor themableColor = new ThemableColor(ThemeColorType.Accent1);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_2
            ThemeFontScheme fontScheme = new ThemeFontScheme(
                "Mine",
                "Times New Roman",  // latinMajor
                "Arial");           // latinMinor
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_3
            ThemableFontFamily themableFont = new ThemableFontFamily(ThemeFontType.Major);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_4
            DocumentTheme theme = new DocumentTheme("Mine", colorScheme, fontScheme);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_5
            DocumentTheme theme1 = new DocumentTheme("From Predefined schemes", PredefinedThemeSchemes.ColorSchemes[0], PredefinedThemeSchemes.FontSchemes[5]);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_6
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();
            workbook.Theme = theme;
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_7
            Color actualColor = themableColor.GetActualValue(theme);
            // the actual color is the same as Accent1 color of the colorScheme
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_8
            var actualFont = themableFont.GetActualValue(theme);
            // the actualFont is the same as the Major font of the fontScheme
            #endregion
        }
Пример #3
0
 private void CreatingColorScheme()
 {
     #region radwordsprocessing-concepts-document-themes_0
     ThemeColorScheme colorScheme = new ThemeColorScheme(
         "Mine",
         Colors.Black,     // background 1
         Colors.Blue,      // text 1
         Colors.Brown,     // background 2
         Colors.Cyan,      // text 2
         Colors.DarkGray,  // accent 1
         Colors.Gray,      // accent 2
         Colors.Green,     // accent 3
         Colors.LightGray, // accent 4
         Colors.Magenta,   // accent 5
         Colors.Orange,    // accent 6
         Colors.Purple,    // hyperlink
         Colors.Red);      // followedHyperlink
     #endregion
 }
Пример #4
0
        private void SetWorkbookTheme()
        {
            ThemeColorScheme colorScheme = new ThemeColorScheme("ExpenseReport",
                                                                Color.FromArgb(255, 65, 65, 65),    // Background1
                                                                Color.FromArgb(255, 240, 240, 240), // Text1
                                                                Color.FromArgb(255, 0, 0, 0),       // Background2
                                                                Color.FromArgb(255, 255, 255, 255), // Text2
                                                                Color.FromArgb(255, 116, 202, 218), // Accent1
                                                                Color.FromArgb(255, 146, 204, 70),  // Accent2
                                                                Color.FromArgb(255, 241, 96, 61),   // Accent3
                                                                Color.FromArgb(255, 143, 145, 158), // Accent4
                                                                Color.FromArgb(255, 141, 119, 251), // Accent5
                                                                Color.FromArgb(255, 91, 119, 153),  // Accent6
                                                                Color.FromArgb(255, 5, 99, 193),    // Hyperlink
                                                                Color.FromArgb(255, 149, 79, 114)); // Followed hyperlink

            ThemeFontScheme fontScheme = new ThemeFontScheme("ExpenseReport", "Cambria", "Segoe UI");
            DocumentTheme   theme      = new DocumentTheme("ExpenseReport", colorScheme, fontScheme);

            this.workbook.Theme = theme;
        }
Пример #5
0
        /// <summary>
        /// Lấy màu của theme
        /// </summary>
        /// <param name="colorScheme"></param>
        /// <returns></returns>
        public EColorManagment GetEColorManagment(ThemeColorScheme colorScheme)
        {
            EColorManagment eColor = new EColorManagment();

            eColor.Accent1           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent1);
            eColor.Accent2           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent2);
            eColor.Accent3           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent3);
            eColor.Accent4           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent4);
            eColor.Accent5           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent5);
            eColor.Accent6           = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeAccent6);
            eColor.BackgroundDark1   = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeDark1);
            eColor.BackgroundDark2   = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeDark2);
            eColor.BackgroundLight1  = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeLight1);
            eColor.BackgroundLight2  = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeLight2);
            eColor.Hyperlink         = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeHyperlink);
            eColor.FollowedHyperlink = GetSolidColor(colorScheme, MsoThemeColorSchemeIndex.msoThemeFollowedHyperlink);
            ////Lấy color accent 1
            //Core.Model.SolidColor color = new Core.Model.SolidColor();
            //color.Brightness = 1;
            //color.Color = color

            return(eColor);
        }
Пример #6
0
        /// <summary>
        /// Lấy màu Solid Color
        /// </summary>
        /// <param name="themeColor"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public Core.Model.SolidColor GetSolidColor(ThemeColorScheme themeColor, MsoThemeColorSchemeIndex index)
        {
            Core.Model.SolidColor solid = new Core.Model.SolidColor();
            solid.Brightness = 1;
            solid.Color      = ConvertColor(themeColor.Colors(index).RGB);
            switch (index)
            {
            case MsoThemeColorSchemeIndex.msoThemeDark1:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounDark1").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounDark1").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeLight1:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounDark2").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounDark2").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeDark2:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounLight1").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounLight1").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeLight2:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounLight2").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_BackgrounLight2").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent1:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent1").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent1").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent2:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent2").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent2").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent3:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent3").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent3").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent4:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent4").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent4").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent5:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent5").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent5").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeAccent6:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent6").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Accent6").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeHyperlink:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_Hyperlink").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_Hyperlink").ToString();
                break;

            case MsoThemeColorSchemeIndex.msoThemeFollowedHyperlink:
                solid.Name        = System.Windows.Application.Current.TryFindResource("ColorGallery_FollowedHyperlink").ToString();
                solid.SpecialName = System.Windows.Application.Current.TryFindResource("ColorGallery_FollowedHyperlink").ToString();
                break;

            default:
                break;
            }
            return(solid);
        }
Пример #7
0
        private void SetWorkbookTheme()
        {
            ThemeColorScheme colorScheme = new ThemeColorScheme("ExpenseReport",
                       Color.FromArgb(255, 65, 65, 65),    // Background1
                       Color.FromArgb(255, 240, 240, 240), // Text1
                       Color.FromArgb(255, 0, 0, 0),       // Background2
                       Color.FromArgb(255, 255, 255, 255), // Text2
                       Color.FromArgb(255, 116, 202, 218), // Accent1
                       Color.FromArgb(255, 146, 204, 70),  // Accent2
                       Color.FromArgb(255, 241, 96, 61),   // Accent3
                       Color.FromArgb(255, 143, 145, 158), // Accent4
                       Color.FromArgb(255, 141, 119, 251), // Accent5
                       Color.FromArgb(255, 91, 119, 153),  // Accent6
                       Color.FromArgb(255, 5, 99, 193),    // Hyperlink
                       Color.FromArgb(255, 149, 79, 114)); // Followed hyperlink

            ThemeFontScheme fontScheme = new ThemeFontScheme("ExpenseReport", "Cambria", "Segoe UI");
            DocumentTheme theme = new DocumentTheme("ExpenseReport", colorScheme, fontScheme);
            this.workbook.Theme = theme;
        }
Пример #8
0
 private void CreatingTheme(ThemeColorScheme colorScheme, ThemeFontScheme fontScheme)
 {
     #region radwordsprocessing-concepts-document-themes_4
     DocumentTheme theme = new DocumentTheme("Mine", colorScheme, fontScheme);
     #endregion
 }