Beispiel #1
0
        public TextDrawer(float densityScale, IShowcaseAreaCalculator calculator)
        {
            mDensityScale = densityScale;
            mCalculator = calculator;

            mPaintTitle = new TextPaint();
            mPaintTitle.AntiAlias = true;

            mPaintDetail = new TextPaint();
            mPaintDetail.AntiAlias = true;
        }
Beispiel #2
0
        private void ApplyFont (TextPaint p)
        {
            var oldTypeface = p.Typeface;
            var oldStyle = oldTypeface != null ? oldTypeface.Style : TypefaceStyle.Normal;
            var fakeStyle = oldStyle & ~font.Typeface.Style;

            if ((fakeStyle & TypefaceStyle.Bold) != 0)
                p.FakeBoldText = true;

            if ((fakeStyle & TypefaceStyle.Italic) != 0)
                p.TextSkewX = -0.25f;

            p.SetTypeface (font.Typeface);
        }
		public static TextPaint GlobalGetFontPaint (Font font, TextAlignment alignment)
		{
			var paint = new TextPaint (PaintFlags.AntiAlias);
			paint.TextAlign = Paint.Align.Left;
			if (alignment == TextAlignment.Center)
				paint.TextAlign = Paint.Align.Center;
			else if (alignment == TextAlignment.Right)
				paint.TextAlign = Paint.Align.Right;

			paint.TextSize = (float)font.Size;
			var typeface = Typeface.Create (font.Family, TypefaceStyle.Normal);
			paint.SetTypeface (typeface);

			return paint;
		}
		private void drawString(Canvas gfx, TextPaint paint, float x, float y)
		{
			if (_maxWidth == int.MaxValue)
			{
				gfx.DrawText(_text, x, y, paint);
			}
			else
			{
				paint.TextAlign = alignWrap();
				StaticLayout layout = new StaticLayout (_text, paint, _maxWidth, Layout.Alignment.AlignNormal, 1f, 0f, false);
				gfx.Translate(x, y);
				layout.Draw(gfx);
				gfx.Translate(-x, -y);
			}
		}
 private void Init(Context context, IIcon icon)
 {
     _context = context;
     _icon = icon;
     _paint = new TextPaint();
     var module = Iconize.FindModuleOf(icon);
     if (module == null)
     {
         throw new Java.Lang.IllegalStateException("Unable to find the module associated " +
                 "with icon " + icon.Key + ", have you registered the module " +
                 "you are trying to use with Iconize.With(...) in your Application?");
     }
     _paint.SetTypeface(module.GetTypeface(context));
     _paint.SetStyle(Paint.Style.Fill);
     _paint.TextAlign = Paint.Align.Center;
     _paint.UnderlineText = false;
     _paint.Color = global::Android.Graphics.Color.Black;
     _paint.AntiAlias = true;
 }
 private void Init(Context context, IIcon icon)
 {
     this.context = context;
     this.icon = icon;
     paint = new TextPaint();
     IconFontDescriptorWrapper descriptor = Iconify.FindTypefaceOf(icon);
     if (descriptor == null)
     {
         throw new IllegalStateException("Unable to find the module associated " +
                 "with icon " + icon.Key + ", have you registered the module " +
                 "you are trying to use with Iconify.with(...) in your Application?");
     }
     paint.SetTypeface(descriptor.GetTypeface(context));
     paint.SetStyle(Paint.Style.Fill);
     paint.TextAlign = Paint.Align.Center;
     paint.UnderlineText = false;
     paint.Color = new Android.Graphics.Color(0, 0, 0);
     //paint.Color = Color.Black;
     paint.AntiAlias = true;
 }
 public override void UpdateMeasureState(TextPaint tp)
 {
     tp.SetTypeface(mTypeface);
     tp.Flags = tp.Flags | PaintFlags.SubpixelText;
 }
		public void resizeText(int width, int height) {
			string text = this.Text;
			// Do not resize if the view does not have dimensions or there is no text
			if (text == null || text.Length == 0 || height <= 0 || width <= 0 || mTextSize == 0) {
				return;
			}

			// Get the text view's paint object
			TextPaint textPaint = this.Paint;

			// Store the current text size
			float oldTextSize = textPaint.TextSize;
			// If there is a max text size set, use the lesser of that and the default text size
			float targetTextSize = mMaxTextSize > 0 ? Java.Lang.Math.Min(mTextSize, mMaxTextSize) : mTextSize;

			// Get the required text height
			int textHeight =  getTextHeight(text, textPaint, width, targetTextSize);

			// Until we either fit within our text view or we had reached our min text size, incrementally try smaller sizes
			while (textHeight > height && targetTextSize > mMinTextSize) {
				targetTextSize = Java.Lang.Math.Max(targetTextSize - 2, mMinTextSize);
				textHeight = getTextHeight(text, textPaint, width, targetTextSize);
			}

			// If we had reached our minimum text size and still don't fit, append an ellipsis
			if (mAddEllipsis && targetTextSize == mMinTextSize && textHeight > height) {
				// Draw using a static layout
				// modified: use a copy of TextPaint for measuring
				TextPaint paint = new TextPaint(textPaint);
				// Draw using a static layout
				StaticLayout layout = new StaticLayout(text, paint, width, Android.Text.Layout.Alignment.AlignNormal, mSpacingMult, mSpacingAdd, false);
				// Check that we have a least one line of rendered text
				if (layout.LineCount > 0) {
					// Since the line at the specific vertical position would be cut off,
					// we must trim up to the previous line
					int lastLine = layout.GetLineForVertical(height) - 1;
					// If the text would not even fit on a single line, clear it
					if (lastLine < 0) {
						this.Text = "";
					}
					// Otherwise, trim to the previous line and add an ellipsis
					else {
						int start = layout.GetLineStart(lastLine);
						int end = layout.GetLineEnd(lastLine);
						float lineWidth = layout.GetLineWidth(lastLine);
						float ellipseWidth = textPaint.MeasureText(mEllipsis);

						// Trim characters off until we have enough room to draw the ellipsis
						while (width < lineWidth + ellipseWidth) {
							lineWidth = textPaint.MeasureText(text.Substring(start, --end + 1).ToString());
						}
						this.Text = text.Substring(0, end) + mEllipsis;
					}
				}
			}

			// Some devices try to auto adjust line spacing, so force default line spacing
			// and invalidate the layout as a side effect
			this.SetTextSize(ComplexUnitType.Px, targetTextSize);
			this.SetLineSpacing(mSpacingAdd, mSpacingMult);

			// Notify the listener if registered
			if (mTextResizeListener != null) {
				mTextResizeListener.onTextResize(this, oldTextSize, targetTextSize);
			}

			// Reset force resize flag
			mNeedsResize = false;
		}
 public override void UpdateMeasureState(TextPaint paint)
 {
     ApplyCustomTypeFace(paint);
 }
 public override void UpdateDrawState(TextPaint ds) {
     apply(ds, newType);
 }
Beispiel #11
0
 public override void UpdateDrawState(TextPaint ds)
 {
     base.UpdateDrawState(ds);
     ApplyCustomFonts(ds, newType);
 }
Beispiel #12
0
        public static Bitmap DrawTextImage(Bitmap image, string text, string author)
        {
            var resultimage = image;
            
            Bitmap.Config bitmapconfig = image.GetConfig();

            System.Diagnostics.Debug.WriteLine("kích thước ảnh: " + image.Width + " " + image.Height);
            if (bitmapconfig == null)
            {
                bitmapconfig = Bitmap.Config.Argb8888;
            }

            Bitmap bg_bitmap = Bitmap.CreateBitmap(image.Width, image.Height + image.Width / 5, Bitmap.Config.Argb8888);

            image = image.Copy(bitmapconfig, true);
            var image1 = image;
            Canvas bgcanvas = new Canvas(bg_bitmap);
            Paint p = new Paint();
            p.Color = Android.Graphics.Color.White;

            TextPaint paint = new TextPaint(PaintFlags.AntiAlias);
            TextPaint paint_author = new TextPaint(PaintFlags.AntiAlias);

            Rect bounds = new Rect();
            paint.Color = Android.Graphics.Color.White;
            paint.TextSize = 150;
            paint.SetTypeface(Typeface.Create(Typeface.Default, TypefaceStyle.Bold));

            paint_author.Color = Android.Graphics.Color.Black;
            paint_author.TextSize = 120;
            
            System.Diagnostics.Debug.WriteLine("kích thước ảnh: " + image.Width + " " + image.Height);
            int textWidth = bgcanvas.Width - 200;
            int textHeight = 0;
            StaticLayout textLayout = new StaticLayout(text, paint, textWidth, Android.Text.Layout.Alignment.AlignCenter, 1, 0, false);
            textHeight = textLayout.Height;
            while (textHeight > image.Height - 200)
            {
                paint.TextSize = paint.TextSize - 1;
                textLayout = new StaticLayout(text, paint, textWidth, Android.Text.Layout.Alignment.AlignCenter, 1, 0, false);
                textHeight = textLayout.Height;
            };
            
            //StaticLayout textLayout = new StaticLayout(text, paint, textWidth, Android.Text.Layout.Alignment.AlignCenter, 1, 0, false);

            StaticLayout textLayout_author = new StaticLayout(author, paint_author, textWidth, Android.Text.Layout.Alignment.AlignCenter, 1, 0, false);

            //textHeight = textLayout.Height;

            int textHeight_author = textLayout_author.Height;

            float x = (image.Width - textWidth) / 2;
            float y = (image.Height - textHeight) / 2;

            float x_author = (image.Width - textWidth) / 2;
            float y_author = image.Height + (image.Width / 5 - textHeight_author) / 2;

            //draw background + image
            bgcanvas.DrawColor(Android.Graphics.Color.White);
            bgcanvas.DrawBitmap(bg_bitmap, 0, 0, p);
            bgcanvas.DrawBitmap(image, 0, 0, null);
            //write content
            bgcanvas.Save();
            bgcanvas.Translate(x, y);
            textLayout.Draw(bgcanvas);
            bgcanvas.Restore();
            //write author
            bgcanvas.Save();
            bgcanvas.Translate(x_author, y_author);
            textLayout_author.Draw(bgcanvas);
            bgcanvas.Restore();

            return bg_bitmap;
        }
 // Set the text size of the text paint object and use a static layout to render text off screen before measuring
 private int GetTextWidth(string source, TextPaint paint, int width, float textSize)
 {
     // Update the text paint object
     paint.TextSize = textSize;
     // Draw using a static layout
     StaticLayout layout = new StaticLayout(source, paint, width, Layout.Alignment.AlignNormal, _spacingMult, _spacingAdd, true);
     layout.Draw(TextResizeCanvas);
     return layout.Width;
 }
Beispiel #14
0
 partial void OnForegroundChangedPartial() => _paint       = null;
Beispiel #15
0
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth  = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth  = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth   = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int   maxTextWidth    = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint {
                Color = TextColor, TextSize = fontSize
            };

            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth  = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();

            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();

            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color       = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();

            background.Left   = triangleWidth;
            background.Top    = halfStrokeWidth;
            background.Right  = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return(BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap));
        }
Beispiel #16
0
 partial void OnFontSizeChangedPartial() => _paint         = null;
Beispiel #17
0
 partial void OnCharacterSpacingChangedPartial() => _paint = null;
Beispiel #18
0
 partial void OnFontFamilyChangedPartial() => _paint       = null;
Beispiel #19
0
 // Invalidate _paint
 partial void OnFontWeightChangedPartial() => _paint       = null;
Beispiel #20
0
 public AndroidBrush(TextPaint paint)
 {
     InnerBrush = paint;
 }
Beispiel #21
0
        private Stream CreateBitmap(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
        {
            Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> > sizeDictionary = new Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> >()
            {
                { LanguageIndex.English, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 23 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Japanese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.French, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 25 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Portuguese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Spanish, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.German, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Russian, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 25 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.SimplifiedChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.TraditionalChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } }
            };

            Paint paint = new Paint();

            paint.TextSize = sizeDictionary[languageIndex][paperSizeIndex];

            Typeface typeface = Typeface.Create(Typeface.Monospace, TypefaceStyle.Normal);

            paint.SetTypeface(typeface);

            paint.GetTextBounds(text, 0, text.Length, new Rect());

            TextPaint textPaint = new TextPaint(paint);

            StaticLayout staticLayout = new StaticLayout(text, textPaint, (int)paperSizeIndex, Android.Text.Layout.Alignment.AlignNormal, 1, 0, false);

            Bitmap bitmap = Bitmap.CreateBitmap(staticLayout.Width, staticLayout.Height, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(bitmap);

            canvas.DrawColor(Android.Graphics.Color.White);

            canvas.Translate(0, 0);

            staticLayout.Draw(canvas);

            MemoryStream memoryStream = new MemoryStream();

            bitmap.Compress(Bitmap.CompressFormat.Png, 100, memoryStream);

            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }
Beispiel #22
0
 public override void UpdateDrawState(TextPaint tp)
 {
     tp.Color = ForegroundColor;
 }
        private void init(Context context)
        {
            mTextPaint = new TextPaint(PaintFlags.AntiAlias) {
                        Density = Resources.DisplayMetrics.Density,
                        TextSize = mTextsize,
                        Color = Color.Black
                    };

                mLinkPaint = new TextPaint(PaintFlags.AntiAlias) {
                        Density = Resources.DisplayMetrics.Density,
                        TextSize = mTextsize,
                        Color = Color.Blue,
                        UnderlineText = true
                    };

                this.SetBackgroundColor (Color.Transparent);

                    this.SetOnTouchListener (new OnTouchListenerAnonymousInnerClassHelper (this));
                //this.OnTouchListener = new OnTouchListenerAnonymousInnerClassHelper(this);
        }
 public override void UpdateDrawState(TextPaint ds)
 {
     base.UpdateDrawState(ds);
     _updateDrawState?.Invoke(ds);
 }
Beispiel #25
0
 public override void UpdateDrawState(TextPaint drawState)
 {
     Apply(drawState);
 }
Beispiel #26
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            var info   = args.Info;
            var canvas = args.Surface.Canvas;

            canvas.Clear();

            var lineSize     = (info.Width / TotalProgress) * 0.75f;
            var lineSizeHalf = lineSize * 0.5f;

            BackgroundPaint.StrokeWidth = lineSize;
            ForegroundPaint.StrokeWidth = lineSize;
            ForegroundPaint.StrokeCap   = SKStrokeCap.Round;

            var rect = new SKRect(lineSize, 0, info.Width - lineSize, info.Height);


            var textRect = new SKRect();

            TextPaint.MeasureText("0", ref textRect);

            var verticalSpace = rect.Height * 0.1f;

            var bottom = rect.Bottom - lineSizeHalf - (textRect.Height + verticalSpace);
            var top    = rect.Top + lineSizeHalf + (textRect.Height + verticalSpace);

            var regularHeight = (bottom - top) * 0.65f;

            var xPosInterval = rect.Width / (TotalProgress - 1);

            for (var i = 0; i < TotalProgress; i++)
            {
                var xPos = rect.Left + xPosInterval * i;

                // Draw Labels
                if (i == 0)
                {
                    // Start Label
                    const string progressText = "0";
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Bottom - 2,
                                    TextPaint);
                }
                else if (i == TotalProgress - 1)
                {
                    // End Label
                    var progressText = TotalProgress.ToString();
                    TextPaint.MeasureText(progressText, ref textRect);
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Bottom - 2,
                                    TextPaint);
                }

                if (i + 1 < Progress)
                {
                    // Draw Foreground
                    canvas.DrawLine(xPos, bottom - regularHeight, xPos, bottom, ForegroundPaint);
                }
                else if (i + 1 == Progress)
                {
                    // Draw Current Progress
                    canvas.DrawLine(xPos, top, xPos, bottom, ForegroundPaint);

                    TextPaint.Color = TextPaint.Color.WithAlpha(255);
                    var progressText = Progress.ToString();
                    TextPaint.MeasureText(progressText, ref textRect);
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Top + textRect.Height,
                                    ActiveTextPaint);
                }
                else
                {
                    // Draw Background
                    canvas.DrawLine(xPos, bottom - regularHeight, xPos, bottom, BackgroundPaint);
                }
            }
        }
		public override void UpdateMeasureState(TextPaint p)
		{
			p.SetTypeface(typeFace);
			p.Flags = p.Flags | PaintFlags.SubpixelText;
		}
        public override void UpdateMeasureState(TextPaint paint)
        {

            ApplyCustomTypeFace(paint, newType, fontColor);
        }
        internal CCTexture2D CreateTextSprite(string text, CCFontDefinition textDefinition)
        {
            if (string.IsNullOrEmpty(text))
                return new CCTexture2D();

            int imageWidth;
            int imageHeight;
            var textDef = textDefinition;
            var contentScaleFactorWidth = CCLabel.DefaultTexelToContentSizeRatios.Width;
            var contentScaleFactorHeight = CCLabel.DefaultTexelToContentSizeRatios.Height;

            textDef.FontSize *= contentScaleFactorWidth;
            textDef.Dimensions.Width *= contentScaleFactorWidth;
            textDef.Dimensions.Height *= contentScaleFactorHeight;

            bool hasPremultipliedAlpha;

            var display = Game.Activity.WindowManager.DefaultDisplay;
            var metrics = new DisplayMetrics();
            display.GetMetrics(metrics);

            // Do not take into account ScaleDensity for now.
//            var fontScaleFactor = metrics.ScaledDensity;
//            textDef.FontSize = (int)(textDef.FontSize * fontScaleFactor);


            // out paint object to hold our drawn text
//            var paintFlags = new PaintFlags();
//            if (textDefinition.isShouldAntialias)
//                paintFlags = PaintFlags.AntiAlias | PaintFlags.SubpixelText;
            
            var textPaint = new TextPaint();
            textPaint.Color = Android.Graphics.Color.White;
            textPaint.TextAlign = Paint.Align.Left;
            textPaint.AntiAlias = textDefinition.isShouldAntialias;

            textPaint.TextSize = textDef.FontSize;

            var fontName = textDef.FontName;
            var ext = System.IO.Path.GetExtension(fontName);
            if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
            {
                
                CCContentManager.SharedContentManager.GetAssetStreamAsBytes(fontName, out fontName);

                var activity = Game.Activity;

                try
                {
                    var typeface = Typeface.CreateFromAsset(activity.Assets, fontName);
                    textPaint.SetTypeface(typeface);
                }
                catch (Exception)
                {
                    textPaint.SetTypeface(Typeface.Create(fontName, TypefaceStyle.Normal));
                }
            }
            else
            {
                textPaint.SetTypeface(Typeface.Create(fontName, TypefaceStyle.Normal));
            }

            // color
            var foregroundColor = Android.Graphics.Color.White;

            textPaint.Color = foregroundColor;

            // alignment
            var horizontalAlignment = textDef.Alignment;
            var verticleAlignement = textDef.LineAlignment;

            var textAlign = (CCTextAlignment.Right == horizontalAlignment) ? Layout.Alignment.AlignOpposite
                : (CCTextAlignment.Center == horizontalAlignment) ? Layout.Alignment.AlignCenter
                : Layout.Alignment.AlignNormal;

            // LineBreak
            // TODO: Find a way to specify the type of line breaking if possible.

            var dimensions = new CCSize(textDef.Dimensions.Width, textDef.Dimensions.Height);

            var layoutAvailable = true;
            if (dimensions.Width <= 0)
            {
                dimensions.Width = 8388608;
                layoutAvailable = false;
            }

            if (dimensions.Height <= 0)
            {
                dimensions.Height = 8388608;
                layoutAvailable = false;
            }


            // Get bounding rectangle - we need its attribute and method values
            var layout = new StaticLayout(text, textPaint, 
                (int)dimensions.Width, textAlign, 1.0f, 0.0f, false);

            var boundingRect = new Rect();
            var lineBounds = new Rect();

            // Loop through all the lines so we can find our drawing offsets
            var lineCount = layout.LineCount;

            // early out if something went wrong somewhere and nothing is to be drawn
            if (lineCount == 0)
                return new CCTexture2D();

            for (int lc = 0; lc < lineCount; lc++)
            {
                layout.GetLineBounds(lc, lineBounds);
                var max = (int)Math.Ceiling(layout.GetLineMax(lc));

                if (boundingRect.Right < max)
                    boundingRect.Right = max;

                boundingRect.Bottom = lineBounds.Bottom;
            }

            if (!layoutAvailable)
            {
                if (dimensions.Width == 8388608)
                {
                    dimensions.Width = boundingRect.Right;
                }
                if (dimensions.Height == 8388608)
                {
                    dimensions.Height = boundingRect.Bottom;
                }
            }

            imageWidth = (int)dimensions.Width;
            imageHeight = (int)dimensions.Height;

            // Recreate our layout based on calculated dimensions so that we can draw the text correctly
            // in our image when Alignment is not Left.
            if (textAlign != Layout.Alignment.AlignNormal)
            {
                layout = new StaticLayout(text, textPaint, 
                    (int)dimensions.Width, textAlign, 1.0f, 0.0f, false);
              
            }


            // Line alignment
            var yOffset = (CCVerticalTextAlignment.Bottom == verticleAlignement 
                || boundingRect.Bottom >= dimensions.Height) ? dimensions.Height - boundingRect.Bottom  // align to bottom
                : (CCVerticalTextAlignment.Top == verticleAlignement) ? 0                    // align to top
                : (imageHeight - boundingRect.Bottom) * 0.5f;                                   // align to center

            try {

                // Create our platform dependant image to be drawn to.
                using (Bitmap textureBitmap = Bitmap.CreateBitmap(imageWidth, imageHeight, Bitmap.Config.Argb8888))
                {
                    using (Canvas drawingCanvas = new Canvas(textureBitmap))
                    {
                        drawingCanvas.DrawARGB(0, 255, 255, 255);

                        // Set our vertical alignment
                        drawingCanvas.Translate(0, yOffset);

                        // Now draw the text using our layout
                        layout.Draw(drawingCanvas);

                        // Create a pixel array
                        int[] pixels = new int[imageWidth * imageHeight];

                        // Now lets get our pixels.
                        // We use CopyPixelsToBuffer so that it is in Premultiplied Alpha already.
                        // Using Bitmap.GetPixels return non Premultiplied Alpha which causes blending problems
                        Java.Nio.IntBuffer byteBuffer = Java.Nio.IntBuffer.Allocate(imageWidth * imageHeight);
                        textureBitmap.CopyPixelsToBuffer(byteBuffer);
                        if (byteBuffer.HasArray)
                        {
                            byteBuffer.Rewind();
                            byteBuffer.Get(pixels, 0, pixels.Length);
                        }

                        // Make sure we recycle - Let's keep it green
                        textureBitmap.Recycle();

                        // Here we create our Texture and then set our pixel data.
                        var texture = new CCTexture2D(imageWidth, imageHeight);
                        texture.XNATexture.SetData<int>(pixels);

                        return texture;
                    }
                }   
            }
            catch (Exception exc)
            {
                CCLog.Log ("CCLabel Android: Error creating native label:{0}\n{1}", exc.Message, exc.StackTrace);
                return new CCTexture2D();
            }
        }
Beispiel #30
0
        public static StaticLayout CreateLayoutForSpannedString(SpannableString spannedString, TextPaint textPaint, int?boundedWidth, Layout.Alignment alignment)
        {
            int finalWidth = int.MaxValue;

            if (boundedWidth > 0)
            {
                finalWidth = (int)boundedWidth;
            }

            var layout = new StaticLayout(
                spannedString, // Text to layout
                textPaint,     // Text paint (font, size, etc...) to use
                finalWidth,    // The maximum width the text can be
                alignment,     // The horizontal alignment of the text
                1.0f,          // Spacing multiplier
                0.0f,          // Additional spacing
                false);        // Include padding

            return(layout);
        }
		public override void UpdateDrawState(TextPaint tp)
		{
			tp.SetTypeface(typeFace;
		}
Beispiel #32
0
 public override void UpdateMeasureState(TextPaint p)
 {
     p.SetTypeface(typeFace);
     p.Flags = p.Flags | PaintFlags.SubpixelText;
 }
		private int getTextHeight(string source, TextPaint paint, int width, float textSize) {
			// modified: make a copy of the original TextPaint object for measuring
			// (apparently the object gets modified while measuring, see also the
			// docs for TextView.getPaint() (which states to access it read-only)
			TextPaint paintCopy = new TextPaint(paint);
			// Update the text paint object
			paintCopy.TextSize = textSize;
			// Measure using a static layout
			StaticLayout layout = new StaticLayout(source, paintCopy, width, Android.Text.Layout.Alignment.AlignNormal, mSpacingMult, mSpacingAdd, true);
			return layout.Height;
		}
Beispiel #34
0
 partial void OnTextDecorationsChangedPartial() => _paint  = null;
 public override void UpdateDrawState(TextPaint ds)
 {
     ApplyCustomTypeface(ds, newType, style, size);
 }
Beispiel #36
0
 private void Init(Context context, Icon icon)
 {
     _context = context;
     _icon = icon;
     _paint = new TextPaint();
     _paint.SetTypeface(Iconify.FindTypefaceOf(icon).GetTypeface(context));
     _paint.SetStyle(Paint.Style.Fill);
     _paint.TextAlign = Paint.Align.Center;
     _paint.UnderlineText = false;
     _paint.Color = Color.Black;
     _paint.AntiAlias = true;
 }
Beispiel #37
0
 public override void UpdateDrawState(TextPaint ds)
 {
     ApplyCustomTypeFace(ds, newType);
 }
Beispiel #38
0
 public override void UpdateDrawState(TextPaint tp)
 {
     tp.SetTypeface(typeFace);
     tp.Flags = tp.Flags | PaintFlags.SubpixelText;
 }
        TextPaint GetFontPaint(Font font, TextAlignment alignment)
        {
            var paint = new TextPaint (PaintFlags.AntiAlias);
            paint.TextAlign = Paint.Align.Left;
            if (alignment == TextAlignment.Center)
                paint.TextAlign = Paint.Align.Left;
            else if (alignment == TextAlignment.Right)
                paint.TextAlign = Paint.Align.Right;

            //	paint.TextSize = (float)font.Size;
            //	var typeface = Typeface.Create (font.Family, TypefaceStyle.Normal);
            //	paint.SetTypeface (typeface);
            var typeface = Typeface.Default;
            paint.SetTypeface (typeface);
            float androidFontSize = AndroidPlatform.SizeToAndroid ((float)font.Size);
            paint.TextSize = androidFontSize;
            return paint;
        }
Beispiel #40
0
        protected override void OnDraw(Canvas canvas)
        {
            var scale = this.Context.Resources.DisplayMetrics.Density;

            var frame = GetFramingRect(canvas);

            if (frame == null)
            {
                return;
            }

            var width  = canvas.Width;
            var height = canvas.Height;

            paint.Color = resultBitmap != null ? resultColor : maskColor;
            paint.Alpha = 100;

            canvas.DrawRect(0, 0, width, frame.Top, paint);
            //canvas.DrawRect(0, frame.Top, frame.Left, frame.Bottom + 1, paint);
            //canvas.DrawRect(frame.Right + 1, frame.Top, width, frame.Bottom + 1, paint);
            canvas.DrawRect(0, frame.Bottom + 1, width, height, paint);


            var textPaint = new TextPaint();

            textPaint.Color    = Color.White;
            textPaint.TextSize = 16 * scale;

            var topTextLayout = new StaticLayout(this.TopText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);

            canvas.Save();
            Rect topBounds = new Rect();

            textPaint.GetTextBounds(this.TopText, 0, this.TopText.Length, topBounds);
            canvas.Translate(0, frame.Top / 2 - (topTextLayout.Height / 2));

            //canvas.Translate(topBounds.Left, topBounds.Bottom);
            topTextLayout.Draw(canvas);

            canvas.Restore();


            var botTextLayout = new StaticLayout(this.BottomText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);

            canvas.Save();
            Rect botBounds = new Rect();

            textPaint.GetTextBounds(this.BottomText, 0, this.BottomText.Length, botBounds);
            canvas.Translate(0, (frame.Bottom + (canvas.Height - frame.Bottom) / 2) - (botTextLayout.Height / 2));

            //canvas.Translate(topBounds.Left, topBounds.Bottom);
            botTextLayout.Draw(canvas);

            canvas.Restore();



            if (resultBitmap != null)
            {
                paint.Alpha = CURRENT_POINT_OPACITY;
                canvas.DrawBitmap(resultBitmap, null, new RectF(frame.Left, frame.Top, frame.Right, frame.Bottom), paint);
            }
            else
            {
                // Draw a two pixel solid black border inside the framing rect
                paint.Color = frameColor;
                //canvas.DrawRect(frame.Left, frame.Top, frame.Right + 1, frame.Top + 2, paint);
                //canvas.DrawRect(frame.Left, frame.Top + 2, frame.Left + 2, frame.Bottom - 1, paint);
                //canvas.DrawRect(frame.Right - 1, frame.Top, frame.Right + 1, frame.Bottom - 1, paint);
                //canvas.DrawRect(frame.Left, frame.Bottom - 1, frame.Right + 1, frame.Bottom + 1, paint);

                // Draw a red "laser scanner" line through the middle to show decoding is active
                paint.Color  = laserColor;
                paint.Alpha  = SCANNER_ALPHA[scannerAlpha];
                scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.Length;
                int middle = frame.Height() / 2 + frame.Top;
                //int middle = frame.Width() / 2 + frame.Left;

                //canvas.DrawRect(frame.Left + 2, middle - 1, frame.Right - 1, middle + 2, paint);

                canvas.DrawRect(0, middle - 1, width, middle + 2, paint);
                //canvas.DrawRect(middle - 1, frame.Top + 2, middle + 2, frame.Bottom - 1, paint); //frame.Top + 2, middle - 1, frame.Bottom - 1, middle + 2, paint);

                //var previewFrame = scanner.GetFramingRectInPreview();
                //float scaleX = frame.Width() / (float) previewFrame.Width();
                //float scaleY = frame.Height() / (float) previewFrame.Height();

                /*var currentPossible = possibleResultPoints;
                 * var currentLast = lastPossibleResultPoints;
                 *
                 * int frameLeft = frame.Left;
                 * int frameTop = frame.Top;
                 *
                 * if (currentPossible == null || currentPossible.Count <= 0)
                 * {
                 *  lastPossibleResultPoints = null;
                 * }
                 * else
                 * {
                 *  possibleResultPoints = new List<com.google.zxing.ResultPoint>(5);
                 *  lastPossibleResultPoints = currentPossible;
                 *  paint.Alpha = CURRENT_POINT_OPACITY;
                 *  paint.Color = resultPointColor;
                 *
                 *  lock (currentPossible)
                 *  {
                 *      foreach (var point in currentPossible)
                 *      {
                 *          canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                 *            frameTop + (int) (point.Y * scaleY), POINT_SIZE, paint);
                 *      }
                 *  }
                 * }
                 *
                 * if (currentLast != null)
                 * {
                 *  paint.Alpha = CURRENT_POINT_OPACITY / 2;
                 *  paint.Color = resultPointColor;
                 *
                 *  lock (currentLast)
                 *  {
                 *      float radius = POINT_SIZE / 2.0f;
                 *      foreach (var point in currentLast)
                 *      {
                 *          canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                 *            frameTop + (int) (point.Y * scaleY), radius, paint);
                 *      }
                 *  }
                 * }
                 */

                // Request another update at the animation interval, but only repaint the laser line,
                // not the entire viewfinder mask.
                PostInvalidateDelayed(ANIMATION_DELAY,
                                      frame.Left - POINT_SIZE,
                                      frame.Top - POINT_SIZE,
                                      frame.Right + POINT_SIZE,
                                      frame.Bottom + POINT_SIZE);
            }

            base.OnDraw(canvas);
        }
Beispiel #41
0
 public override void UpdateDrawState (TextPaint ds)
 {
     base.UpdateDrawState (ds);
     ds.UnderlineText = false;
     ds.SetTypeface (Android.Graphics.Typeface.DefaultBold);
 }
Beispiel #42
0
 public override void UpdateDrawState(TextPaint ds)
 {
     base.UpdateDrawState(ds);
     ds.UnderlineText = _label.UnderlineText;
 }
 public HtmlLink(FlowTextViewSharp outerInstance, string content, int start, int end, float xOffset, TextPaint paint, string url)
     : base(outerInstance, content, start, end, xOffset, paint)
 {
     this.outerInstance = outerInstance;
                 this.url = url;
 }
Beispiel #44
0
		public AndroidBrush(TextPaint paint)
		{
			InnerBrush = paint;
		}
 private void recyclePaint(TextPaint paint)
 {
     mPaintHeap.Add(paint);
 }
Beispiel #46
0
 public override void UpdateMeasureState(TextPaint paint)
 {
     base.UpdateMeasureState(paint);
     ApplyCustomFonts(paint, newType);
 }
 public HtmlObject(FlowTextViewSharp outerInstance, string content, int start, int end, float xOffset, TextPaint paint)
     : base()
 {
     this.outerInstance = outerInstance;
                 this.content = content;
                 this.start = start;
                 this.end = end;
                 this.xOffset = xOffset;
                 this.paint = paint;
 }
 public override void UpdateDrawState(TextPaint tp)
 {
     Apply(tp);
 }
			public override void UpdateDrawState(TextPaint tp)
			{
				Apply(tp);
			}
 public override void UpdateMeasureState(TextPaint p)
 {
     Apply(p);
 }
Beispiel #51
0
 public override void UpdateMeasureState(TextPaint paint)
 {
     Apply(paint);
 }
Beispiel #52
0
        /// <summary>
        /// Calculates and returns an appropriate width and height value for the contents of the control.
        /// This is called by the underlying grid layout system and should not be used in application logic.
        /// </summary>
        /// <param name="constraints">The size that the control is limited to.</param>
        /// <returns>The label size, given a width constraint and a measured height.</returns>
        public Size Measure(Size constraints)
        {
            if (string.IsNullOrEmpty(StringValue))
            {
                return(new Size());
            }

            if (_constraints == constraints)
            {
                return(new Size(MeasuredWidth, MeasuredHeight));
            }

            _constraints = constraints;
            var height        = _constraints.Height > int.MaxValue ? int.MaxValue : (int)Math.Ceiling(_constraints.Height);
            var width         = _constraints.Width > int.MaxValue ? int.MaxValue : (int)Math.Ceiling(_constraints.Width);
            var measuredWidth = 0;

            // Do not resize if the view does not have dimensions or there is no text
            if (string.IsNullOrEmpty(StringValue) || height <= 0 || width <= 0 || TextSize <= 0)
            {
                if (Text != string.Empty)
                {
                    SetText(string.Empty, BufferType.Normal);
                }
                _measuredLines = 0;
            }
            else
            {
                // modified: make a copy of the original TextPaint object for measuring
                // (apparently the object gets modified while measuring, see also the
                // docs for TextView.getPaint() (which states to access it read-only)
                var paint = new TextPaint(Paint)
                {
                    TextSize = TextSize,
                };
                // Measure using a static layout
                var layout = new StaticLayout(StringValue, paint, width, Layout.Alignment.AlignNormal, 1.0f, 0, true);

                float totalWidth = 0;

                // If we had reached our minimum text size and still don't fit, append an ellipsis
                if (layout.Height > height || _maxLineCount > 0 && layout.LineCount > _maxLineCount)
                {
                    var ellipsisWidth = Paint.MeasureText(Ellipsis);
                    var addEllipsis   = false;
                    int lastLineIndex;

                    if (height == int.MaxValue)
                    {
                        lastLineIndex = Math.Max(layout.LineCount - 1, 0);
                    }
                    else
                    {
                        lastLineIndex = Math.Max(layout.GetLineForVertical(height) - 1, 0);
                        if (lastLineIndex < layout.LineCount - 1)
                        {
                            addEllipsis = true;
                        }
                    }

                    if (_maxLineCount > 0 && lastLineIndex > _maxLineCount - 1)
                    {
                        lastLineIndex = _maxLineCount - 1;
                        addEllipsis   = true;
                    }

                    _measuredLines = lastLineIndex + 1;
                    var ellipsizeIndex     = layout.GetLineEnd(lastLineIndex);
                    var lastLineStartIndex = layout.GetLineStart(lastLineIndex);
                    ellipsizeIndex = lastLineStartIndex + (int)Math.Ceiling((ellipsizeIndex - lastLineStartIndex) * 1.4);
                    if (StringValue.Length < ellipsizeIndex)
                    {
                        ellipsizeIndex = StringValue.Length;
                        addEllipsis    = false;
                    }
                    var text = StringValue.Substring(lastLineStartIndex, ellipsizeIndex - lastLineStartIndex).TrimEnd();
                    totalWidth = Paint.MeasureText(text) + (addEllipsis ? ellipsisWidth : 0);

                    // Trim characters off until we have enough room to draw the ellipsis
                    while (width < totalWidth && text != string.Empty)
                    {
                        addEllipsis = true;
                        text        = StringValue.Substring(lastLineStartIndex, --ellipsizeIndex - lastLineStartIndex);
                        totalWidth  = Paint.MeasureText(text) + ellipsisWidth;
                    }

                    if (addEllipsis)
                    {
                        text = StringValue.Substring(0, ellipsizeIndex).TrimEnd() + Ellipsis;
                        if (text != Text)
                        {
                            SetText(text, BufferType.Normal);
                        }
                    }
                }
                else if (base.Text != StringValue)
                {
                    SetText(StringValue, BufferType.Normal);
                    _measuredLines = layout.LineCount;
                }
                else
                {
                    _measuredLines = layout.LineCount;
                }

                // Some devices try to auto adjust line spacing, so force default line spacing
                // and invalidate the layout as a side effect
                SetLineSpacing(0, 1.0f);

                for (var i = 0; i < _measuredLines; i++)
                {
                    var lineWidth = layout.GetLineWidth(i);
                    if (lineWidth > totalWidth)
                    {
                        totalWidth = lineWidth;
                    }
                }
                measuredWidth = (int)Math.Ceiling(totalWidth);
            }

            var size = this.MeasureView(constraints);

            return(new Size(measuredWidth, size.Height));
        }
		protected override void OnDraw (Canvas canvas)
		{
			
			var scale = this.Context.Resources.DisplayMetrics.Density;

			var frame = GetFramingRect();
			if (frame == null)
				return;

			var width = canvas.Width;
			var height = canvas.Height;

			paint.Color = resultBitmap != null ? resultColor : maskColor;
			paint.Alpha = 100;

			canvas.DrawRect(0, 0, width, frame.Top, paint);
			//canvas.DrawRect(0, frame.Top, frame.Left, frame.Bottom + 1, paint);
			//canvas.DrawRect(frame.Right + 1, frame.Top, width, frame.Bottom + 1, paint);
			canvas.DrawRect(0, frame.Bottom + 1, width, height, paint);

		
			var textPaint = new TextPaint();
			textPaint.Color = Color.White;
			textPaint.TextSize = 16 * scale;

			var topTextLayout = new StaticLayout(this.TopText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
			canvas.Save();
			Rect topBounds = new Rect();

			textPaint.GetTextBounds(this.TopText, 0, this.TopText.Length, topBounds);
			canvas.Translate(0, frame.Top / 2 - (topTextLayout.Height / 2));

			//canvas.Translate(topBounds.Left, topBounds.Bottom);
			topTextLayout.Draw(canvas);

			canvas.Restore();


			var botTextLayout = new StaticLayout(this.BottomText, textPaint, canvas.Width, Android.Text.Layout.Alignment.AlignCenter, 1.0f, 0.0f, false);
			canvas.Save();
			Rect botBounds = new Rect();
			
			textPaint.GetTextBounds(this.BottomText, 0, this.BottomText.Length, botBounds);
			canvas.Translate(0, (frame.Bottom + (canvas.Height - frame.Bottom) / 2) - (botTextLayout.Height / 2));
			
			//canvas.Translate(topBounds.Left, topBounds.Bottom);
			botTextLayout.Draw(canvas);
			
			canvas.Restore();





			if (resultBitmap != null)
			{
				paint.Alpha = CURRENT_POINT_OPACITY;
				canvas.DrawBitmap(resultBitmap, null, new RectF(frame.Left, frame.Top, frame.Right, frame.Bottom), paint);
			}
			else
			{
				 // Draw a two pixel solid black border inside the framing rect
				paint.Color = frameColor;
				//canvas.DrawRect(frame.Left, frame.Top, frame.Right + 1, frame.Top + 2, paint);
				//canvas.DrawRect(frame.Left, frame.Top + 2, frame.Left + 2, frame.Bottom - 1, paint);
				//canvas.DrawRect(frame.Right - 1, frame.Top, frame.Right + 1, frame.Bottom - 1, paint);
				//canvas.DrawRect(frame.Left, frame.Bottom - 1, frame.Right + 1, frame.Bottom + 1, paint);

				// Draw a red "laser scanner" line through the middle to show decoding is active
				paint.Color = laserColor;
				paint.Alpha = SCANNER_ALPHA[scannerAlpha];
				scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.Length;
				int middle = frame.Height() / 2 + frame.Top;
				//int middle = frame.Width() / 2 + frame.Left;

				//canvas.DrawRect(frame.Left + 2, middle - 1, frame.Right - 1, middle + 2, paint);

				canvas.DrawRect(0, middle - 1, width, middle + 2, paint);
				//canvas.DrawRect(middle - 1, frame.Top + 2, middle + 2, frame.Bottom - 1, paint); //frame.Top + 2, middle - 1, frame.Bottom - 1, middle + 2, paint);

				//var previewFrame = scanner.GetFramingRectInPreview();
      			//float scaleX = frame.Width() / (float) previewFrame.Width();
      			//float scaleY = frame.Height() / (float) previewFrame.Height();

				/*var currentPossible = possibleResultPoints;
				var currentLast = lastPossibleResultPoints;

				int frameLeft = frame.Left;
				int frameTop = frame.Top;

				if (currentPossible == null || currentPossible.Count <= 0) 
				{
        			lastPossibleResultPoints = null;
				} 
				else 
				{
					possibleResultPoints = new List<com.google.zxing.ResultPoint>(5);
					lastPossibleResultPoints = currentPossible;
					paint.Alpha = CURRENT_POINT_OPACITY;
					paint.Color = resultPointColor;

					lock (currentPossible) 
					{
						foreach (var point in currentPossible) 
						{
							canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                              frameTop + (int) (point.Y * scaleY), POINT_SIZE, paint);
						}
					}
				}

				if (currentLast != null) 
				{
					paint.Alpha = CURRENT_POINT_OPACITY / 2;
					paint.Color = resultPointColor;

					lock (currentLast) 
					{
						float radius = POINT_SIZE / 2.0f;
						foreach (var point in currentLast) 
						{
							canvas.DrawCircle(frameLeft + (int) (point.X * scaleX),
                              frameTop + (int) (point.Y * scaleY), radius, paint);
						}
					}
				}
				*/

				// Request another update at the animation interval, but only repaint the laser line,
				// not the entire viewfinder mask.
				PostInvalidateDelayed(ANIMATION_DELAY,
				                      frame.Left - POINT_SIZE,
				                      frame.Top - POINT_SIZE,
				                      frame.Right + POINT_SIZE,
				                      frame.Bottom + POINT_SIZE);
			}

			base.OnDraw (canvas);
		}
Beispiel #54
0
 public override void UpdateDrawState(TextPaint drawState)
 {
     base.UpdateDrawState(drawState);
     drawState.UnderlineText = false;
 }
		public override void UpdateDrawState(TextPaint tp)
		{
			tp.SetTypeface(typeFace);
			tp.Flags = tp.Flags | PaintFlags.SubpixelText;
		}
Beispiel #56
0
        public CompassView(Context context, Android.Util.IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            _paint = new Paint();
            _paint.SetStyle(Paint.Style.Fill);
            _paint.AntiAlias = true;
            _paint.TextSize = (float)DIRECTION_TEXT_HEIGHT;
            _paint.SetTypeface(Typeface.Create("sans-serif-thin", TypefaceStyle.Normal));

            _tickPaint = new Paint();
            _tickPaint.SetStyle(Paint.Style.Stroke);
            _tickPaint.StrokeWidth = (float)TICK_WIDTH;
            _tickPaint.AntiAlias = true;
            _tickPaint.Color = Color.White;

            _placePaint = new TextPaint();
            _placePaint.SetStyle(Paint.Style.Fill);
            _placePaint.AntiAlias = true;
            _placePaint.Color = Color.White;
            _placePaint.TextSize = (float)PLACE_TEXT_HEIGHT;
            _placePaint.SetTypeface(Typeface.Create("sans-serif-light", TypefaceStyle.Normal));

            _path = new Path();
            _textBounds = new Rect();
            _allBounds = new List<Rect>();

            _distanceFormat = NumberFormat.GetNumberInstance(Locale.Default);
            _distanceFormat.MinimumFractionDigits = 0;
            _distanceFormat.MaximumFractionDigits = 1;

            _placeBitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.place_mark);
            _animatedHeading = Double.NaN;

            _directions = context.Resources.GetStringArray(Resource.Array.direction_abbreviations);

            _animator = new ValueAnimator();
            setupAnimator();
        }
 public override void UpdateMeasureState(TextPaint paint) {
     apply(paint, newType);
 }
Beispiel #58
0
 public override void UpdateDrawState(TextPaint ds)
 {
     base.UpdateDrawState(ds);
     ds.UnderlineText = false;
     ds.Color         = "#32345C".ToColor();
 }
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int maxTextWidth = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint { Color = TextColor, TextSize = fontSize };
            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();
            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();
            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();
            background.Left = triangleWidth;
            background.Top = halfStrokeWidth;
            background.Right = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap);
        }
		public override void UpdateMeasureState(TextPaint p)
		{
			p.SetTypeface(typeFace);
		}