Beispiel #1
0
        public async Task TestTextLayoutCard()
        {
            var layout = new LayoutText()
            {
                Text        = ""
                , TextSize  = TextSize.Large
                , Alignment = Alignment.Center
                , AutoFit   = true
                , BgColor   = "000000"
                , FgColor   = "ffffff"
            };

            await TestLayoutCard(layout);

            //For coverage
            layout.SetDefaults();
        }
Beispiel #2
0
        private void SetLayoutText(LayoutText layoutText)
        {
            // Selects a different text sample.

            ReadingDirection readingDirection = ReadingDirection.LeftToRight;
            String           text             = "";
            String           fontName         = "";
            String           localeName       = "";

            switch (layoutText)
            {
            case LayoutText.Latin:
                fontName         = "Segoe UI";
                localeName       = "en-us";
                readingDirection = ReadingDirection.LeftToRight;
                text             =
                    "DirectWrite provides factored layers of functionality, with each layer interacting seamlessly with the next. "
                    + "The API design gives an application the freedom and flexibility to adopt individual layers depending on their needs and schedule.\n"
                    + "\n"
                    + "The text layout API provides the highest level functionality available from DirectWrite. "
                    + "It provides services for the application to measure, display, and interact with richly formatted text strings. "
                    + "This text API can be used in applications that currently use Win32 DrawText to build a modern UI with richly formatted text.\n"
                    + "\n"
                    + "* Text-intensive applications that implement their own layout engine may use the next layer down: the script processor. "
                    + "The script processor segments text into runs of similar properties and handles the mapping from Unicode codepoints "
                    + "to the appropriate glyph in the font. "
                    + "DirectWrite's own layout is built upon this same font and script processing system. "
                    + "This sample demonstrates how a custom layout can utilize the information from script itemization, bidi analysis, line breaking analysis, and shaping, "
                    + "to accomplish text measurement/fitting, line breaking, basic justification, and drawing.\n"
                    + "\n"
                    + "The glyph-rendering layer is the lowest layer and provides glyph-rendering functionality for applications "
                    + "that implement their own complete text layout engine. The glyph rendering layer is also useful for applications that implement a custom "
                    + "renderer to modify the glyph-drawing behavior through the callback function in the DirectWrite text-formatting API.\n"
                    + "\n"
                    + "The DirectWrite font system is available to all the functional layers, and enables an application to access font and glyph information. "
                    + "It is designed to handle common font technologies and data formats. The DirectWrite font model follows the common typographic practice of "
                    + "supporting any number of weights, styles, and stretches in the same font family. This model, the same model followed by WPF and CSS, "
                    + "specifies that fonts differing only in weight (bold, light, etc.), style (upright, italic, or oblique) or stretch (narrow, condensed, wide, etc.) "
                    + "are considered to be members of a single font family.\n"
                    + "\n"
                    + "Text in DirectWrite is rendered using Microsoft ClearType, which enhances the clarity and readability of text. "
                    + "ClearType takes advantage of the fact that modern LCD displays have RGB stripes for each pixel that can be controlled individually. "
                    + "DirectWrite uses the latest enhancements to ClearType, first included with Windows Vista with Windows Presentation Foundation, "
                    + "that enables it to evaluate not just the individual letters but also the spacing between letters. "
                    + "Before these ClearType enhancements, text with a “reading” size of 10 or 12 points was difficult to display: "
                    + "we could place either 1 pixel in between letters, which was often too little, or 2 pixels, which was often too much. "
                    + "Using the extra resolution in the subpixels provides us with fractional spacing, which improves the evenness and symmetry of the entire page.\n"
                    + "\n"
                    + "The subpixel ClearType positioning offers the most accurate spacing of characters on screen, "
                    + "especially at small sizes where the difference between a sub-pixel and a whole pixel represents a significant proportion of glyph width. "
                    + "It allows text to be measured in ideal resolution space and rendered at its natural position at the LCD color stripe, subpixel granularity. "
                    + "Text measured and rendered using this technology is, by definition, "
                    + "resolution-independent—meaning the exact same layout of text is achieved across the range of various display resolutions.\n"
                    + "\n"
                    + "Unlike either flavor of GDI's ClearType rendering, sub-pixel ClearType offers the most accurate width of characters. "
                    + "The Text String API adopts sub-pixel text rendering by default, which means it measures text at its ideal resolution independent "
                    + "to the current display resolution, and produces the glyph positioning result based on the truly scaled glyph advance widths and positioning offsets.";
                break;

            case LayoutText.Arabic:
                fontName         = "Arabic Typesetting";
                localeName       = "ar-eg";
                readingDirection = ReadingDirection.RightToLeft;
                text             =
                    "الديباجة\n"
                    + "لمّا كان الاعتراف بالكرامة المتأصلة في جميع أعضاء الأسرة البشرية وبحقوقهم المتساوية الثابتة هو أساس الحرية والعدل والسلام في العالم.\n"
                    + "\n"
                    + "ولما كان تناسي حقوق الإنسان وازدراؤها قد أفضيا إلى أعمال همجية آذت الضمير الإنساني. وكان غاية ما يرنو إليه عامة البشر انبثاق عالم يتمتع فيه الفرد بحرية القول والعقيدة ويتحرر من الفزع والفاقة.\n"
                    + "\n"
                    + "ولما كان من الضروري أن يتولى القانون حماية حقوق الإنسان لكيلا يضطر المرء آخر الأمر إلى التمرد على الاستبداد والظلم.\n"
                    + "\n"
                    + "ولما كانت شعوب الأمم المتحدة قد أكدت في الميثاق من جديد إيمانها بحقوق الإنسان الأساسية وبكرامة الفرد وقدره وبما للرجال والنساء من حقوق متساوية وحزمت أمرها على أن تدفع بالرقي الاجتماعي قدمًا وأن ترفع مستوى الحياة في جو من الحرية أفسح.\n"
                    + "\n"
                    + "ولما كانت الدول الأعضاء قد تعهدت بالتعاون مع الأمم المتحدة على ضمان إطراد مراعاة حقوق الإنسان والحريات الأساسية واحترامها.\n"
                    + "\n"
                    + "ولما كان للإدراك العام لهذه الحقوق والحريات الأهمية الكبرى للوفاء التام بهذا التعهد.\n"
                    + "\n"
                    + "فإن الجمعية العامة\n"
                    + "\n"
                    + "تنادي بهذا الإعلان العالمي لحقوق الإنسان\n"
                    + "\n"
                    + "على أنه المستوى المشترك الذي ينبغي أن تستهدفه كافة الشعوب والأمم حتى يسعى كل فرد وهيئة في المجتمع، واضعين على الدوام هذا الإعلان نصب أعينهم، إلى توطيد احترام هذه الحقوق والحريات عن طريق التعليم والتربية واتخاذ إجراءات مطردة، قومية وعالمية، لضمان الإعتراف بها ومراعاتها بصورة عالمية فعالة بين الدول الأعضاء ذاتها وشعوب البقاع الخاضعة لسلطانها.\n"
                    + "\n"
                    + "المادة 1\n"
                    + "\n"
                    + "يولد جميع الناس أحرارًا متساوين في الكرامة والحقوق. وقد وهبوا عقلاً وضميرًا وعليهم أن يعامل بعضهم بعضًا بروح الإخاء.\n"
                    + "\n"
                    + "المادة 2\n"
                    + "\n"
                    + "لكل إنسان حق التمتع بكافة الحقوق والحريات الواردة في هذا الإعلان، دون أي تمييز، كالتمييز بسبب العنصر أو اللون أو الجنس أو اللغة أو الدين أو الرأي السياسي أو أي رأي آخر، أو الأصل الوطني أو الإجتماعي أو الثروة أو الميلاد أو أي وضع آخر، دون أية تفرقة بين الرجال والنساء.\n"
                    + "\n"
                    + "وفضلاً عما تقدم فلن يكون هناك أي تمييز أساسه الوضع السياسي أو القانوني أو الدولي لبلد أو البقعة التي ينتمي إليها الفرد سواء كان هذا البلد أو تلك البقعة مستقلاً أو تحت الوصاية أو غير متمتع بالحكم الذاتي أو كانت سيادته خاضعة لأي قيد من القيود.\n";
                break;

            case LayoutText.Japanese:
                fontName         = "Meiryo";
                localeName       = "jp-jp";
                readingDirection = ReadingDirection.LeftToRight;
                text             =
                    "『世界人権宣言』\n"
                    + "(1948.12.10 第3回国連総会採択)〈前文〉\n"
                    + "\n"
                    + "人類社会のすべての構成員の固有の尊厳と平等で譲ることのできない権利とを承認することは、世界における自由、正義及び平和の基礎であるので、\n"
                    + "\n"
                    + "人権の無視及び軽侮が、人類の良心を踏みにじった野蛮行為をもたらし、言論及び信仰の自由が受けられ、恐怖及び欠乏のない世界の到来が、一般の人々の最高の願望として宣言されたので、\n"
                    + "\n"
                    + "人間が専制と圧迫とに対する最後の手段として反逆に訴えることがないようにするためには、法の支配によって人権を保護することが肝要であるので、\n"
                    + "\n"
                    + "諸国間の友好関係の発展を促進することが肝要であるので、\n"
                    + "\n"
                    + "国際連合の諸国民は、国連憲章において、基本的人権、人間の尊厳及び価値並びに男女の同権についての信念を再確認し、かつ、一層大きな自由のうちで社会的進歩と生活水準の向上とを促進することを決意したので、\n"
                    + "\n"
                    + "加盟国は、国際連合と協力して、人権及び基本的自由の普遍的な尊重及び遵守の促進を達成することを誓約したので、\n"
                    + "\n"
                    + "これらの権利及び自由に対する共通の理解は、この誓約を完全にするためにもっとも重要であるので、\n"
                    + "\n"
                    + "よって、ここに、国連総会は、\n"
                    + "\n"
                    + "\n"
                    + "社会の各個人及び各機関が、この世界人権宣言を常に念頭に置きながら、加盟国自身の人民の間にも、また、加盟国の管轄下にある地域の人民の間にも、これらの権利と自由との尊重を指導及び教育によって促進すること並びにそれらの普遍的措置によって確保することに努力するように、すべての人民とすべての国とが達成すべき共通の基準として、この人権宣言を公布する。\n"
                    + "\n"
                    + "第1条\n"
                    + "すべての人間は、生まれながらにして自由であり、かつ、尊厳と権利と について平等である。人間は、理性と良心とを授けられており、互いに同 胞の精神をもって行動しなければならない。\n"
                    + "\n"
                    + "第2条"
                    + "すべて人は、人種、皮膚の色、性、言語、宗教、政治上その他の意見、\n"
                    + "\n"
                    + "国民的もしくは社会的出身、財産、門地その他の地位又はこれに類するい\n"
                    + "\n"
                    + "かなる自由による差別をも受けることなく、この宣言に掲げるすべての権\n"
                    + "\n"
                    + "利と自由とを享有することができる。\n"
                    + "\n"
                    + "さらに、個人の属する国又は地域が独立国であると、信託統治地域で\n"
                    + "\n"
                    + "あると、非自治地域であると、又は他のなんらかの主権制限の下にあると\n"
                    + "\n"
                    + "を問わず、その国又は地域の政治上、管轄上又は国際上の地位に基ずくい\n"
                    + "\n"
                    + "かなる差別もしてはならない。\n"
                    + "\n"
                    + "第3条\n"
                    + "すべての人は、生命、自由及び身体の安全に対する権利を有する。\n"
                    + "\n"
                    + "第4条\n"
                    + "何人も、奴隷にされ、又は苦役に服することはない。奴隷制度及び奴隷\n"
                    + "\n"
                    + "売買は、いかなる形においても禁止する。\n"
                    + "\n"
                    + "第5条\n"
                    + "何人も、拷問又は残虐な、非人道的なもしくは屈辱的な取扱もしくは刑\n"
                    + "\n"
                    + "罰を受けることはない。\n";

                break;
            }
            textMode_ = layoutText;

            TextFormat textFormat = null;

            try
            {
                textFormat = new TextFormat(FactoryDWrite, fontName, null, FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 14, localeName);
                textFormat.ReadingDirection = readingDirection;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create text format for custom layout! CreateTextFormat()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                flowLayout.SetTextFormat(textFormat);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not set text format on custom layout! SetTextFormat()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                flowLayout.AnalyzeText(text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Text analysis failed! FlowLayout::AnalyzeText()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        private void SetLayoutText(LayoutText layoutText)
        {
            // Selects a different text sample.

            ReadingDirection readingDirection = ReadingDirection.LeftToRight;
            String text = "";
            String fontName = "";
            String localeName = "";

            switch (layoutText)
            {
                case LayoutText.Latin:
                    fontName = "Segoe UI";
                    localeName = "en-us";
                    readingDirection = ReadingDirection.LeftToRight;
                    text =
                          "DirectWrite provides factored layers of functionality, with each layer interacting seamlessly with the next. "
                        + "The API design gives an application the freedom and flexibility to adopt individual layers depending on their needs and schedule.\n"
                        + "\n"
                        + "The text layout API provides the highest level functionality available from DirectWrite. "
                        + "It provides services for the application to measure, display, and interact with richly formatted text strings. "
                        + "This text API can be used in applications that currently use Win32 DrawText to build a modern UI with richly formatted text.\n"
                        + "\n"
                        + "* Text-intensive applications that implement their own layout engine may use the next layer down: the script processor. "
                        + "The script processor segments text into runs of similar properties and handles the mapping from Unicode codepoints "
                        + "to the appropriate glyph in the font. "
                        + "DirectWrite's own layout is built upon this same font and script processing system. "
                        + "This sample demonstrates how a custom layout can utilize the information from script itemization, bidi analysis, line breaking analysis, and shaping, "
                        + "to accomplish text measurement/fitting, line breaking, basic justification, and drawing.\n"
                        + "\n"
                        + "The glyph-rendering layer is the lowest layer and provides glyph-rendering functionality for applications "
                        + "that implement their own complete text layout engine. The glyph rendering layer is also useful for applications that implement a custom "
                        + "renderer to modify the glyph-drawing behavior through the callback function in the DirectWrite text-formatting API.\n"
                        + "\n"
                        + "The DirectWrite font system is available to all the functional layers, and enables an application to access font and glyph information. "
                        + "It is designed to handle common font technologies and data formats. The DirectWrite font model follows the common typographic practice of "
                        + "supporting any number of weights, styles, and stretches in the same font family. This model, the same model followed by WPF and CSS, "
                        + "specifies that fonts differing only in weight (bold, light, etc.), style (upright, italic, or oblique) or stretch (narrow, condensed, wide, etc.) "
                        + "are considered to be members of a single font family.\n"
                        + "\n"
                        + "Text in DirectWrite is rendered using Microsoft ClearType, which enhances the clarity and readability of text. "
                        + "ClearType takes advantage of the fact that modern LCD displays have RGB stripes for each pixel that can be controlled individually. "
                        + "DirectWrite uses the latest enhancements to ClearType, first included with Windows Vista with Windows Presentation Foundation, "
                        + "that enables it to evaluate not just the individual letters but also the spacing between letters. "
                        + "Before these ClearType enhancements, text with a “reading” size of 10 or 12 points was difficult to display: "
                        + "we could place either 1 pixel in between letters, which was often too little, or 2 pixels, which was often too much. "
                        + "Using the extra resolution in the subpixels provides us with fractional spacing, which improves the evenness and symmetry of the entire page.\n"
                        + "\n"
                        + "The subpixel ClearType positioning offers the most accurate spacing of characters on screen, "
                        + "especially at small sizes where the difference between a sub-pixel and a whole pixel represents a significant proportion of glyph width. "
                        + "It allows text to be measured in ideal resolution space and rendered at its natural position at the LCD color stripe, subpixel granularity. "
                        + "Text measured and rendered using this technology is, by definition, "
                        + "resolution-independent—meaning the exact same layout of text is achieved across the range of various display resolutions.\n"
                        + "\n"
                        + "Unlike either flavor of GDI's ClearType rendering, sub-pixel ClearType offers the most accurate width of characters. "
                        + "The Text String API adopts sub-pixel text rendering by default, which means it measures text at its ideal resolution independent "
                        + "to the current display resolution, and produces the glyph positioning result based on the truly scaled glyph advance widths and positioning offsets.";
                    break;
                case LayoutText.Arabic:
                    fontName = "Arabic Typesetting";
                    localeName = "ar-eg";
                    readingDirection = ReadingDirection.RightToLeft;
                    text =
                        "الديباجة\n"
                        + "لمّا كان الاعتراف بالكرامة المتأصلة في جميع أعضاء الأسرة البشرية وبحقوقهم المتساوية الثابتة هو أساس الحرية والعدل والسلام في العالم.\n"
                        + "\n"
                        + "ولما كان تناسي حقوق الإنسان وازدراؤها قد أفضيا إلى أعمال همجية آذت الضمير الإنساني. وكان غاية ما يرنو إليه عامة البشر انبثاق عالم يتمتع فيه الفرد بحرية القول والعقيدة ويتحرر من الفزع والفاقة.\n"
                        + "\n"
                        + "ولما كان من الضروري أن يتولى القانون حماية حقوق الإنسان لكيلا يضطر المرء آخر الأمر إلى التمرد على الاستبداد والظلم.\n"
                        + "\n"
                        + "ولما كانت شعوب الأمم المتحدة قد أكدت في الميثاق من جديد إيمانها بحقوق الإنسان الأساسية وبكرامة الفرد وقدره وبما للرجال والنساء من حقوق متساوية وحزمت أمرها على أن تدفع بالرقي الاجتماعي قدمًا وأن ترفع مستوى الحياة في جو من الحرية أفسح.\n"
                        + "\n"
                        + "ولما كانت الدول الأعضاء قد تعهدت بالتعاون مع الأمم المتحدة على ضمان إطراد مراعاة حقوق الإنسان والحريات الأساسية واحترامها.\n"
                        + "\n"
                        + "ولما كان للإدراك العام لهذه الحقوق والحريات الأهمية الكبرى للوفاء التام بهذا التعهد.\n"
                        + "\n"
                        + "فإن الجمعية العامة\n"
                        + "\n"
                        + "تنادي بهذا الإعلان العالمي لحقوق الإنسان\n"
                        + "\n"
                        + "على أنه المستوى المشترك الذي ينبغي أن تستهدفه كافة الشعوب والأمم حتى يسعى كل فرد وهيئة في المجتمع، واضعين على الدوام هذا الإعلان نصب أعينهم، إلى توطيد احترام هذه الحقوق والحريات عن طريق التعليم والتربية واتخاذ إجراءات مطردة، قومية وعالمية، لضمان الإعتراف بها ومراعاتها بصورة عالمية فعالة بين الدول الأعضاء ذاتها وشعوب البقاع الخاضعة لسلطانها.\n"
                        + "\n"
                        + "المادة 1\n"
                        + "\n"
                        + "يولد جميع الناس أحرارًا متساوين في الكرامة والحقوق. وقد وهبوا عقلاً وضميرًا وعليهم أن يعامل بعضهم بعضًا بروح الإخاء.\n"
                        + "\n"
                        + "المادة 2\n"
                        + "\n"
                        + "لكل إنسان حق التمتع بكافة الحقوق والحريات الواردة في هذا الإعلان، دون أي تمييز، كالتمييز بسبب العنصر أو اللون أو الجنس أو اللغة أو الدين أو الرأي السياسي أو أي رأي آخر، أو الأصل الوطني أو الإجتماعي أو الثروة أو الميلاد أو أي وضع آخر، دون أية تفرقة بين الرجال والنساء.\n"
                        + "\n"
                        + "وفضلاً عما تقدم فلن يكون هناك أي تمييز أساسه الوضع السياسي أو القانوني أو الدولي لبلد أو البقعة التي ينتمي إليها الفرد سواء كان هذا البلد أو تلك البقعة مستقلاً أو تحت الوصاية أو غير متمتع بالحكم الذاتي أو كانت سيادته خاضعة لأي قيد من القيود.\n";
                    break;
                case LayoutText.Japanese:
                    fontName = "Meiryo";
                    localeName = "jp-jp";
                    readingDirection = ReadingDirection.LeftToRight;
                    text =
                        "『世界人権宣言』\n"
                        + "(1948.12.10 第3回国連総会採択)〈前文〉\n"
                        + "\n"
                        + "人類社会のすべての構成員の固有の尊厳と平等で譲ることのできない権利とを承認することは、世界における自由、正義及び平和の基礎であるので、\n"
                        + "\n"
                        + "人権の無視及び軽侮が、人類の良心を踏みにじった野蛮行為をもたらし、言論及び信仰の自由が受けられ、恐怖及び欠乏のない世界の到来が、一般の人々の最高の願望として宣言されたので、\n"
                        + "\n"
                        + "人間が専制と圧迫とに対する最後の手段として反逆に訴えることがないようにするためには、法の支配によって人権を保護することが肝要であるので、\n"
                        + "\n"
                        + "諸国間の友好関係の発展を促進することが肝要であるので、\n"
                        + "\n"
                        + "国際連合の諸国民は、国連憲章において、基本的人権、人間の尊厳及び価値並びに男女の同権についての信念を再確認し、かつ、一層大きな自由のうちで社会的進歩と生活水準の向上とを促進することを決意したので、\n"
                        + "\n"
                        + "加盟国は、国際連合と協力して、人権及び基本的自由の普遍的な尊重及び遵守の促進を達成することを誓約したので、\n"
                        + "\n"
                        + "これらの権利及び自由に対する共通の理解は、この誓約を完全にするためにもっとも重要であるので、\n"
                        + "\n"
                        + "よって、ここに、国連総会は、\n"
                        + "\n"
                        + "\n"
                        + "社会の各個人及び各機関が、この世界人権宣言を常に念頭に置きながら、加盟国自身の人民の間にも、また、加盟国の管轄下にある地域の人民の間にも、これらの権利と自由との尊重を指導及び教育によって促進すること並びにそれらの普遍的措置によって確保することに努力するように、すべての人民とすべての国とが達成すべき共通の基準として、この人権宣言を公布する。\n"
                        + "\n"
                        + "第1条\n"
                        + "すべての人間は、生まれながらにして自由であり、かつ、尊厳と権利と について平等である。人間は、理性と良心とを授けられており、互いに同 胞の精神をもって行動しなければならない。\n"
                        + "\n"
                        + "第2条"
                        + "すべて人は、人種、皮膚の色、性、言語、宗教、政治上その他の意見、\n"
                        + "\n"
                        + "国民的もしくは社会的出身、財産、門地その他の地位又はこれに類するい\n"
                        + "\n"
                        + "かなる自由による差別をも受けることなく、この宣言に掲げるすべての権\n"
                        + "\n"
                        + "利と自由とを享有することができる。\n"
                        + "\n"
                        + "さらに、個人の属する国又は地域が独立国であると、信託統治地域で\n"
                        + "\n"
                        + "あると、非自治地域であると、又は他のなんらかの主権制限の下にあると\n"
                        + "\n"
                        + "を問わず、その国又は地域の政治上、管轄上又は国際上の地位に基ずくい\n"
                        + "\n"
                        + "かなる差別もしてはならない。\n"
                        + "\n"
                        + "第3条\n"
                        + "すべての人は、生命、自由及び身体の安全に対する権利を有する。\n"
                        + "\n"
                        + "第4条\n"
                        + "何人も、奴隷にされ、又は苦役に服することはない。奴隷制度及び奴隷\n"
                        + "\n"
                        + "売買は、いかなる形においても禁止する。\n"
                        + "\n"
                        + "第5条\n"
                        + "何人も、拷問又は残虐な、非人道的なもしくは屈辱的な取扱もしくは刑\n"
                        + "\n"
                        + "罰を受けることはない。\n";

                    break;
            }
            textMode_ = layoutText;

            TextFormat textFormat = null;
            try
            {
                textFormat = new TextFormat(FactoryDWrite, fontName, null, FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 14, localeName);
                textFormat.ReadingDirection = readingDirection;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create text format for custom layout! CreateTextFormat()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                flowLayout.SetTextFormat(textFormat);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not set text format on custom layout! SetTextFormat()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                flowLayout.AnalyzeText(text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Text analysis failed! FlowLayout::AnalyzeText()" + Environment.NewLine + ex.Message, "CutomLayout", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void LayoutPageSize(Map pMap, LayoutControl pLayout, string pMapTitle, string pPageSizeName = "A3", double pWidth = 42, double pHeight = 29.7)
        {
            var mG = pLayout.CreateGraphics();

            // Calculate position parameters
            int pPageWidth  = Utilities.Cm(pWidth);
            int pPageHeight = Utilities.Cm(pHeight);

            //int pPageWidth = pLayout.PrinterSettings.DefaultPageSettings.PaperSize.Width;
            //int pPageHeight = pLayout.PrinterSettings.DefaultPageSettings.PaperSize.Height;

            int pOuterMargin     = Utilities.Cm(1);
            int pInternalMargin  = Utilities.Cm(0.25);
            int pTitleHeight     = Utilities.Cm(1);
            int pSubTitleHeight  = Utilities.Cm(0.5);
            int pTitleAreaHeight = pTitleHeight + pInternalMargin + pSubTitleHeight + pInternalMargin;
            int pLegendWidth     = Utilities.Cm(5);
            int pMapRectWidth    = ((pPageWidth - (2 * pOuterMargin)) - pLegendWidth) - pInternalMargin;
            int pMapRectHeight   = (pPageHeight - (2 * pOuterMargin)) - pTitleAreaHeight;
            int pMapWidth        = pMapRectWidth - (pInternalMargin * 2);
            int pMapHeight       = pMapRectHeight - (pInternalMargin * 2);
            int pScaleBarHeight  = Utilities.Cm(0.75);
            int pScaleBarWidth   = Utilities.Cm(5);
            int pNArrowWidth     = Utilities.Cm(1);
            int pNArrowHeight    = Utilities.Cm(1);

            // Set fonts
            var mFont1 = new Font("Arial", 9, FontStyle.Bold, GraphicsUnit.Millimeter);
            var mFont2 = new Font("Arial", 4, FontStyle.Italic, GraphicsUnit.Millimeter);
            var mFont3 = new Font("Arial", 3, FontStyle.Regular, GraphicsUnit.Millimeter);

            // Set page size
            var mPaperSize = new PaperSize();

            mPaperSize.PaperName = pPageSizeName;
            mPaperSize.Width     = pPageWidth;
            mPaperSize.Height    = pPageHeight;
            pLayout.PrinterSettings.DefaultPageSettings.PaperSize = mPaperSize;

            // Set printer margin to 1 cm
            pLayout.PrinterSettings.DefaultPageSettings.Margins = new Margins(pOuterMargin, pOuterMargin, pOuterMargin, pOuterMargin);

            // Add map to layout
            var mMap = new LayoutMap(pMap);

            //mMap.MapControl = pMap;
            mMap.Size     = new Size(pPageWidth, pPageHeight);
            mMap.Location = new Point(0, 0);
            pLayout.AddToLayout(mMap);

            // Add map mask

            // Add top margin
            AddRectangle(pLayout, pPageWidth, pOuterMargin + pTitleAreaHeight, 0, 0);

            // Add right margin
            AddRectangle(pLayout, pOuterMargin + pInternalMargin + pLegendWidth, pPageHeight, ((pPageWidth - pOuterMargin) - pLegendWidth) - pInternalMargin, 0);

            // Add bottom margin
            AddRectangle(pLayout, pPageWidth, pOuterMargin, 0, pPageHeight - pOuterMargin);

            // Add left margin
            AddRectangle(pLayout, pOuterMargin, pPageHeight, 0, 0);

            // Add title element to layout
            var mMapTitleElement = new LayoutText();

            mMapTitleElement.Name     = "Title";
            mMapTitleElement.Size     = new Size(pMapRectWidth, pTitleHeight);
            mMapTitleElement.Location = new Point(pOuterMargin, pOuterMargin);
            mMapTitleElement.Text     = pMapTitle;
            mMapTitleElement.Font     = mFont1;
            pLayout.AddToLayout(mMapTitleElement);

            // Add subtitle element to layout
            var mSubTitleElement = new LayoutText();

            mSubTitleElement.Name     = "Subtitle";
            mSubTitleElement.Size     = new Size(pMapRectWidth, pSubTitleHeight);
            mSubTitleElement.Location = new Point(pOuterMargin, pOuterMargin + pTitleHeight + pInternalMargin);
            mSubTitleElement.Text     = "New Addressing System for Abu Dhabi Municipality";
            mSubTitleElement.Font     = mFont2;
            pLayout.AddToLayout(mSubTitleElement);

            // Add map border rectangle to map
            var mRect = new LayoutRectangle();

            mRect.Size     = new Size(pMapRectWidth, pMapRectHeight);
            mRect.Location = new Point(pOuterMargin, pOuterMargin + pTitleAreaHeight);
            pLayout.AddToLayout(mRect);

            // Add legend element to layout
            var mLegend = new LayoutLegend();

            mLegend.Name          = "Legend";
            mLegend.LayoutControl = pLayout;
            mLegend.Map           = mMap;
            mLegend.Size          = new Size(pLegendWidth, pMapRectHeight);
            mLegend.Location      = new Point(pPageWidth - pOuterMargin - pLegendWidth, pOuterMargin + pTitleAreaHeight);
            mLegend.Font          = mFont3;
            pLayout.AddToLayout(mLegend);

            // Add scalebar element to layout
            var mScaleBar = new LayoutScaleBar();

            mScaleBar.Name            = "Scale Bar";
            mScaleBar.Map             = mMap;
            mScaleBar.Unit            = ScaleBarUnit.Meters;
            mScaleBar.UnitText        = "m";
            mScaleBar.Size            = new Size(pScaleBarWidth, pScaleBarWidth);
            mScaleBar.Location        = new Point(pOuterMargin + pInternalMargin + pInternalMargin, ((((pPageHeight - pOuterMargin) - pInternalMargin) - pInternalMargin) - pInternalMargin) - pScaleBarHeight);
            mScaleBar.Font            = mFont3;
            mScaleBar.BreakBeforeZero = false;
            mScaleBar.NumberOfBreaks  = 2;
            pLayout.AddToLayout(mScaleBar);

            // Add north arrow to layout
            var mNorthArrow = new LayoutNorthArrow();

            mNorthArrow.Name            = "North Arrow";
            mNorthArrow.NorthArrowStyle = NorthArrowStyle.ArrowN;
            mNorthArrow.Size            = new Size(Utilities.Cm(0.5), Utilities.Cm(1));
            mNorthArrow.Location        = new Point(Utilities.Cm(1.5), Utilities.Cm(3.5));
            pLayout.AddToLayout(mNorthArrow);

            mG.DrawLine(new Pen(Color.Black), new Point(0, 0), new Point(500, 500));
        }