프로젝트

일반

사용자정보

개정판 b3f088e9

IDb3f088e9acb7c697cd9b4e63fcb91a9695f74d1e
상위 3e2e0589
하위 f714bef8, 84e1aacc

백흠경이(가) 5년 이상 전에 추가함

revised issue #937: calculate font size to fit given text boundary

Change-Id: I71bf1ad20ec70b4d3f71a4615f97230f0be0f1b5

차이점 보기:

FinalService/KCOM_FinalService/MarkupToPDF/Controls_PDF/HoneyPDFLib_DrawSet_DrawString.cs
16 16
        {
17 17
            string ARIALUNI_TFF = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "Arial Unicode MS.TTF");
18 18

  
19
            double dFontSize = double.MaxValue;
19 20
            BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
20
            string[] tokens = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.None);
21
            string sLongestStr = tokens.OrderByDescending(s => s.Length).First();
22
            float width = bf.GetWidthPoint(sLongestStr, rect.Height);
23
            float fFontSize = rect.Height*(rect.Width/width);
24

  
25
            iTextSharp.text.Font itextFont = new iTextSharp.text.Font(bf, fFontSize);
21
            string[] tokens = text.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
22
            foreach (var token in tokens)
23
            {
24
                float width = bf.GetWidthPoint(token, rect.Height);
25
                double ratio = rect.Width / width;
26
                double size = rect.Height * ratio;
27
                dFontSize = size < dFontSize ? size : dFontSize;
28
            }
29
            ///dFontSize = dFontSize > rect.Height ? rect.Height : dFontSize;
30
            /*
31
            width = bf.GetWidthPoint(sLongestStr, (float)dFontSize);
32
            float ascent = bf.GetAscentPoint(sLongestStr, (float)dFontSize);
33
            float descent = bf.GetDescentPoint(sLongestStr, (float)dFontSize);
34
            */
35

  
36
            iTextSharp.text.Font itextFont = new iTextSharp.text.Font(bf, (float)(dFontSize));
26 37
            itextFont.SetStyle(0);
27 38
            if (fontstyle == FontStyles.Italic)
28 39
            {
......
114 125
            ct.SetText(new Phrase(new Chunk(text, itextFont)));
115 126
            ct.Alignment = Element.ALIGN_CENTER | Element.ALIGN_TOP;
116 127
            ct.SetLeading(itextFont.CalculatedSize + 1, ct.MultipliedLeading);
117

  
128
            /// expand size of rectangle to prevent text disappear
129
            calRect.Right += itextFont.CalculatedSize;
130
            string[] tokens = text.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
131
            float top = calRect.Bottom + tokens.Length * itextFont.CalculatedSize + (float)2;
132
            calRect.Top = top < calRect.Top ? calRect.Top : top;
133
            /// up to here
118 134
            ct.SetSimpleColumn(calRect);
119 135
            ct.Go();
120 136

  
......
185 201
            ct.SetText(new Phrase(new Chunk(text, itextFont)));
186 202
            ct.Alignment = Element.ALIGN_CENTER | Element.ALIGN_TOP;
187 203
            ct.SetLeading(itextFont.CalculatedSize + 1, ct.MultipliedLeading);
204
            /// expand size of rectangle to prevent text disappear
205
            calRect.Right += itextFont.CalculatedSize;
206
            string[] tokens = text.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
207
            float top = calRect.Bottom + tokens.Length * itextFont.CalculatedSize + (float)2;
208
            calRect.Top = top < calRect.Top ? calRect.Top : top;
209
            /// up to here
188 210
            ct.SetSimpleColumn(calRect);
189 211
            ct.Go();
190 212

  

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)