Esempio n. 1
0
		public static ABC GetCharWidthABC(char ch, Font font, System.Drawing.Graphics gr)
		{
			ABC[] _temp = new ABC[1];
			var nativFont = CreateFont (font.Name, font.Size, font.Style, font.GdiCharSet, font.GdiVerticalFont);
			var atts = buildAttributedString(ch.ToString(), nativFont);
			// for now just a line not sure if this is going to work
			CTLine line = new CTLine(atts);

			float ascent;
			float descent;
			float leading;
			_temp[0].abcB = (uint)line.GetTypographicBounds(out ascent, out descent, out leading);


			return _temp[0];
		}
 static void PrepareGlyphArcInfo (CTLine line, long glyphCount, GlyphArcInfo[] glyphArcInfo)
 {
         var runArray = line.GetGlyphRuns ();
         
         // Examine each run in the line, updating glyphOffset to track how far along the run is 
         // in terms of glyphCount.
         long glyphOffset = 0;
         float ascent = 0;
         float descent = 0;
         float leading = 0;
         foreach (var run in runArray) {
                 var runGlyphCount = run.GlyphCount;
                 
                 // Ask for the width of each glyph in turn.
                 var runGlyphIndex = 0;
                 for (; runGlyphIndex < runGlyphCount; runGlyphIndex++) {
                         glyphArcInfo[runGlyphIndex + glyphOffset].width = (float)run.GetTypographicBounds (new NSRange (runGlyphIndex, 1), out ascent, out descent, out leading);
                         
                 }
                 
                 glyphOffset += runGlyphCount;
                 
         }
         
         var lineLength = line.GetTypographicBounds (out ascent, out descent, out leading);
         
         var prevHalfWidth = glyphArcInfo[0].width / 2.0;
         glyphArcInfo[0].angle = (float)((prevHalfWidth / lineLength) * Math.PI);
         
         var lineGlyphIndex = 1;
         for (; lineGlyphIndex < glyphCount; lineGlyphIndex++) {
                 
                 var halfWidth = glyphArcInfo[lineGlyphIndex].width / 2.0;
                 var prevCenterToCenter = prevHalfWidth + halfWidth;
                 
                 glyphArcInfo[lineGlyphIndex].angle = (float)((prevCenterToCenter / lineLength) * Math.PI);
                 
                 prevHalfWidth = halfWidth;
                 
         }
 }
        public SizeF MeasureString(string textg, Font font, RectangleF rect)
        {
            // As per documentation
            // https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101
            //
            // * Note * Not sure if we should save off the graphic state, set context transform to identity
            //  and restore state to do the measurement.  Something to be looked into.
            //			context.TextPosition = rect.Location;
            //			var startPos = context.TextPosition;
            //			context.SelectFont ( font.nativeFont.PostScriptName,
            //			                    font.SizeInPoints,
            //			                    CGTextEncoding.MacRoman);
            //			context.SetTextDrawingMode(CGTextDrawingMode.Invisible);
            //
            //			context.SetCharacterSpacing(1);
            //			var textMatrix = CGAffineTransform.MakeScale(1f,-1f);
            //			context.TextMatrix = textMatrix;
            //
            //			context.ShowTextAtPoint(rect.X, rect.Y, textg, textg.Length);
            //			var endPos = context.TextPosition;
            //
            //			var measure = new SizeF(endPos.X - startPos.X, font.nativeFont.CapHeightMetric);

            var atts = buildAttributedString(textg, font);

            // for now just a line not sure if this is going to work
            CTLine line = new CTLine(atts);
            var lineBounds = line.GetImageBounds(context);
            // Create and initialize some values from the bounds.
            float ascent;
            float descent;
            float leading;
            double lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);

            var measure = new SizeF((float)lineWidth, ascent + descent);

            return measure;
        }
		internal static CCSize MeasureString (string textg, CTFont font, CCRect rect)
		{

			var atts = buildAttributedString(textg, font);

			// for now just a line not sure if this is going to work
			CTLine line = new CTLine(atts);

			// Create and initialize some values from the bounds.
			nfloat ascent;
			nfloat descent;
			nfloat leading;
			double lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);

            var measure = new CCSize((float)(lineWidth + leading), (float)(ascent + descent));

			return measure;
		}
		// This only handles one character for right now
		internal static void GetCharABCWidthsFloat (char characters, CTFont font, out ABCFloat[] abc)
		{

			var atts = buildAttributedString(characters.ToString(), font);

			// for now just a line not sure if this is going to work
			CTLine line = new CTLine(atts);

			nfloat ascent;
			nfloat descent;
			nfloat leading;
			abc = new ABCFloat[1];
			abc[0].abcfB = (float)line.GetTypographicBounds(out ascent, out descent, out leading);
            abc [0].abcfB += (float)leading;
		}
Esempio n. 6
0
		public override double GetBaseline (object backend)
		{
			LayoutInfo li = (LayoutInfo)backend;
			using (var line = new CTLine (CreateAttributedString (li))) {
				nfloat ascent, descent, leading;
				line.GetTypographicBounds (out ascent, out descent, out leading);
				return (double)ascent;
			}
		}