{"id":4784,"date":"2024-06-06T11:50:01","date_gmt":"2024-06-06T09:50:01","guid":{"rendered":"https:\/\/oopm.org\/?page_id=4784"},"modified":"2025-02-05T15:41:46","modified_gmt":"2025-02-05T14:41:46","slug":"10-3-1-details-of-the-simple-text-fromatter","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=4784","title":{"rendered":"10.3.1 Details of the simple text formatter"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages4784&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages4784&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">In the section we describe the details of the simple text formatter. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The overall structure of class <code>Document<\/code> is the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Document(temp: <strong>ref<\/strong> Template, lineMax: <strong>var<\/strong> integer):\n    :::\n    content: <strong>obj<\/strong> OrderedList(Paragraph)    \n    addParagraph(theContent: <strong>var<\/strong> String, theStyle: <strong>ref<\/strong> Style):\n       content.insert(Paragraph(theContent, theStyle))\n    :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>Document<\/code> has the following attributes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A data-item <code>content<\/code>, which is an <code>OrderedList<\/code> of the <code>Paragraphs<\/code> in a given <code>Document<\/code>.<\/li>\n\n\n\n<li>A method <code>addParagraph<\/code> that inserts a new <code>Paragraph<\/code> with arguments <code>theContent<\/code> and <code>theStyle<\/code> into <code>content<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Next we have added <code>format<\/code> methods to <code>Document<\/code> and <code>Paragraph<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Document(temp: <strong>ref<\/strong> Template, lineMax: <strong>var<\/strong> integer):\n    <strong>class<\/strong> Paragraph(theContent: <strong>var<\/strong> String, theStyle: <strong>ref<\/strong> Style):\n        format -&gt; formattedPar: <strong>var<\/strong> String:\n            formattedPar := theStyle.format(theContent, lineMax)\n    ...\n    format -&gt; formattedDoc: <strong>var<\/strong> String:\n       formattedDoc := \"\"\n       content.scan\n          formattedDoc := formattedDoc + current.format\n    print:\n       print(format) <\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>format<\/code> method for <code>Paragraph<\/code> returns a <code>String<\/code> in <code>formattedPar<\/code> as computed by invoking <code>theStyle.format(theContent,lineMax)<\/code>.<\/li>\n\n\n\n<li>The <code>format<\/code> method of <code>Document<\/code>  returns a <code>String<\/code> in <code>formattedDoc<\/code> by adding the formatted strings for each <code>Paragraph<\/code> in the content (<code>content<\/code>) of the <code>Document<\/code>.<\/li>\n\n\n\n<li>Finally the <code>print<\/code> method prints the <code>String<\/code> returned by invoking the <code>format<\/code> method of the <code>Document<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For class <code>Template<\/code>, we just add the data-item <code>styles<\/code> which is an <code>OrderedList<\/code> of possible styles that are defined for the <code>Template<\/code> &#8211; it is not used in the examples, and we leave it to the reader to make use of it. In addition we add an <code>inner(Template)<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Template:\n   styles:  <strong>obj<\/strong> OrderedList(Style)\n   heading: <strong>ref<\/strong> Style\n   bodyText: <strong>ref<\/strong> Style \n   inner(Template)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For class <code>Style<\/code>, we make explicit that generation of a <code>Style<\/code> object returns a reference to the newly generated object &#8211; this is not really needed since such a reference is returned by default. We also add <code>inner(Style)<\/code> and <code>inner(format)<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Style -&gt; s: <strong>ref<\/strong> Style:\n   format(content: <strong>var<\/strong> String, lineMax: <strong>var<\/strong> integer) \n                                        -&gt; formattedString: <strong>var<\/strong> String:&lt;\n      inner(format)\n   inner(Style)\n   s := this(Style)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following example describes the classes <code>DefaultHeading<\/code> and <code>DefaultBodyText<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> DefaultHeading: Style\n   secNo: <strong>var<\/strong> integer\n   format::&lt;\n      secNo := secNo + 1\n      formattedString := \"\\n\" + secNo + \". \" + content \n<strong>class<\/strong> DefaultBodyText: Style\n   format::&lt;\n      pos: <strong>var<\/strong> integer\n      pos := 3\n      formattedString := \"\\n   \" \n      for (1):to(content.length):repeat\n          pos := pos + 1\n          if (pos &gt; lineMax):then\n             formattedString := formattedString + \"\\n   \"\n             pos := 3\n          formattedString := formattedString + content.get&#91;inx]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>DefaultHeading<\/code> has a local variable <code>secNo<\/code> keeping track of the heading numbers. The <code>format<\/code> method increments <code>secNo<\/code> by one and returns a <code>String<\/code> consisting of a newline (<code>\"\\n\"<\/code>), followed by <code>secNo<\/code> followed by a dot and a blank (<code>\". \"<\/code>) and the string hold in the <code>content<\/code> parameter of <code>format<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>format<\/code> method of class <code>DefaultBodyText<\/code> appends the characters in <code>content<\/code> to <code>formattedContent<\/code>. A newline and there blanks (<code>\"\\n   \"<\/code>) are inserted so each line has a maximum of <code>lineMax<\/code> characters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We define a standard template as a subclass of <code>Template<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> StandardTemplate: Template\n   heading := DefaultHeading\n   bodyText:= DefaultBodyText\t <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>StandardTemplate<\/code> object initializes the predefined styles <code>heading<\/code> and <code>bodyText<\/code> to <code>defaultHeading<\/code> and <code>defaultBodyText<\/code> respectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally we define class <code>StandardDocument<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> StandardDocument: Document\n    addHeading(h: <strong>ref<\/strong> String):\n        addParagraph(h, theTemplate.heading)\n    addBodyText(b: <strong>ref<\/strong> String):\n       addParagraph(b, theTemplate.bodyText)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>StandardDocument<\/code> is a subclass of <code>Document<\/code>. It adds two methods <code>addHeading<\/code> and <code>addBodyText<\/code>. Each invoke <code>addParagraph<\/code> with their <code>String<\/code> parameter and the appropriate style defined within <code>theTemplate<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This completes describing the details of the simple text formatting system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=4784\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In the section we describe the details of the simple text formatter. The overall structure of class Document is the following: A Document has the following attributes: Next we have added format methods to Document and Paragraph: For class Template, we just add the data-item styles which is an OrderedList of possible styles that are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4730,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4784","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4784"}],"version-history":[{"count":26,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4784\/revisions"}],"predecessor-version":[{"id":11364,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4784\/revisions\/11364"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4730"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}