示例#1
0
        void EnsureResources(ICanvasResourceCreatorWithDpi resourceCreator, Size targetSize)
        {
            if (resourceRealizationSize == targetSize && !needsResourceRecreation)
                return;

            float canvasWidth = (float)targetSize.Width;
            float canvasHeight = (float)targetSize.Height;
            sizeDim = Math.Min(canvasWidth, canvasHeight);

            if (!defaultFontSizeSet)
            {
                CurrentFontSize = sizeDim / 1.3f;
                CurrentFontSize = Math.Max((float)fontSizeSlider.Minimum, CurrentFontSize);
                CurrentFontSize = Math.Min((float)fontSizeSlider.Maximum, CurrentFontSize);
                fontSizeSlider.Value = CurrentFontSize;
                defaultFontSizeSet = true;
            }

            if (textLayout != null) 
                textLayout.Dispose();
            textLayout = CreateTextLayout(resourceCreator, canvasWidth, canvasHeight);

            if (!UniformStyle)
            {
                textLayout.SetFontSize(0, 1, CurrentUppercaseFontSize);
                textLayout.SetFontFamily(0, 1, uppercaseFontPicker.CurrentFontFamily);

                textLayout.SetFontSize(1, 2, CurrentLowercaseFontSize);
                textLayout.SetFontFamily(1, 2, lowercaseFontPicker.CurrentFontFamily);
            }

            needsResourceRecreation = false;
            resourceRealizationSize = targetSize;
        }
 private void ShrinkFontAndAttachCustomBrushData(
     CanvasTextLayout textLayout, 
     int textPosition, 
     int characterCount, 
     CustomBrushData.BaselineAdjustmentType baselineAdjustmentType)
 {
     textLayout.SetFontSize(textPosition, characterCount, (float)CurrentFontSize * fontSizeShrinkAmount);
     textLayout.SetCustomBrush(textPosition, characterCount, new CustomBrushData() { BaselineAdjustment = baselineAdjustmentType });
 }