コード例 #1
0
        public override Task LoadAsync(IConfiguration configuration, IResourceLoader loader)
        {
            var link     = Link;
            var request  = link.CreateRequestFor(Url);
            var download = loader.DownloadAsync(request);

            SetDownload(download);

            return(link.ProcessResponse(download, response =>
            {
                var type = link.Type ?? MimeTypeNames.Css;
                var engine = configuration.GetStyleEngine(type);

                if (engine != null)
                {
                    var options = new StyleOptions
                    {
                        Element = link,
                        IsDisabled = link.IsDisabled,
                        IsAlternate = link.RelationList.Contains(Keywords.Alternate),
                        Configuration = configuration
                    };

                    _sheet = engine.ParseStylesheet(response, options);
                    _sheet.Media.MediaText = link.Media ?? String.Empty;
                }
            }));
        }
コード例 #2
0
        public static string ConvertFromFlowDocument(FlowDocument source, double base_font_size = 12)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml("<html><body></body></html>");

            var body = doc.DocumentNode.SelectSingleNode("//body");

            double fontsizemul = base_font_size / 12.0;

            var style = new StyleOptions()
            {
                Color              = Colors.White,
                FontWeight         = FontWeights.Normal,
                FontStyle          = FontStyles.Normal,
                TextDecoration     = null,
                FontSize           = 12,
                FontSizeMultiplier = fontsizemul
            };

            foreach (Paragraph i in source.Blocks)
            {
                ConvertParagraph(i, doc, body, style);
            }

            return(body.InnerHtml);
        }
コード例 #3
0
        private void CreateCell(string type, IRow row, int column, object value, StyleOptions styleOptions)
        {
            switch (type)
            {
            case "Boolean":
                CreateCell(row, column, Convert.ToBoolean(value), styleOptions);
                break;

            case "Short":
            case "Int16":
            case "Int32":
            case "Int64":
            case "Float":
            case "Double":
                CreateCell(row, column, Convert.ToDouble(value), styleOptions);
                break;

            case "Datetime":
                CreateCell(row, column, Convert.ToDateTime(value), styleOptions);
                break;

            default:
                CreateCell(row, column, value.ToString(), styleOptions);
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a style sheet for the given response asynchronously.
        /// </summary>
        /// <param name="response">
        /// The response with the stream representing the source of the
        /// stylesheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <param name="cancel">The cancellation token.</param>
        /// <returns>The task resulting in the style sheet.</returns>
        public async Task <IStyleSheet> ParseStylesheetAsync(IResponse response, StyleOptions options, CancellationToken cancel)
        {
            var context       = options.Context;
            var configuration = context.Configuration;
            var parser        = new CssParser(_options, configuration);
            var url           = response.Address?.Href;
            var sheet         = new CssStyleSheet(parser, url, options.Element)
            {
                IsDisabled = options.IsDisabled
            };
            var source    = new TextSource(response.Content);
            var tokenizer = new CssTokenizer(source);

            tokenizer.Error += (_, ev) => context.Fire(ev);
            var builder = new CssBuilder(tokenizer, parser);

            context.Fire(new CssParseEvent(sheet, completed: false));
            try
            {
                await parser.ParseStylesheetAsync(sheet, source).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                context.Fire(new CssErrorEvent(CssParseError.EOF, new TextPosition()));
            }
            context.Fire(new CssParseEvent(sheet, completed: true));
            return(sheet);
        }
コード例 #5
0
        private StyleOptions ConstructStyleFromShapeInfo(Shape shape)
        {
            var opt   = new StyleOptions();
            var props = opt.GetType().GetProperties();

            foreach (var propertyInfo in props)
            {
                var valueInStr = shape.Tags[Service.Effect.Tag.ReloadPrefix + propertyInfo.Name];
                if (string.IsNullOrEmpty(valueInStr))
                {
                    continue;
                }

                if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(opt, valueInStr, null);
                }
                else if (propertyInfo.PropertyType == typeof(int))
                {
                    var valueInInt = int.Parse(valueInStr);
                    propertyInfo.SetValue(opt, valueInInt, null);
                }
                else if (propertyInfo.PropertyType == typeof(bool))
                {
                    var valueInBool = bool.Parse(valueInStr);
                    propertyInfo.SetValue(opt, valueInBool, null);
                }
            }
            return(opt);
        }
コード例 #6
0
ファイル: HtmlLinkElement.cs プロジェクト: howej/AngleSharp
        void FinishLoading(Task <IResponse> task)
        {
            var type   = Type ?? MimeTypes.Css;
            var config = Owner.Options;
            var engine = config.GetStyleEngine(type);

            if (task.IsCompleted && !task.IsFaulted)
            {
                using (var response = task.Result)
                {
                    if (engine != null && RelationList.Contains(Keywords.StyleSheet))
                    {
                        var options = new StyleOptions
                        {
                            Element       = this,
                            Title         = Title,
                            IsDisabled    = IsDisabled,
                            IsAlternate   = RelationList.Contains(Keywords.Alternate),
                            Configuration = config
                        };

                        if (response != null)
                        {
                            try { _sheet = engine.ParseStylesheet(response, options); }
                            catch { /* Do not care here */ }
                        }
                    }
                }
            }

            this.FireLoadOrErrorEvent(task);
        }
コード例 #7
0
        private ICellStyle CreateCellStyle(StyleOptions options)
        {
            // 创建列头单元格实例样式
            ICellStyle cellStyle = workbook.CreateCellStyle();

            if (options.HorizontalAlignment.IsNotNull())
            {
                cellStyle.Alignment = (HorizontalAlignment)options.HorizontalAlignment;
            }
            if (options.VerticalAlignment.IsNotNull())
            {
                cellStyle.VerticalAlignment = (VerticalAlignment)options.VerticalAlignment;
            }

            // 背景色
            if (options.BackgroundColor >= 8)
            {
                cellStyle.FillForegroundColor = options.BackgroundColor;
                cellStyle.FillPattern         = FillPattern.SolidForeground;
            }

            var cellFont = workbook.CreateFont();

            cellFont.FontName           = options.FontName;
            cellFont.IsBold             = options.IsBold;
            cellFont.FontHeightInPoints = options.FontSize;
            cellFont.Color = options.FontColor;

            cellStyle.SetFont(cellFont);

            return(cellStyle);
        }
コード例 #8
0
        private void btnTmp_Click(object sender, EventArgs e)
        {
            List <User> users = new List <User>();

            for (int i = 1; i <= 10; i++)
            {
                users.Add(new User
                {
                    UserName    = "******" + i.ToString(),
                    Sex         = 10 % 2 == 0 ? "男" : "女",
                    NickName    = "昵称" + i.ToString(),
                    Email       = "mail" + i.ToString() + "@email.com",
                    PhoneNumber = "18800000000",
                    Status      = 1,
                    RegTime     = DateTime.Now,
                    IsOnline    = 10 % 3 == 0
                });
            }

            var titleStyleOptions = new StyleOptions
            {
                HorizontalAlignment = Office.Excel.Enums.SkylineHorizontalAlignment.Center,
                VerticalAlignment   = Office.Excel.Enums.SkylineVerticalAlignment.Center,
                BackgroundColor     = 13, // Color.Yellow,
                FontColor           = 10, // Color.Red,
                FontSize            = 20,
                FontName            = "微软雅黑",
                IsBold = true
            };
            var headerOptions = new StyleOptions
            {
                HorizontalAlignment = Office.Excel.Enums.SkylineHorizontalAlignment.Center,
                VerticalAlignment   = Office.Excel.Enums.SkylineVerticalAlignment.Center,
                FontSize            = 14,
                //FontName = "微软雅黑",
                FontColor = 12,// Color.Red,
                IsBold    = true
            };
            var contentOptions = new StyleOptions
            {
                HorizontalAlignment = Office.Excel.Enums.SkylineHorizontalAlignment.Center,
                VerticalAlignment   = Office.Excel.Enums.SkylineVerticalAlignment.Center,
                //FontSize = 20,
                //IsBold = true
            };
            ExcelUtil excelUtil = new ExcelUtil();

            excelUtil.CreateWorkbook("tmp.xlsx");
            excelUtil.CreateSheets("01");

            // var headers = new string[] { "用户姓名", "性别", "昵称", "邮箱", "手机号码", "状态", "注册时间", "是否在线" }
            var headers = GetHeader();

            //excelUtil.AddHeader("用户数据", headers, new RowOptions { });
            excelUtil.AddHeader("用户数据", headers, new RowOptions {
            }, titleStyleOptions, headerOptions);
            excelUtil.AddContent(users, contentOptions);
            excelUtil.SaveWorkbook();
        }
コード例 #9
0
        public void TestSerialization()
        {
            option.OptionName = "Test Option Name";
            option.Save(PathUtil.GetDocTestPath() + "option.user");
            var loadedOption = StyleOptions.Load(PathUtil.GetDocTestPath() + "option.user");

            Assert.AreEqual("Test Option Name", loadedOption.OptionName);
        }
コード例 #10
0
        public void TestApply()
        {
            variant.Set("OptionName", "test option name");
            var option = new StyleOptions();

            variant.Apply(option);
            Assert.AreEqual("test option name", option.OptionName);
        }
コード例 #11
0
        /// <summary>
        /// Creates a style declaration for the given source.
        /// </summary>
        /// <param name="source">
        /// The source code for the inline style declaration.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created style declaration.</returns>
        public ICssStyleDeclaration ParseInline(String source, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var style  = new CssStyleDeclaration(parser);

            style.Update(source);
            return(style);
        }
コード例 #12
0
        /// <summary>
        /// Creates a media list for the given source.
        /// </summary>
        /// <param name="source">The media source.</param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created media list.</returns>
        public IMediaList ParseMedia(String source, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var media  = new MediaList(parser);

            media.MediaText = source;
            return(media);
        }
コード例 #13
0
 public StyleOptions(StyleOptions copy)
     : this()
 {
     Color              = copy.Color;
     FontSize           = copy.FontSize;
     FontSizeMultiplier = copy.FontSizeMultiplier;
     FontWeight         = copy.FontWeight;
     FontStyle          = copy.FontStyle;
     TextDecoration     = copy.TextDecoration;
 }
コード例 #14
0
        /// <summary>
        /// Creates a style sheet for the given source.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code describing the style sheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet ParseStylesheet(String sourceCode, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var sheet  = new CssStyleSheet(parser, default(String), options.Element)
            {
                IsDisabled = options.IsDisabled
            };
            var source = new TextSource(sourceCode);

            return(Parse(parser, sheet, source).Result);
        }
コード例 #15
0
        private static void ConvertParagraph(Paragraph paragraph, HtmlDocument doc, HtmlNode body, StyleOptions base_style)
        {
            StyleOptions current_style = new StyleOptions(base_style);
            HtmlNode     working_node  = CreateStyleTags(paragraph, doc, body, body, ref current_style);

            foreach (var i in paragraph.Inlines)
            {
                ConvertInline(i, doc, body, base_style, ref working_node, ref current_style);
            }
            body.AppendChild(doc.CreateElement("br"));
        }
コード例 #16
0
        /// <summary>
        /// Creates a style sheet for the given response from a request.
        /// </summary>
        /// <param name="response">
        /// The response with the stream representing the source of the
        /// stylesheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet ParseStylesheet(IResponse response, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var sheet  = new CssStyleSheet(parser, response.Address.Href, options.Element)
            {
                IsDisabled = options.IsDisabled
            };
            var source = new TextSource(response.Content);

            return(Parse(parser, sheet, source).Result);
        }
コード例 #17
0
        /// <summary>
        /// Creates a media list for the given source.
        /// </summary>
        /// <param name="source">The media source.</param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created media list.</returns>
        public IMediaList ParseMedia(String source, StyleOptions options)
        {
            var configuration = options.Context.Configuration;
            var parser        = new CssParser(_options, configuration);
            var media         = new MediaList(parser)
            {
                MediaText = source
            };

            return(media);
        }
コード例 #18
0
        /// <summary>
        /// Creates a style sheet for the given response asynchronously.
        /// </summary>
        /// <param name="response">
        /// The response with the stream representing the source of the
        /// stylesheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <param name="cancel">The cancellation token.</param>
        /// <returns>The task resulting in the style sheet.</returns>
        public async Task <IStyleSheet> ParseStylesheetAsync(IResponse response, StyleOptions options, CancellationToken cancel)
        {
            var parser = new CssParser(_options, options.Configuration);
            var url    = response.Address != null ? response.Address.Href : null;
            var sheet  = new CssStyleSheet(parser, url, options.Element)
            {
                IsDisabled = options.IsDisabled
            };
            var source = new TextSource(response.Content);

            return(await Parse(parser, sheet, source).ConfigureAwait(false));
        }
コード例 #19
0
        /// <summary>
        /// Creates a style sheet for the given source.
        /// </summary>
        /// <param name="sourceCode">
        /// The source code describing the style sheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet ParseStylesheet(String sourceCode, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var sheet  = new CssStyleSheet(parser)
            {
                OwnerNode  = options.Element,
                IsDisabled = options.IsDisabled,
                Title      = options.Title
            };
            var source = new TextSource(sourceCode);

            return(Parse(parser, sheet, source));
        }
コード例 #20
0
        /// <summary>
        /// Creates a style sheet for the given source.
        /// </summary>
        /// <param name="source">The source code describing the style sheet.</param>
        /// <param name="options">The options with the parameters for evaluating the style.</param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet Parse(String source, StyleOptions options)
        {
            var style = new CssStyleSheet(source)
            {
                OwnerNode  = options.Element,
                IsDisabled = options.IsDisabled,
                Title      = options.Title
            };
            var parser = new CssParser(style);

            parser.Parse();
            return(style);
        }
コード例 #21
0
        /// <summary>
        /// Creates a style sheet for the given response from a request.
        /// </summary>
        /// <param name="response">The response with the stream representing the source of the stylesheet.</param>
        /// <param name="options">The options with the parameters for evaluating the style.</param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet Parse(IResponse response, StyleOptions options)
        {
            var style = new CssStyleSheet(new TextSource(response.Content))
            {
                Href       = response.Address.Href,
                OwnerNode  = options.Element,
                IsDisabled = options.IsDisabled,
                Title      = options.Title
            };
            var parser = new CssParser(style);

            parser.Parse();
            return(style);
        }
コード例 #22
0
        private ICell CreateCell(IRow row, int column, double cellValue, StyleOptions styleOptions)
        {
            var cell = row.CreateCell(column);

            if (cellValue.IsNotNull())
            {
                cell.SetCellValue(cellValue);
            }
            if (styleOptions != null)
            {
                cell.CellStyle = CreateCellStyle(styleOptions);
            }
            return(cell);
        }
コード例 #23
0
        /// <summary>
        /// Creates a style sheet for the given response from a request.
        /// </summary>
        /// <param name="response">
        /// The response with the stream representing the source of the
        /// stylesheet.
        /// </param>
        /// <param name="options">
        /// The options with the parameters for evaluating the style.
        /// </param>
        /// <returns>The created style sheet.</returns>
        public IStyleSheet ParseStylesheet(IResponse response, StyleOptions options)
        {
            var parser = new CssParser(_options, options.Configuration);
            var sheet  = new CssStyleSheet(parser)
            {
                Href       = response.Address.Href,
                OwnerNode  = options.Element,
                IsDisabled = options.IsDisabled,
                Title      = options.Title
            };
            var source = new TextSource(response.Content);

            return(Parse(parser, sheet, source));
        }
コード例 #24
0
        async Task CreateSheetAsync(IStyleEngine engine, IBrowsingContext context)
        {
            var cancel   = CancellationToken.None;
            var response = VirtualResponse.Create(res => res.Content(TextContent).Address(default(Url)));
            var options  = new StyleOptions(context)
            {
                Element     = this,
                IsDisabled  = IsDisabled,
                IsAlternate = false
            };
            var task = engine.ParseStylesheetAsync(response, options, cancel);

            _sheet = await task.ConfigureAwait(false);
        }
コード例 #25
0
        private ICell CreateCell(IRow row, int column, string cellValue, StyleOptions styleOptions)
        {
            var cell = row.CreateCell(column);

            if (!cellValue.IsNullOrWhiteSpace())
            {
                cell.SetCellValue(cellValue);
            }
            if (styleOptions != null)
            {
                cell.CellStyle = CreateCellStyle(styleOptions);
            }
            return(cell);
        }
コード例 #26
0
            public override bool Equals(object obj)
            {
                if (StyleOptions.ReferenceEquals(obj, null) || !(obj is StyleOptions))
                {
                    return(false);
                }
                StyleOptions cmp = (StyleOptions)obj;

                return
                    (cmp.Color == Color &&
                     cmp.FontSize == FontSize &&
                     cmp.FontWeight == FontWeight &&
                     cmp.FontStyle == FontStyle &&
                     Compare(cmp.TextDecoration, TextDecoration));
            }
コード例 #27
0
 void UpdateSheet()
 {
     if (Owner.Options.IsStyling)
     {
         var options = new StyleOptions
         {
             Element    = this,
             Document   = Owner,
             Context    = Owner.DefaultView,
             IsDisabled = IsDisabled,
             Title      = Title
         };
         _sheet = Owner.Options.ParseStyling(TextContent, options, Type);
     }
 }
コード例 #28
0
        public void TestCopy()
        {
            variant.Set("TextBoxPosition", 999);
            variant.Set("OptionName", "test option name");
            variant = variant.Copy(new StyleOptions());

            var option = new StyleOptions();

            option.TextBoxPosition = 999;
            option.OptionName      = "test option name";

            variant.Apply(option);
            Assert.AreEqual(5, option.TextBoxPosition);
            Assert.AreEqual("Reloaded", option.OptionName);
        }
コード例 #29
0
        IStyleSheet CreateSheet()
        {
            if (Owner.Options.IsStyling)
            {
                var options = new StyleOptions
                {
                    Element     = this,
                    IsDisabled  = IsDisabled,
                    Title       = Title,
                    IsAlternate = false
                };
                return(Owner.Options.ParseStyling(TextContent, options, Type));
            }

            return(null);
        }
コード例 #30
0
        protected override async Task ProcessResponseAsync(IResponse response)
        {
            var cancel  = CancellationToken.None;
            var options = new StyleOptions(_link.Owner)
            {
                Element     = _link,
                IsDisabled  = _link.IsDisabled,
                IsAlternate = _link.RelationList.Contains(Keywords.Alternate)
            };

            var task  = _engine.ParseStylesheetAsync(response, options, cancel);
            var sheet = await task.ConfigureAwait(false);

            sheet.Media.MediaText = _link.Media ?? String.Empty;
            Sheet = sheet;
        }
コード例 #31
0
ファイル: XtraGrid.cs プロジェクト: labeuze/source
        /// <summary>Définition d'un StyleOptions</summary>
        /// <param name="sStyle">Définition du style "None, StyleEnabled, UseBackColor, UseDrawEndEllipsis, UseDrawFocusRect, UseFont, UseForeColor, UseHorzAlignment, UseImage, UseVertAlignment, UseWordWrap"</param>
        /// <returns>true si le style a été défini</returns>
        public static bool GetStyleOptions(string sStyle, out StyleOptions style)
        {
            bool bStyle = false;

            style = StyleOptions.None;

            if (sStyle == null) return false;
            string[] sStyles = zsplit.Split(sStyle, ',', true);
            foreach (string s in sStyles)
            {
                switch (s.ToLower())
                {
                    case "none":
                        bStyle = true;
                        break;
                    case "styleenabled":
                        bStyle = true;
                        style |= StyleOptions.StyleEnabled;
                        break;
                    case "usebackcolor":
                        bStyle = true;
                        style |= StyleOptions.UseBackColor;
                        break;
                    case "usedrawendellipsis":
                        bStyle = true;
                        style |= StyleOptions.UseDrawEndEllipsis;
                        break;
                    case "usedrawfocusrect":
                        bStyle = true;
                        style |= StyleOptions.UseDrawFocusRect;
                        break;
                    case "usefont":
                        bStyle = true;
                        style |= StyleOptions.UseFont;
                        break;
                    case "useforecolor":
                        bStyle = true;
                        style |= StyleOptions.UseForeColor;
                        break;
                    case "usehorzalignment":
                        bStyle = true;
                        style |= StyleOptions.UseHorzAlignment;
                        break;
                    case "useimage":
                        bStyle = true;
                        style |= StyleOptions.UseImage;
                        break;
                    case "usevertalignment":
                        bStyle = true;
                        style |= StyleOptions.UseVertAlignment;
                        break;
                    case "usewordwrap":
                        bStyle = true;
                        style |= StyleOptions.UseWordWrap;
                        break;
                }
            }
            return bStyle;
        }