Example #1
0
        private static void UpdateTextVObject(BaseTextVObject vObject, ICanvas canvas)
        {
            var layer = new Layer();

            layer.VObjects.Add(vObject);
            canvas.Layers.Add(layer);

            var colorManagement = vObject.GetColorManagement(true);

            if (colorManagement != null)
            {
                colorManagement.InitPreviewColorMap(vObject.GetColors());
            }

            vObject.CurrentFileId = TextRenderer.RenderToFile(vObject, canvas.ScreenXDpi * canvas.Zoom);
        }
Example #2
0
        private static Bitmap GetTextBitmap(BaseTextVObject vObject, float dpi, Point location, bool extendBitmap, out string id)
        {
            if (vObject == null)
            {
                throw new ArgumentNullException("vObject");
            }

            if (dpi <= 0)
            {
                throw new ArgumentOutOfRangeException("dpi");
            }

            var rect   = vObject.MeasureText(dpi);
            var width  = (int)System.Math.Ceiling(rect.Width + (extendBitmap ? location.X * 2 : 0));
            var height = (int)System.Math.Ceiling(rect.Height + (extendBitmap ? location.Y * 2 : 0));

            if (rect.IsEmpty)
            {
                throw new InvalidOperationException("TextRenderer cannot write a text bitmap because it is empty");
            }

            var scale           = dpi / vObject.TargetDpi ?? 1;
            var colorManagement = vObject.GetColorManagement(true);
            var textBitmap      = new Bitmap(width, height, ColorManagement.GetPixelFormat(_colorSpace), RgbColor.Transparent)
            {
                DpiX         = dpi / scale,
                DpiY         = dpi / scale,
                ColorProfile = ColorManagement.GetProfile(colorManagement, _colorSpace, true)
            };

            using (var graphics = textBitmap.GetAdvancedGraphics())
            {
                graphics.Transform.Translate(-rect.X + location.X, -rect.Y + location.Y);

                if (!Utils.EqualsOfFloatNumbers(scale, 1))
                {
                    graphics.Transform.Scale(scale, scale);
                }

                var angle   = vObject.Angle;
                var opacity = vObject.Opacity;

                var curvedText = vObject as CurvedTextVObject;
                if (curvedText != null)
                {
                    curvedText.TextPath.RotateAt(-angle, curvedText.TextPath.GetFirstPoint());
                }

                vObject.Transform.Update(null, null, null, null, 0);
                vObject.Opacity = 1;

                vObject.DrawText(graphics, textBitmap, colorManagement);

                if (curvedText != null)
                {
                    curvedText.TextPath.RotateAt(angle, curvedText.TextPath.GetFirstPoint());
                }

                vObject.Transform.Update(null, null, null, null, angle);
                vObject.Opacity = opacity;
            }

            textBitmap.DpiX = dpi;
            textBitmap.DpiY = dpi;

            id = CreateFileId(vObject.GetMD5(dpi));

            return(textBitmap);
        }