// /// <summary> /// async request for image /// </summary> /// <param name="binder"></param> /// <param name="requestFrom"></param> public void RequestImageAsync(ImageBinder binder, CssImageRun imgRun, object requestFrom) { if (_htmlVisualRoot != null) { _htmlVisualRoot.RaiseImageRequest( binder, requestFrom, false); } else { binder.LazyLoadImage(); } //-------------------------------------------------- if (binder.State == BinderState.Loaded) { Image img = binder.LocalImage; if (img != null) { //set real image info imgRun.ImageRectangle = new Rectangle( (int)imgRun.Left, (int)imgRun.Top, img.Width, img.Height); } } }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="controller">the html tag data of this box</param> public CssBoxImage(Css.BoxSpec boxSpec, RootGraphic rootgfx, ImageBinder binder) : base(boxSpec, rootgfx) { this._imgRun = new CssImageRun(); this._imgRun.ImageBinder = binder; this._imgRun.SetOwner(this); var runlist = new List<CssRun>(1); runlist.Add(_imgRun); CssBox.UnsafeSetContentRuns(this, runlist, false); }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="controller">the html tag data of this box</param> public CssBoxImage(Css.BoxSpec boxSpec, IRootGraphics rootgfx, ImageBinder binder) : base(boxSpec, rootgfx) { this._imgRun = new CssImageRun(); this._imgRun.ImageBinder = binder; this._imgRun.SetOwner(this); var runlist = new List <CssRun>(1); runlist.Add(_imgRun); CssBox.UnsafeSetContentRuns(this, runlist, false); }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="controller">the html tag data of this box</param> public CssBoxImage(Css.BoxSpec boxSpec, ImageBinder binder) : base(boxSpec) { _imgRun = new CssImageRun(); _imgRun.ImageBinder = binder; binder.ImageChanged += Binder_ImageChanged; _imgRun.SetOwner(this); // var runlist = new List <CssRun>(1); runlist.Add(_imgRun); CssBox.UnsafeSetContentRuns(this, runlist, false); }
public SvgImage(SvgImageSpec spec, object controller) : base(controller) { this.imageSpec = spec; this._imgRun = new LayoutFarm.HtmlBoxes.CssImageRun(); }
/// <summary> /// Measure image box size by the width\height set on the box and the actual rendered image size.<br/> /// If no image exists for the box error icon will be set. /// </summary> /// <param name="imgRun">the image word to measure</param> static void MeasureImageSize(CssImageRun imgRun, LayoutVisitor lay) { var width = imgRun.OwnerBox.Width; var height = imgRun.OwnerBox.Height; bool hasImageTagWidth = width.Number > 0 && width.UnitOrNames == Css.CssUnitOrNames.Pixels; bool hasImageTagHeight = height.Number > 0 && height.UnitOrNames == Css.CssUnitOrNames.Pixels; bool scaleImageHeight = false; if (hasImageTagWidth) { imgRun.Width = width.Number; } else if (width.Number > 0 && width.IsPercentage) { imgRun.Width = width.Number * lay.LatestContainingBlock.VisualWidth; scaleImageHeight = true; } else if (imgRun.HasUserImageContent) { imgRun.Width = imgRun.ImageRectangle == Rectangle.Empty ? imgRun.OriginalImageWidth : imgRun.ImageRectangle.Width; } else { imgRun.Width = hasImageTagHeight ? height.Number / 1.14f : 20; } var maxWidth = imgRun.OwnerBox.MaxWidth;// new CssLength(imageWord.OwnerBox.MaxWidth); if (maxWidth.Number > 0) { float maxWidthVal = -1; switch (maxWidth.UnitOrNames) { case Css.CssUnitOrNames.Percent: { maxWidthVal = maxWidth.Number * lay.LatestContainingBlock.VisualWidth; } break; case Css.CssUnitOrNames.Pixels: { maxWidthVal = maxWidth.Number; } break; } if (maxWidthVal > -1 && imgRun.Width > maxWidthVal) { imgRun.Width = maxWidthVal; scaleImageHeight = !hasImageTagHeight; } } if (hasImageTagHeight) { imgRun.Height = height.Number; } else if (imgRun.HasUserImageContent) { imgRun.Height = imgRun.ImageRectangle == Rectangle.Empty ? imgRun.OriginalImageHeight : imgRun.ImageRectangle.Height; } else { imgRun.Height = imgRun.Width > 0 ? imgRun.Width * 1.14f : 22.8f; } if (imgRun.HasUserImageContent) { // If only the width was set in the html tag, ratio the height. if ((hasImageTagWidth && !hasImageTagHeight) || scaleImageHeight) { // Divide the given tag width with the actual image width, to get the ratio. float ratio = imgRun.Width / imgRun.OriginalImageWidth; imgRun.Height = imgRun.OriginalImageHeight * ratio; } // If only the height was set in the html tag, ratio the width. else if (hasImageTagHeight && !hasImageTagWidth) { // Divide the given tag height with the actual image height, to get the ratio. float ratio = imgRun.Height / imgRun.OriginalImageHeight; imgRun.Width = imgRun.OriginalImageWidth * ratio; } } //imageWord.Height += imageWord.OwnerBox.ActualBorderBottomWidth + imageWord.OwnerBox.ActualBorderTopWidth + imageWord.OwnerBox.ActualPaddingTop + imageWord.OwnerBox.ActualPaddingBottom; }
/// <summary> /// async request for image /// </summary> /// <param name="binder"></param> /// <param name="requestFrom"></param> public void RequestImageAsync(ImageBinder binder, CssImageRun imgRun, object requestFrom) { if (htmlContainer != null) { this.htmlContainer.RaiseImageRequest( binder, requestFrom, false); } else { binder.LazyLoadImage(); } //-------------------------------------------------- if (binder.State == ImageBinderState.Loaded) { Image img = binder.Image; if (img != null) { //set real image info imgRun.ImageRectangle = new Rectangle( (int)imgRun.Left, (int)imgRun.Top, img.Width, img.Height); } } }