コード例 #1
0
        protected internal override Path GetDrawingPath(float dpi = 72)
        {
            var border = GetBorderWidth(dpi);

            border = Common.ConvertPointsToPixelsFloat(dpi, border);
            var rect = GetDrawingRectangle(dpi);

            rect.Width  += border;
            rect.Height += border;

            return(rect.GetPath());
        }
コード例 #2
0
        private void FitTextToPath(float dpi)
        {
            if (!FitToPath)
            {
                return;
            }

            using (var bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb, RgbColor.Transparent)
            {
                DpiX = dpi, DpiY = dpi
            })
                using (var graphics = bitmap.GetAdvancedGraphics())
                {
                    var path       = GetDrawingTextPath(dpi);
                    var pathLength = path.ToAdvancedPath().GetLength();
                    var font       = CreateFont(graphics);
                    var textLength = font.MeasureString(Text).Width;

                    var tolerance = Common.ConvertPointsToPixelsFloat(dpi, _fitToPathTolerance);

                    if (textLength - pathLength > tolerance)
                    {
                        while (textLength - pathLength > tolerance)
                        {
                            Font.Size -= FitToPathStep;

                            font       = CreateFont(graphics);
                            textLength = font.MeasureString(Text).Width;
                        }
                    }
                    else if (OriginalFontSize > 0 && OriginalFontSize > Font.Size)
                    {
                        while (pathLength - textLength > tolerance && OriginalFontSize > Font.Size)
                        {
                            Font.Size += FitToPathStep;

                            font       = CreateFont(graphics);
                            textLength = font.MeasureString(Text).Width;
                        }
                    }
                }
        }