/// <summary> /// Próbuje pierwsze puste pole z listy u¿ywaj¹c najmniejszych pokrywaj¹cych prostok¹tów /// </summary> /// <param name="container"></param> /// <param name="r"></param> private bool SimpleMend(RectangleContainer container, Rectangle r) { if (container == null || r == null) throw new ArgumentNullException(); Rectangle empty = container.EmptyFields[0]; if (empty == null) return false; if (empty.LongerSide > r.LongerSide || empty.ShorterSide > r.ShorterSide) return false; if (!empty.RectangleOrientation.Equals(r.RectangleOrientation)) r.Rotate(); Point nLT = new Point(empty.RightDown.X - r.SideA, empty.RightDown.Y - r.SideB); if (nLT.X >= 0 && nLT.Y >= 0) { r.Move(nLT); rects.RemoveRectangle(r); } container.InsertRectangle(r); return true; }
/// <summary> /// Przygotowuje pierwszy prostokat do wstawienia do kontenera /// </summary> /// <param name="r">Prostok�t do wstawienia jako pierwszy</param> private void FirstRectanglePreparation(Rectangle r) { r.Move(new Point(0, 0)); this.maxCorrectRect = new Rectangle(r.LeftTop, r.RightDown); this.maxCorrectRect.ContainedRectangles.Add(r); this.maxPossibleRect = new Rectangle(r.LeftTop, r.RightDown); this.isCorrectRectangle = true; }
/// <summary> /// Wstawia prostok�t do kontenera /// </summary> /// <param name="r">Prostok�t do wstawienia</param> /// <param name="rLeftTop">Lewy g�rny wierzcho�ek prostok�ta</param> /// <param name="o">Orientacja prostok�ta</param> public void InsertRectangle(Rectangle r, Point rLeftTop, Rectangle.Orientation o) { Console.WriteLine("insert rect[(" + r.LeftTop.X + ", " + r.LeftTop.Y + "), (" + r.RightDown.X + ", " + r.RightDown.Y + ")]" + " -> (" + rLeftTop.X + ", " + rLeftTop.Y + ")"); InsertRectangleCheckParameters(r, rLeftTop); if (o.Equals(Rectangle.Orientation.Horizontal) && r.SideA < r.SideB) r.Rotate(); else if (o.Equals(Rectangle.Orientation.Vertical) && r.SideA > r.SideB) r.Rotate(); if (rectangles.Count == 0) FirstRectanglePreparation(r); else r.Move(rLeftTop); rectangles.Add(r); //jesli to byl pierwszy prostakat wszystko jest dobrze - nie trzeba tego robic if (rectangles.Count > 1) { // spr. czy po dodaniu wciaz prawidlowy prostokat if (isCorrectRectangle) { // doklejamy od dolu prostokata if (r.LeftTop.X == maxCorrectRect.LeftTop.X && r.RightDown.X == maxCorrectRect.RightDown.X && r.LeftTop.Y <= maxCorrectRect.RightDown.Y) UpdateMaxRectangles(r); // doklejamy z prawej strony prostokata else if (r.LeftTop.Y == maxCorrectRect.LeftTop.Y && r.RightDown.Y == maxCorrectRect.RightDown.Y && r.LeftTop.X <= maxCorrectRect.RightDown.X) UpdateMaxRectangles(r); // naklejamy na prostokat else if (maxCorrectRect.Covers(r)) r.SetParentRectangle(maxCorrectRect); // zaklejamy ca�y prostok�t - to r�wnie g�upi przypadek jak poprzedni, ale skoro kto� tak chce... else if (r.Covers(maxCorrectRect)) UpdateMaxRectangles(r); // calosc przestaje byc poprawnym prostokatem else { isCorrectRectangle = false; AddNewEmptyFields(r); UpdateMaxPossibleRectangle(r); } }// gdy calosc nie jest prawidlowym prostokatem else { //sprawdzenie czy dodanie prostokata nie pokrylo calkowicie jakichs emptyFields //spr. czy przeciecia dodanego z empty sa niepuste (jesli tak - usuwamy odpow. empty z listy i wstawiamy zamiast niego empty-dodany) //spr. czy nie zmienil sie maxPossibleRect UpdateEmptyFields(r); if (emptyFields.Count == 0) UpdateMaxCorrectAfterFillingAllEmpties(); UpdateMaxPossibleRectangle(r); } } }
/// <summary> /// Prostok�t do��czany do boku budowanego prostak�ta z prawej strony. /// </summary> /// <param name="outsRight">lista prostok�t�w na brzegu z prawej strony</param> /// <param name="outsDown">lista prostok�t�w na brzegu z do�u</param> /// <param name="holesRight">lista dziur z prawej strony</param> /// <param name="holesDown">lista dziur z do�u</param> /// <param name="rect">do��czany prostok�t</param> private void stickRectangleRight(List<OutRect> outsRight, List<OutRect> outsDown, List<Hole> holesRight, List<Hole> holesDown, Rectangle rect) { OutRect outRect; Hole hole; rect.Move(new Point(Min_X, 0)); updateMaxValues(rect); if (rect.SideB < Min_Y) { outRect = new OutRect(rect.SideA, rect.SideB, new Point(rect.LeftTop.X, rect.LeftTop.Y)); outsRight.Add(outRect); hole = new Hole(rect.SideA, Max_Y - rect.SideB, new Point(Min_X, rect.RightDown.Y)); hole.NeighbourOne = outRect; hole.OrientDown = true; hole.OrientRight = true; if (isCornerHole(holesDown)) hole.saveResize(rect.SideA, Min_Y - rect.SideB); else { hole.Corner = true; if (outsDown.Count > 0) hole.NeighbourSecond = outsDown[outsDown.Count - 1]; } holesRight.Add(hole); } else { if (Max_Y > Min_Y && !isCornerHole(holesDown) && outsDown.Count > 0) { hole = new Hole(Max_X - Min_X, Max_Y - Min_Y, new Point(Min_X, Min_Y)); hole.NeighbourOne = outsDown[outsDown.Count - 1]; hole.OrientDown = true; hole.OrientRight = true; hole.Corner = true; holesDown.Add(hole); } Min_X = rect.RightDown.X; } }
/// <summary> /// Prostok�t wype�nia na dan� dziur�. Ewentualnie mo�e powsta� nowa dziura. /// </summary> /// <param name="rect">dany prostok�t</param> /// <param name="newHole">powsta�a nowa dziura</param> /// <returns> /// 0 - prostok�t w ca�o�ci wype�ni� dan� dziur� - dziura do usuni�cia /// 1 - prostok�t wype�ni� cze�ciowo dan� dziur� - mo�liwa aktualizacja Min_X lub Min_Y /// -1 - prostok�t wype�ni� cz�ciowo dan� dziur� /// </returns> public int filled(Rectangle rect, out Hole newHole) { Point leftTop = new Point(_rect.LeftTop.X, _rect.LeftTop.Y); //Point rightTop = new Point(_rect.RightDown.X, _rect.RightDown.Y); int sideA = rect.SideA - _rect.SideA; int sideB = rect.SideB - _rect.SideB; int result = 0; rect.Move(leftTop); newHole = null; if (sideA >=0 && sideB >= 0) return 0; if (_orientRight && _orientDown) { result = 1; if (sideA < 0 && sideB < 0) { int holeSideA = _rect.SideA; _rect.Move(new Point(rect.RightDown.X, rect.LeftTop.Y)); saveResize(-sideA, rect.SideB); newHole = new Hole(holeSideA, -sideB, new Point(rect.LeftTop.X, rect.RightDown.Y)); if (_corner) { _corner = false; newHole.OrientRight = true; newHole.OrientDown = true; newHole.Corner = true; } } else if (sideA >= 0) { _rect.Move(new Point(rect.LeftTop.X, rect.RightDown.Y)); saveResize(rect.SideA, -sideB); } else if (sideB >= 0) { _rect.Move(new Point(rect.RightDown.X, rect.LeftTop.Y)); saveResize(-sideA, rect.SideB); } } else if (_orientRight) { if (sideB >= 0) { _rect.Move(new Point(rect.RightDown.X, rect.LeftTop.Y)); saveResize(-sideA, _rect.SideB); result = 1; } else { _rect.Move(new Point(rect.LeftTop.X, rect.RightDown.Y)); if(_neighbourSecond != null) saveResize(Math.Min(rect.SideA, _neighbourSecond.SideA), -sideB); result = -1; } } else if (_orientDown) { if (sideA >= 0) { _rect.Move(new Point(rect.LeftTop.X, rect.RightDown.Y)); saveResize(_rect.SideA, -sideB); result = 1; } else { _rect.Move(new Point(rect.RightDown.X, rect.LeftTop.Y)); if (_neighbourSecond != null) saveResize(-sideA, Math.Min(rect.SideB, _neighbourSecond.SideB)); result = -1; } } return result; }
public RenderedSlide RenderSlide(LiturgyLayoutRenderInfo renderInfo, Slide slide, List <Compiler.XenonCompilerMessage> messages) { RenderedSlide res = new RenderedSlide(); res.MediaType = MediaType.Image; res.AssetPath = ""; res.RenderedAs = "Liturgy"; // draw it // for now just draw the layout Bitmap bmp = new Bitmap(Layouts.LiturgyLayout.Size.Width, Layouts.LiturgyLayout.Size.Height); Bitmap kbmp = new Bitmap(Layouts.LiturgyLayout.Size.Width, Layouts.LiturgyLayout.Size.Height); Graphics gfx = Graphics.FromImage(bmp); Graphics kgfx = Graphics.FromImage(kbmp); Font LSBSymbolFont = new System.Drawing.Font("LSBSymbol", 36, System.Drawing.FontStyle.Regular); gfx.Clear(Color.Black); kgfx.Clear(Color.Black); gfx.FillRectangle(Brushes.White, Layouts.LiturgyLayout.Key); kgfx.FillRectangle(Brushes.White, Layouts.LiturgyLayout.Key); StringFormat topleftalign = new StringFormat() { LineAlignment = StringAlignment.Near, Alignment = StringAlignment.Near }; StringFormat centeralign = new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }; System.Drawing.Rectangle text = Layouts.LiturgyLayout.Text.Move(Layouts.LiturgyLayout.Key.Location); System.Drawing.Rectangle speaker = Layouts.LiturgyLayout.Speaker.Move(Layouts.LiturgyLayout.Key.Location); //gfx.DrawRectangle(Pens.Red, text); //gfx.DrawRectangle(Pens.Purple, speaker); // compute line spacing int textlinecombinedheight = 0; foreach (var line in slide.Lines) { textlinecombinedheight += (int)(float)line.Content[0].Attributes["height"]; } int interspace = (renderInfo.TextBox.Height - textlinecombinedheight) / (slide.Lines.Count + 1); int linenum = 0; int linepos = interspace; foreach (var line in slide.Lines) { gfx.DrawString(line.Content[0].Data, renderInfo.RegularFont, Brushes.Black, text.Move(0, linepos + interspace * linenum).Location, topleftalign); linenum++; linepos += (int)(float)line.Content[0].Attributes["height"]; } res.Bitmap = bmp; return(res); }