public void Merge(BBox b) { xMin = Math.Min(xMin, b.xMin); yMin = Math.Min(yMin, b.yMin); xMax = Math.Max(xMax, b.xMax); yMax = Math.Max(yMax, b.yMax); }
// 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); }
public Outline GetTextOutline(string[] lines, ref Outline.Point position, HorizontalJustification h, VerticalJustification v, bool useKerning, float interline) { //int nblines = lines.Length; // total cbox BBox bbox = Measure(lines, interline); float startY = 0; switch (v) { case VerticalJustification.Origin: startY = position.Y; break; case VerticalJustification.Top: startY = position.Y - bbox.yMax; break; case VerticalJustification.Bottom: startY = position.Y - bbox.yMin; break; case VerticalJustification.Center: startY = position.Y + (bbox.yMax - bbox.yMin) / 2 - bbox.yMax; break; } Outline outline = new Outline(); Outline.Point pos = new Outline.Point(); foreach (string line in lines) { pos.X = position.X; pos.Y = startY; Outline o = GetStringOutline(line, ref pos, h, VerticalJustification.Origin, useKerning); outline.AddOutline(o); startY -= Height * interline; } return(outline); }
// 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 a single glyph public BBox Measure(char c, out Outline.Point advance) { // load glyph for c in face slot int code = FT.FT_Load_Char(face_, (uint)c, (int)(FT.FT_LOAD_DEFAULT | (1 << 3))); // FT_LOAD_DEFAULT, FT_LOAD_NO_BITMAP, FT_LOAD_NO_SCALE ? FT.CheckError(code); // Check that the glyph is in Outline format FT.FT_FaceRec facerec = FT.HandleToRecord <FT.FT_FaceRec>(face_); IntPtr slot = facerec.glyph; FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord <FT.FT_GlyphSlotRec>(slot); if (slotrec.format != FT.GLYPH_FORMAT_OUTLINE) { throw new FTError("Bad glyph format (" + slotrec.format + ")"); } // get glyph in gptr IntPtr gptr; code = FT.FT_Get_Glyph(slotrec, out gptr); FT.CheckError(code); FT.FT_BBox ft_bbox; FT.FT_Glyph_Get_CBox(gptr, 0, out ft_bbox); FT.FT_Done_Glyph(gptr); BBox bbox = new BBox(ft_bbox, vectorScale_); advance = new Outline.Point(slotrec.advance, vectorScale_); 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 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 a single glyph public BBox Measure(char c, out Outline.Point advance) { // load glyph for c in face slot int code = FT.FT_Load_Char(face_, (uint)c, (int)(FT.FT_LOAD_DEFAULT|( 1 << 3 ))); // FT_LOAD_DEFAULT, FT_LOAD_NO_BITMAP, FT_LOAD_NO_SCALE ? FT.CheckError(code); // Check that the glyph is in Outline format FT.FT_FaceRec facerec = FT.HandleToRecord<FT.FT_FaceRec>(face_); IntPtr slot = facerec.glyph; FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord<FT.FT_GlyphSlotRec>(slot); if (slotrec.format != FT.GLYPH_FORMAT_OUTLINE) { throw new FTError("Bad glyph format (" + slotrec.format + ")"); } // get glyph in gptr IntPtr gptr; code = FT.FT_Get_Glyph(slot, out gptr); FT.CheckError(code); FT.FT_BBox ft_bbox; FT.FT_Glyph_Get_CBox(gptr, 0, out ft_bbox); FT.FT_Done_Glyph(gptr); BBox bbox = new BBox(ft_bbox, vectorScale_); advance = new Outline.Point(slotrec.advance, vectorScale_); return bbox; }