Exemplo n.º 1
0
 public CssNumericToken(CssTokenType tokenType, string value, string unit = null)
     : base(tokenType)
 {
     ArgChecker.AssertArgNotNullOrEmpty(value, nameof(value));
     _unparsedValue = value;
     _value         = new CssNumeric(double.Parse(value, CultureInfo.InvariantCulture), unit);
 }
Exemplo n.º 2
0
 internal CssTypeSelector(string localName, string namespacePrefix, CssSpecificity specificity)
     : base(specificity)
 {
     ArgChecker.AssertArgNotNullOrEmpty(localName, nameof(localName));
     _localName       = localName;
     _namespacePrefix = namespacePrefix;
 }
Exemplo n.º 3
0
 public CssDeclaration(string name, ImmutableArray <CssToken> values, bool isImportant)
 {
     ArgChecker.AssertArgNotNullOrEmpty(name, nameof(name));
     _name        = name;
     _values      = values;
     _isImportant = isImportant;
 }
Exemplo n.º 4
0
 internal CssTypeSelector(string localName, string namespacePrefix)
     : base(localName == AnyLocalName ? UniversalSpecificity : DefaultSpecificity)
 {
     ArgChecker.AssertArgNotNullOrEmpty(localName, nameof(localName));
     _localName       = localName;
     _namespacePrefix = namespacePrefix;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Callback to overwrite the loaded image with image to load from given URI.<br/>
        /// Can be called directly from delegate handler or asynchronously after setting <see cref="Handled"/> to True.<br/>
        /// </summary>
        /// <param name="path">the path to the image to load (file path or URL)</param>
        public void Callback(string path)
        {
            ArgChecker.AssertArgNotNullOrEmpty(path, "path");

            _handled = true;
            _callback(path, null, RRect.Empty);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a font mapping from <paramref name="fromFamily"/> to <paramref name="toFamily"/> iff the <paramref name="fromFamily"/> is not found.<br/>
        /// When the <paramref name="fromFamily"/> font is used in rendered html and is not found in existing
        /// fonts (installed or added) it will be replaced by <paramref name="toFamily"/>.<br/>
        /// </summary>
        /// <remarks>
        /// This fonts mapping can be used as a fallback in case the requested font is not installed in the client system.
        /// </remarks>
        /// <param name="fromFamily">the font family to replace</param>
        /// <param name="toFamily">the font family to replace with</param>
        public static void AddFontFamilyMapping(string fromFamily, string toFamily)
        {
            ArgChecker.AssertArgNotNullOrEmpty(fromFamily, "fromFamily");
            ArgChecker.AssertArgNotNullOrEmpty(toFamily, "toFamily");

            FontsUtils.AddFontFamilyMapping(fromFamily, toFamily);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a font mapping from <paramref name="fromFamily"/> to <paramref name="toFamily"/> iff the <paramref name="fromFamily"/> is not found.<br/>
        /// When the <paramref name="fromFamily"/> font is used in rendered html and is not found in existing
        /// fonts (installed or added) it will be replaced by <paramref name="toFamily"/>.<br/>
        /// </summary>
        /// <param name="fromFamily">the font family to replace</param>
        /// <param name="toFamily">the font family to replace with</param>
        public void AddFontFamilyMapping(string fromFamily, string toFamily)
        {
            ArgChecker.AssertArgNotNullOrEmpty(fromFamily, "fromFamily");
            ArgChecker.AssertArgNotNullOrEmpty(toFamily, "toFamily");

            this._fontsMapping[fromFamily] = toFamily;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new block from the block's source
        /// </summary>
        /// <param name="class">the name of the css class of the block</param>
        /// <param name="directParent"> </param>
        public CssBlockSelectorItem(string @class, bool directParent)
        {
            ArgChecker.AssertArgNotNullOrEmpty(@class, "@class");

            _class        = @class;
            _directParent = directParent;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Callback to overwrite the loaded image with image to load from given URI.<br/>
        /// Can be called directly from delegate handler or asynchronously after setting <see cref="Handled"/> to True.<br/>
        /// If <paramref name="imageRectangle"/> is given (not <see cref="System.Drawing.Rectangle.Empty"/>) then only the specified rectangle will
        /// be used from the loaded image and not all of it, also the rectangle will be used for size and not the actual image size.<br/>
        /// </summary>
        /// <param name="path">the path to the image to load (file path or URL)</param>
        /// <param name="imageRectangle">optional: limit to specific rectangle of the image and not all of it</param>
        public void Callback(string path, Rectangle imageRectangle = new Rectangle())
        {
            ArgChecker.AssertArgNotNullOrEmpty(path, "path");

            _handled = true;
            _callback(path, null, imageRectangle);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Init.
        /// </summary>
        /// <param name="name">the name of the html tag</param>
        /// <param name="attributes">collection of attributes and thier value the html tag has</param>
        /// <param name="text">the text sub-string of the html element</param>
        public HtmlTag(string name, Dictionary <string, string> attributes = null)
        {
            ArgChecker.AssertArgNotNullOrEmpty(name, "name");

            _name       = name;
            _attributes = attributes;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Adds a font mapping from <paramref name="fromFamily"/> to <paramref name="toFamily"/> iff the <paramref name="fromFamily"/> is not found.<br/>
        /// When the <paramref name="fromFamily"/> font is used in rendered html and is not found in existing
        /// fonts (installed or added) it will be replaced by <paramref name="toFamily"/>.<br/>
        /// </summary>
        /// <remarks>
        /// This fonts mapping can be used as a fallback in case the requested font is not installed in the client system.
        /// </remarks>
        /// <param name="fromFamily">the font family to replace</param>
        /// <param name="toFamily">the font family to replace with</param>
        public static void AddFontFamilyMapping(string fromFamily, string toFamily)
        {
            ArgChecker.AssertArgNotNullOrEmpty(fromFamily, "fromFamily");
            ArgChecker.AssertArgNotNullOrEmpty(toFamily, "toFamily");

            PdfSharpAdapter.Instance.AddFontFamilyMapping(fromFamily, toFamily);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Callback to overwrite the loaded image with image to load from given URI.<br/>
        /// Can be called directly from delegate handler or asynchronously after setting <see cref="Handled"/> to True.<br/>
        /// Only the specified rectangle (x,y,width,height) will be used from the loaded image and not all of it, also
        /// the rectangle will be used for size and not the actual image size.<br/>
        /// </summary>
        /// <param name="path">the path to the image to load (file path or URL)</param>
        /// <param name="imageRectangle">optional: limit to specific rectangle of the image and not all of it</param>
        public void Callback(string path, double x, double y, double width, double height)
        {
            ArgChecker.AssertArgNotNullOrEmpty(path, "path");

            _handled = true;
            _callback(path, null, new RRect(x, y, width, height));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get attribute value of element at the given x,y location by given key.<br/>
        /// If more than one element exist with the attribute at the location the inner most is returned.
        /// </summary>
        /// <param name="location">the location to find the attribute at</param>
        /// <param name="attribute">the attribute key to get value by</param>
        /// <returns>found attribute value or null if not found</returns>
        public string GetAttributeAt(RPoint location, string attribute)
        {
            ArgChecker.AssertArgNotNullOrEmpty(attribute, "attribute");

            var cssBox = DomUtils.GetCssBox(this._root, this.OffsetByScroll(location));

            return(cssBox != null?DomUtils.GetAttribute(cssBox, attribute) : null);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Init.
        /// </summary>
        /// <param name="name">the name of the html tag</param>
        /// <param name="attributes">collection of attributes and thier value the html tag has</param>
        /// <param name="isClosing">is the html tag is closing tag</param>
        public HtmlTag(string name, Dictionary <string, string> attributes = null, bool isClosing = false)
        {
            ArgChecker.AssertArgNotNullOrEmpty(name, "name");

            _name       = name;
            _attributes = attributes ?? new Dictionary <string, string>();
            _isClosing  = isClosing;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Init.
        /// </summary>
        /// <param name="name">the name of the html tag</param>
        /// <param name="isSingle">if the tag is single placed; in other words it doesn't have a separate closing tag;</param>
        /// <param name="attributes">collection of attributes and their value the html tag has</param>
        public HtmlTag(string name, bool isSingle, Dictionary <string, string> attributes = null)
        {
            ArgChecker.AssertArgNotNullOrEmpty(name, "name");

            this._name       = name;
            this._isSingle   = isSingle;
            this._attributes = attributes;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Get the rectangle of html element as calculated by html layout.<br/>
        /// Element if found by id (id attribute on the html element).<br/>
        /// Note: to get the screen rectangle you need to adjust by the hosting control.<br/>
        /// </summary>
        /// <param name="elementId">the id of the element to get its rectangle</param>
        /// <returns>the rectangle of the element or null if not found</returns>
        public RRect?GetElementRectangle(string elementId)
        {
            ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId");

            var box = DomUtils.GetBoxById(this._root, elementId.ToLower());

            return(box != null?CommonUtils.GetFirstValueOrDefault(box.Rectangles, box.Bounds) : (RRect?)null);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get the rectangle of html element as calculated by html layout.<br/>
        /// Element if found by id (id attribute on the html element).<br/>
        /// Note: to get the screen rectangle you need to adjust by the hosting control.<br/>
        /// </summary>
        /// <param name="elementId">the id of the element to get its rectangle</param>
        /// <returns>the rectangle of the element or null if not found</returns>
        public RRect?GetElementRectangle(string elementId, out List <string> elementsIds, out CssBox box)
        {
            elementsIds = new List <string>();
            ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId");

            box = DomUtils.GetBoxById(_root, elementId.ToLower(), ref elementsIds);

            return(box != null?CommonUtils.GetFirstValueOrDefault(box.Rectangles, box.Bounds) : (RRect?)null);
        }
Exemplo n.º 18
0
        public override void AddItem(string text, bool enabled, EventHandler onClick)
        {
            ArgChecker.AssertArgNotNullOrEmpty(text, "text");
            ArgChecker.AssertArgNotNull(onClick, "onClick");

            var item = _contextMenu.Items.Add(text, null, onClick);

            item.Enabled = enabled;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Creates a new block from the block's source
        /// </summary>
        /// <param name="class">the name of the css class of the block</param>
        /// <param name="properties">the CSS block properties and values</param>
        /// <param name="selectors">optional: additional selectors to used in hierarchy</param>
        public CssBlock(string @class, Dictionary <string, string> properties, List <CssBlockSelectorItem> selectors = null)
        {
            ArgChecker.AssertArgNotNullOrEmpty(@class, "@class");
            ArgChecker.AssertArgNotNull(properties, "properties");

            _class      = @class;
            _selectors  = selectors;
            _properties = properties;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Creates a new block from the block's source
        /// </summary>
        /// <param name="class">the name of the css class of the block</param>
        /// <param name="properties">the CSS block properties and values</param>
        /// <param name="selectors">optional: additional selectors to used in hierarchy</param>
        /// <param name="hover">optional: is the css block has :hover pseudo-class</param>
        public CssBlock(string @class, Dictionary <string, string> properties, List <CssBlockSelectorItem> selectors = null, bool hover = false)
        {
            ArgChecker.AssertArgNotNullOrEmpty(@class, "@class");
            ArgChecker.AssertArgNotNull(properties, "properties");

            this._class      = @class;
            this._selectors  = selectors;
            this._properties = properties;
            this._hover      = hover;
        }
Exemplo n.º 21
0
        public override void AddItem(string text, bool enabled, EventHandler onClick)
        {
            ArgChecker.AssertArgNotNullOrEmpty(text, "text");
            ArgChecker.AssertArgNotNull(onClick, "onClick");

            var item = new MenuItem();

            item.Header    = text;
            item.IsEnabled = enabled;
            item.Click    += new RoutedEventHandler(onClick);
            _contextMenu.Items.Add(item);
        }
Exemplo n.º 22
0
        public override void AddItem(string text, bool enabled, EventHandler onClick)
        {
            ArgChecker.AssertArgNotNullOrEmpty(text, "text");
            ArgChecker.AssertArgNotNull(onClick, "onClick");

            var item = new ButtonMenuItem {
                Text = text, Enabled = enabled
            };

            item.Click += (sender, e) => onClick(sender, e);
            _contextMenu.Items.Add(item);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Adjust the scrollbar of the panel on html element by the given id.<br/>
        /// The top of the html element rectangle will be at the top of the panel, if there
        /// is not enough height to scroll to the top the scroll will be at maximum.<br/>
        /// </summary>
        /// <param name="elementId">the id of the element to scroll to</param>
        public virtual void ScrollToElement(string elementId, out string result, out List <string> availableIds)
        {
            availableIds = new List <string>();
            result       = "_htmlContainer is null";
            ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId");

            if (_htmlContainer != null)
            {
                result = "id not found";
                CssBox box  = null;
                var    rect = _htmlContainer.GetElementRectangle(elementId, out availableIds, out box);
                if (rect.HasValue)
                {
                    result = "";//Scrolled to " + rect.Value.Location.X + ":" + rect.Value.Location.Y;
                    Dispatcher.Invoke(new Action(() =>
                    {
                        ScrollToPoint(rect.Value.Location.X, Math.Max(rect.Value.Location.Y - 50, 0));
                        box.BorderLeftColor          = "red";
                        box.BorderLeftStyle          = "solid";
                        box.BorderLeftWidth          = "2px";
                        box.PaddingLeft              = "3px";
                        System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
                        t.Interval = 300;
                        this.InvalidateVisual();
                        int counter = 0;
                        t.Tick     += (sen, ev) =>
                        {
                            if (counter == 6)
                            {
                                t.Stop();
                                box.BorderLeftColor = "black";
                                box.BorderLeftStyle = "none";
                                box.BorderLeftWidth = "0";
                                box.PaddingLeft     = "0";
                            }
                            if (counter % 2 == 0)
                            {
                                box.BorderLeftWidth = "2px";
                            }
                            else
                            {
                                box.BorderLeftWidth = "0px";
                            }
                            this.InvalidateVisual();
                            counter++;
                        };
                        t.Start();
                        _htmlContainer.HandleMouseMove(this, Mouse.GetPosition(this));
                    }));
                }
            }
        }
Exemplo n.º 24
0
        internal CssAttributeSelector(string localName, string namespacePrefix, CssAttributeMatchOperator matchOperator, CssStringToken matchOperand)
            : base(DefaultSpecificity)
        {
            ArgChecker.AssertArgNotNullOrEmpty(localName, nameof(localName));
            ArgChecker.AssertIsTrue <ArgumentNullException>(
                matchOperator == CssAttributeMatchOperator.Any || matchOperand != null,
                string.Format(CultureInfo.InvariantCulture, "The {0} is required for match operator '{1}'.", nameof(matchOperand), matchOperator));

            _localName       = localName;
            _namespacePrefix = namespacePrefix;
            _matchOperator   = matchOperator;
            _matchOperand    = matchOperand;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Adjust the scrollbar of the panel on html element by the given id.<br/>
        /// The top of the html element rectangle will be at the top of the panel, if there
        /// is not enough height to scroll to the top the scroll will be at maximum.<br/>
        /// </summary>
        /// <param name="elementId">the id of the element to scroll to</param>
        public virtual void ScrollToElement(string elementId)
        {
            ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId");

            if (_htmlContainer != null)
            {
                var rect = _htmlContainer.GetElementRectangle(elementId);
                if (rect.HasValue)
                {
                    UpdateScroll(Point.Round(rect.Value.Location));
                    _htmlContainer.HandleMouseMove(this, new MouseEventArgs(MouseButtons, 0, MousePosition.X, MousePosition.Y, 0));
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Adjust the scrollbar of the panel on html element by the given id.<br/>
        /// The top of the html element rectangle will be at the top of the panel, if there
        /// is not enough height to scroll to the top the scroll will be at maximum.<br/>
        /// </summary>
        /// <param name="elementId">the id of the element to scroll to</param>
        public virtual void ScrollToElement(string elementId)
        {
            ArgChecker.AssertArgNotNullOrEmpty(elementId, "elementId");

            if (_htmlContainer != null)
            {
                var rect = _htmlContainer.GetElementRectangle(elementId);
                if (rect.HasValue)
                {
                    ScrollToPoint(rect.Value.Location.X, rect.Value.Location.Y);
                    _htmlContainer.HandleMouseMove(this, Mouse.GetPosition(this));
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Init with optinals document and stylesheet.
        /// </summary>
        /// <param name="htmlSource">the html to init with, init empty if not given</param>
        /// <param name="bridge">used to resolve external references in html code (property, method calls)</param>
        /// <param name="baseCssData">optional: the stylesheet to init with, init default if not given</param>
        public HtmlContainer(string htmlSource, object bridge, CssData baseCssData = null)
        {
            ArgChecker.AssertArgNotNullOrEmpty(htmlSource, "htmlSource");

            _bridge  = bridge;
            _cssData = baseCssData ?? CssUtils.DefaultCssData;

            if (htmlSource != null)
            {
                _root = DomParser.GenerateCssTree(htmlSource, ref _cssData, bridge);
                if (_root != null)
                {
                    _root.HtmlContainer = this;
                    _selectionHandler   = new SelectionHandler(_root);
                }
            }
        }
Exemplo n.º 28
0
 public CssFunction(string name, ImmutableArray <CssComponent> components)
     : base(components)
 {
     ArgChecker.AssertArgNotNullOrEmpty(name, nameof(name));
     this.Name = name;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Resolve color value from given color name.
 /// </summary>
 /// <param name="colorName">the color name</param>
 /// <returns>color value</returns>
 public RColor GetColor(string colorName)
 {
     ArgChecker.AssertArgNotNullOrEmpty(colorName, "colorName");
     return(GetColorInt(colorName));
 }
Exemplo n.º 30
0
 internal CssIdSelector(string id)
     : base(DefaultSpecificity)
 {
     ArgChecker.AssertArgNotNullOrEmpty(id, nameof(id));
     _id = id;
 }