The Wayback Machine - https://web.archive.org/web/20240708044809/https://www.geeksforgeeks.org/creating-wysiwyg-document-editor/
Open In App

Creating WYSIWYG Document Editor | Natural Language Programming

Last Updated : 19 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

When my elder son and I finished writing our Plain English compiler, we decided to test its usefulness by adding a what-you-see-is-what-you-get document editor that we could then use to document our system. Two birds with one stone!

Document View

We call this facility the Writer. This is what our instruction manual looks like when you open it in the Writer:

We call this Document View: one line per page. Whole pages (and groups of pages, contiguous or not) can be selected, copied, cut, pasted, duplicated and printed in this view. They can also be saved in Adobe PDF format so folks without the Writer can read them.

Page View

When you open a page, you see that page exactly as it will appear when it is printed (or saved as a PDF page), albeit with sky-blue grid lines to aid in tasteful layout. This is how page 8 of our instruction manual appears on the screen:

In this view, whole pages can be enlarged, reduced, rotated, and spell-checked. And various text and graphic “shapes” can be added, deleted, moved, sized, colored, flipped, mirrored, rotated, copied, cut, pasted, duplicated, grouped, etc. The Home, End, Page Up, and Page Down keys can be used to conveniently flip through the pages, without returning to Document View.

Externalized Pages

Documents (and parts of documents) can be saved, as mentioned above, as PDFs. But the native format for permanent storage is much simpler, and is text only. Consider, for example, the document below, which has just one page with four shapes on it: a pink ellipse, a green triangle, a blue square, and a text box with “ABC” in it:

If you use our “Open as Text” command (or any other text editor) to open this document, this is what you’ll see:

ream cal-3024
  page 15840 12240 1 1440
    ellipse 0 0 0 0 1000 875 1440 1440 2880 2880
    polygon 0 0 0 1500 1000 875 4 4320 1440 5760 2880 4320 2880 4320 1440
    rectangle 0 0 0 2100 1000 875 7200 1440 8640 2880 0
    text 0 0 0 -1 0 0 10080 1440 14400 2880 0 "title" "osmosian" 1440 "center" 0 0 0 yes
       "ABC"
    end
  end
end

One entry for the whole document, one for each page, and one for each shape on the page. And not a single “<" in sight!

It would be too much to paste the 4,000 Plain English sentences that define the whole Writer here. They are included in the source code that comes with our system . For now, let’s settle for a sample routine:

To group any selected shapes on a page:
If the page is nil, exit.
Create a group shape.
Put "group" into the group shape's kind.
Put the page's scale into the group shape's scale.
Move the page's shapes to some original shapes.
Loop.
Put the original shapes' first into a shape.
If the shape is nil, break.
Remove the shape from the original shapes.
If the shape is not selected, append the shape to the page's shapes; repeat.
Deselect the shape.
Append the shape to the group shape's shapes.
Repeat.  
Append the group shape to the page's shapes.
Select the group shape.
Adjust the group shape.

Shapes on pages are drawn back-to-front, so the newly grouped shapes will appear on top of the other shapes on the page.

Not a Toy

Please keep in mind that this is facility is not a “toy.” We used it, as I mentioned above, to write the documentation for our system. And since then it’s been used to produce an 800-page illustrated “teach your kid to read” course . Not to mention several other books for children, numerous training manuals, and presentation materials of all kinds, large and small. This is one of my all-time favorite pages, developed by a grade school teacher in an attempt to settle an age-old question:

QED.



Similar Reads

Creating a Simple Image Editor using JavaScript
In this article, we will be creating a Simple Image Editor that can be used to adjust the image values like brightness, contrast, hue, saturation, grayscale, and sepia. Image editors allow one to quickly edit pictures after they have been captured for enhancing them or completely changing their look. Using a combination of various values, one can g
10 min read
Natural Language Programming — Teaching Kids
We take a different approach to teaching kids how to program here at the Osmosian Order of Plain English Programmers. The Interface The first thing we do is remove all unnecessary and distracting clutter. This, for example, is what our full-screen Integrated Development Environment (IDE) looks like: Alphabetical menus and a status message field at
8 min read
Natural Language Programming
Having programmed for many years in many languages, I often find myself thinking in English pseudo-code, then I translate my thoughts into whatever artificial syntax I'm working with at the time. So one day I thought, "Why not simply code at a natural language level and skip the translation step?" My elder son (also a programmer) and I talked it ov
10 min read
Introduction of HIP parallel programming language
One must have header terms parallel computing, heterogeneous computing, high performance computing (HPC). If not you can explore HPC domain it is one of the fastest growing technology. It has touched almost all industries such as Medical, Security, Entertainment, Autonomous car, Finance, Oil industry etc. and list is growing every year. Companies l
2 min read
Features of C Programming Language
C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and a clean style, these features make C language suitable for sys
3 min read
Swift Programming Language
Swift is a general-purpose, multi-paradigm, object-oriented, functional, imperative, and block-structured language. Swift is the result of the latest research on programming languages and is built using a modern approach to safety, and software design patterns by Apple Inc. for iOS applications, macOS applications, watchOS applications, tvOS applic
4 min read
Go Programming Language (Introduction)
Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports environment adopting patterns alike to dynamic langua
11 min read
Build a basic Text Editor using Tkinter in Python
Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but this is the only framework that’s built into the Python standard library. It has several strengths; it’s cross-platform, so the same code works on Windows, macOS, and Linux. It is lightweight and relatively painless to use compared to other frameworks
4 min read
How to create Text Editor using Javascript and HTML ?
Project Introduction: In this article, we will learn how to make a simple text editor JavaScript application where we can manipulate the user input in different styles, edit the input, capitalize, etc many string operations. Let's see the implementation.Approach: Create buttons to perform operations on text in div.Create textarea in div using texta
5 min read
How to Download and Install Magix Studio Video Editor In Windows ?
Magix Studio Video Editor is a paid video editing software, with a 30-day free trial. This video editor is famous for reducing steps, i.e. making tough editing jobs easy, it helps to add animated titles, in just a few mouse clicks. Irrespective of your machine, the software works in any of it, so now, you do not need to worry about your system conf
3 min read
Article Tags :
Practice Tags :