// Compute the Bounding Box of multilines public BBox Measure(string[] lines, float interline) { Outline.Point position = new Outline.Point(); // start at 0,0 Outline.Point lineTransition = new Outline.Point(0, -Height * interline); BBox bbox = new BBox(); foreach (string line in lines) { BBox lbox = Measure(line); lbox.Translate(position); bbox.Merge(lbox); position.Translate(lineTransition); } return(bbox); }
// Compute the Bounding Box a text line public BBox Measure(string txt) { BBox bbox = new BBox(); Outline.Point advance = new Outline.Point(); foreach (char c in txt) { Outline.Point cadv; BBox cbbox = Measure(c, out cadv); // translate char bbox to total advancement so far cbbox.Translate(advance); bbox.Merge(cbbox); // add char adv to total adv advance.Translate(cadv); } return(bbox); }
// Compute the Bounding Box of multilines public BBox Measure(string[] lines, float interline) { Outline.Point position = new Outline.Point(); // start at 0,0 Outline.Point lineTransition = new Outline.Point(0, - Height * interline); BBox bbox = new BBox(); foreach (string line in lines) { BBox lbox = Measure(line); lbox.Translate(position); bbox.Merge(lbox); position.Translate(lineTransition); } return bbox; }
// Compute the outline for a whole line public Outline GetStringOutline(string txt, ref Outline.Point position, HorizontalJustification h, VerticalJustification v, bool useKerning, float spacing, float emboldStrenght, int isteps) { Outline res = new Outline(); // first set pen position according to requested text justification if (h != HorizontalJustification.Origin || v != VerticalJustification.Origin) { // Compute Bounding box and set original advancement according to justification BBox bbox = Measure(txt); switch (h) { case HorizontalJustification.Left: position.X = position.X - bbox.xMin; break; case HorizontalJustification.Right: position.X = position.X - bbox.xMax; break; case HorizontalJustification.Center: position.X = position.X - (bbox.xMin + bbox.xMax) / 2; break; } switch (v) { case VerticalJustification.Top: position.Y = position.Y - bbox.yMax; break; case VerticalJustification.Bottom: position.Y = position.Y - bbox.yMin; break; case VerticalJustification.Center: position.Y = position.Y - (bbox.yMin + bbox.yMax) / 2; break; } } // Console.WriteLine("Original pen position=" + position); if (!HasKerning) { useKerning = false; } uint prev = 0; for (int i = 0; i < txt.Length; ++i) { uint idx = (uint)FT.FT_Get_Char_Index(face_, txt[i]); if (useKerning && prev != 0 && idx != 0) // adjust with kerning properties { position.Translate(GetKerning((uint)prev, idx)); } Outline.Point adv; Outline o = GetGlyphOutline(idx, out adv, true, emboldStrenght, isteps); o.Translate(position); res.AddOutline(o); adv.Scale(spacing); position.Translate(adv); prev = idx; } /* * foreach (char c in txt) * { * Outline.Point adv; * Outline o = GetGlyphOutline(c, out adv, true); * o.Translate(advance); * res.AddOutline(o); * advance.Translate(adv); * } */ return(res); }
// Compute the Bounding Box a text line public BBox Measure(string txt) { BBox bbox = new BBox(); Outline.Point advance = new Outline.Point(); foreach (char c in txt) { Outline.Point cadv; BBox cbbox = Measure(c, out cadv); // translate char bbox to total advancement so far cbbox.Translate(advance); bbox.Merge(cbbox); // add char adv to total adv advance.Translate(cadv); } return bbox; }