コード例 #1
0
ファイル: Formatter.cs プロジェクト: fealty/Typesetting
        /// <summary>
        ///   This method determines the common baselines for the paragraph.
        /// </summary>
        private void DetermineBaselines()
        {
            float baselineOffset = 0.0f;
            float strikethroughOffset = 0.0f;
            float underlineOffset = 0.0f;
            float strikethroughThickness = 0.0f;
            float underlineThickness = 0.0f;

            foreach(FormattedRun run in _OutputSink.Runs)
            {
                DxFontMetrics dxMetrics = run.Font.ResolveFace().Metrics;

                FontMetrics metrics = new FontMetrics(
                    dxMetrics.Ascent, dxMetrics.Descent, dxMetrics.DesignUnitsPerEm);

                float blo = metrics.Measure(dxMetrics.Ascent + dxMetrics.Descent, run.PointSize);
                float sto = metrics.Measure(dxMetrics.StrikethroughPosition, run.PointSize);
                float ulo = metrics.Measure(dxMetrics.UnderlinePosition, run.PointSize);
                float stt = metrics.Measure(dxMetrics.StrikethroughThickness, run.PointSize);
                float ult = metrics.Measure(dxMetrics.UnderlineThickness, run.PointSize);

                baselineOffset = TakeAbsMax(baselineOffset, blo);
                strikethroughOffset = TakeAbsMax(strikethroughOffset, sto);
                underlineOffset = TakeAbsMax(underlineOffset, ulo);
                strikethroughThickness = TakeAbsMax(strikethroughThickness, stt);
                underlineThickness = TakeAbsMax(underlineThickness, ult);
            }

            _OutputSink.BaselineOffset = baselineOffset;
            _OutputSink.StrikethroughOffset = strikethroughOffset;
            _OutputSink.StrikethroughThickness = strikethroughThickness;
            _OutputSink.UnderlineOffset = underlineOffset;
            _OutputSink.UnderlineThickness = underlineThickness;
        }