Ejemplo n.º 1
0
        internal AnchorActualInfo GetAnchorActualInfo(int anchorId)
        {
            Template.Anchor a = pageCollection.ActiveTemplate.Anchors.Find(x => x.Id == anchorId);
            if (a == null)
            {
                throw new Exception("Anchor[id=" + anchorId + "] does not exist.");
            }
            if (!a.IsSet())
            {
                throw new Exception("Anchor[id=" + anchorId + "] is not set.");
            }

            StringBuilder sb = new StringBuilder(Serialization.Json.Serialize(a, false));

            for (int?id = a.ParentAnchorId; id != null;)
            {
                Template.Anchor pa = pageCollection.ActiveTemplate.Anchors.Find(x => x.Id == id);
                sb.Append(Serialization.Json.Serialize(pa, false));
                id = pa.ParentAnchorId;
            }
            string sa = sb.ToString();

            if (!anchorHashes2anchorActualInfo.TryGetValue(sa, out AnchorActualInfo anchorActualInfo))
            {
                anchorActualInfo = new AnchorActualInfo(a, this);
                anchorHashes2anchorActualInfo[sa] = anchorActualInfo;
            }
            return(anchorActualInfo);
        }
Ejemplo n.º 2
0
        RectangleF?getFieldActualRectangle(Template.Field field)
        {
            if (!field.IsSet())
            {
                throw new Exception("Field is not set.");
            }
            if (field.Rectangle.Width <= Settings.Constants.CoordinateDeviationMargin || field.Rectangle.Height <= Settings.Constants.CoordinateDeviationMargin)
            {
                throw new Exception("Rectangle is malformed.");
            }
            RectangleF r = field.Rectangle.GetSystemRectangleF();

            if (field.LeftAnchor != null)
            {
                AnchorActualInfo aai = GetAnchorActualInfo(field.LeftAnchor.Id);
                if (!aai.Found)
                {
                    return(null);
                }
                float right = r.Right;
                r.X    += aai.Shift.Width - field.LeftAnchor.Shift;
                r.Width = right - r.X;
            }
            if (field.TopAnchor != null)
            {
                AnchorActualInfo aai = GetAnchorActualInfo(field.TopAnchor.Id);
                if (!aai.Found)
                {
                    return(null);
                }
                float bottom = r.Bottom;
                r.Y     += aai.Shift.Height - field.TopAnchor.Shift;
                r.Height = bottom - r.Y;
            }
            if (field.RightAnchor != null)
            {
                AnchorActualInfo aai = GetAnchorActualInfo(field.RightAnchor.Id);
                if (!aai.Found)
                {
                    return(null);
                }
                r.Width += aai.Shift.Width - field.RightAnchor.Shift;
            }
            if (field.BottomAnchor != null)
            {
                AnchorActualInfo aai = GetAnchorActualInfo(field.BottomAnchor.Id);
                if (!aai.Found)
                {
                    return(null);
                }
                r.Height += aai.Shift.Height - field.BottomAnchor.Shift;
            }
            //!!!???when all the anchors found then not null even if it is collapsed
            //if (r.Width <= 0 || r.Height <= 0)
            //    return null;
            return(r);
        }
Ejemplo n.º 3
0
        //internal AnchorActualInfo GetAnchorActualInfo(int anchorId)
        //{
        //    Template.Anchor a = PageCollection.ActiveTemplate.Anchors.Find(x => x.Id == anchorId);
        //    if (a == null)
        //        throw new Exception("Anchor[id=" + anchorId + "] does not exist.");
        //    if (!a.IsSet())
        //        throw new Exception("Anchor[id=" + anchorId + "] is not set.");

        //    StringBuilder sb = new StringBuilder(Serialization.Json.Serialize(a, false));
        //    for (int? id = a.ParentAnchorId; id != null;)
        //    {
        //        Template.Anchor pa = PageCollection.ActiveTemplate.Anchors.Find(x => x.Id == id);
        //        sb.Append(Serialization.Json.Serialize(pa, false));
        //        id = pa.ParentAnchorId;
        //    }
        //    string sa = sb.ToString();
        //    if (!anchorHashes2anchorActualInfo.TryGetValue(sa, out AnchorActualInfo anchorActualInfo))
        //    {
        //        anchorActualInfo = new AnchorActualInfo(a, this);
        //        anchorHashes2anchorActualInfo[sa] = anchorActualInfo;
        //    }
        //    return anchorActualInfo;
        //}
        //Dictionary<string, AnchorActualInfo> anchorHashes2anchorActualInfo = new Dictionary<string, AnchorActualInfo>();

        internal AnchorActualInfo GetAnchorActualInfo(int anchorId)
        {
            Template.Anchor a = PageCollection.ActiveTemplate.Anchors.Find(x => x.Id == anchorId);
            if (a == null)
            {
                throw new Exception("Anchor[id=" + anchorId + "] does not exist.");
            }
            if (!a.IsSet())
            {
                throw new Exception("Anchor[id=" + anchorId + "] is not set.");
            }

            if (!anchorIds2anchorActualInfo.TryGetValue(a.Id, out AnchorActualInfo anchorActualInfo))
            {
                anchorActualInfo = new AnchorActualInfo(a, this);
                anchorIds2anchorActualInfo[a.Id] = anchorActualInfo;
            }
            return(anchorActualInfo);
        }
Ejemplo n.º 4
0
 void findAnchor(Page page, Func <PointF, bool> findNext)
 {
     if (Anchor.ParentAnchorId != null)
     {
         Template.Anchor  pa   = page.PageCollection.ActiveTemplate.Anchors.Find(x => x.Id == Anchor.ParentAnchorId);
         AnchorActualInfo paai = new AnchorActualInfo(pa);
         paai.findAnchor(page, (PointF p) =>
         {
             bool found = page.findAnchor(Anchor, p, findNext);
             if (found)
             {
                 paai.Position          = p;
                 ParentAnchorActualInfo = paai;
             }
             return(!found);
         });
     }
     else
     {
         page.findAnchor(Anchor, new PointF(), findNext);
     }
 }