Graecise banner

Modify the code to make it fit your needs

When I made Graecise I initially only made for my own use. Since I'm using a German keyboard layout, some of the combinations that were originally in Graecise have been altered upon request. Some of the alterations were made in order to make users of Beta Code more comfortable.
It is, however, easy for you to alter the source yourself and make it fit your needs:


Note that all alterations you make to the code will be lost when you update Graecise! Also note that as ov version 0.7.0 there are two instances of every character - one for the routine that will be called when you run the macro without highlighting text and one for the routine that handles highlighted texts.

Remapping accents, trema, etc.

You now have the possibility to change the code. I tried to comment it so it is easy for people who want to adapt Graecise to their own needs. I realized, however, that it is not that good a documentation. So here's a bit more help.
Let's assume you want to change the grave accent from backslash (because on your keyboard layout you gotta do some finger gymnastics if you want to type one) to, say, the questionmark. This can quite easily be done. Take a look at the code:
Codesnippet from Graecise - declaring an arrayAt the beginning of the code I declared arrays for each vowel. These arrays contain all the combinations of (in this case) "a" Graecise will recognize. As you can see, the array is grouped into pairs. A routine later will check if it can find the string Graecise read from your document and replace it by the string that is just beside it.
So, to stay with our example, you want to map the grave accent to "?". You need to find all the "\" in the arrays and change them to "?". This would be quite tedious if it wasn't for "Search and Replace" which does a great deal of the work all by itself if you tell it to. For this example, changing the "\" to something else, there's not much harm that can be done since "\" only ever appears as the grave accent. But if you wanted to remap "(" or ")" to something else, be cautious to only replace "(" where it is not part of the code itself. This is always the case when it's in quotes. A bracket that is not in quotes should be left alone.
Apart from the arrays you also need to change some more lines. For every capital Vowel (and Rho) there's a line like the following:
Codesnippet: Looping to get accents in front of a capital vowel.
In every one of those lines you have to change the "\" to "?" (or whatever you chose before).
Codesnippet - Get the accents of small vowelsAnd finally there's one last bit you have to change to make it work. Fortunately there's only one instance of this piece of code for all small vowels. You're now done and the grave accent should now be on the "?" key. Don't forget saving the new code. Mind you, sometimes OpenOffice.org behaves a bit weird when altering the code and not restarting Writer afterwards and might throw an error even though there is none. To make sure it works correctly I recommend exiting Writer and starting it again.

Remapping characters

If you want to remap a letter that cannot have an accent, trema etc., say Chi from "x" to "c", this is very easy and only needs four modifications to the code: Find the lines

Case "x":
textCursor.setString("χ")
Case "X":
textCursor.setString("Χ")
and
Case "c":
textCursor.setString("ξ")
Case "C":
textCursor.setString("Ξ")

Simpy exchange the charactes in the quotes (either the Greek charakters or the Latin ones - it should work both ways).

Remapping a vowel is a bit more work. Apart from finding the lines analogue to the ones above you also need to change one more instance of case "" which you will find nearly at the end of the code.Code needing to be altered
Assuming you want to remap Omega from W,w to Q,q that would mean you have to find the lines as exchange the characters as in the example above. I recommend, however, to exchange the Latin characters in this case, otherwise you'll also have to copy and paste all the code below the "Case "W"". Aditionally you should change all instances of wComp and CapWComp, including the array itself. You don't have to do it but it is neater and might save you some trouble in the future when you have to look into the code again.

Adding new characters

Well, Graecise doesn't have it all, because I don't regularly need all the possible symbols there are. But if you want to add a character that can easily be done. Let's assume you need the Sampi (Ϡ) very often and want to map it to the paragraph sign (§), which you don't (and you don't want to use the "insert special character" option or similar possibilities to get it).
Codesnippet from Graecise - a case statementAs you can see in the code, Graecise reads - at least in the first step - single characters and runs them through a "Select Case" routine. Every time it finds a fitting "case" it will do things with the character.
Thus you need to create a switch (case statement) for the symbol you want to be replaced by Ϡ. It would look like this:

Case "§"
 textCursor.setString("Ϡ")

For combining characters it is basically the same, only more complicated. The easiest way would be to copy the code from an existing combining character. As there are capital and non capital characters you most likely would need to get four (two - but two times because we have two different routines handling "word graecising" and "selection graecising") snippets. For small letters it is quite easy, just take a look above. This is because the accents on small letters are handled differently from those on capital letters.
A snippet you could use for a capital combining letter would for example look like that:
Codesnippet from Graecise - code for a capital combining letterAs you can see, at the start there's again a case statement - it tells StarBasic what to do when the macro finds a capital A. It then distinguishes whether there's something in front of the A or not. There is a bit of superfluous code there that I keep in case I want to reintroduce automatic setting of an accent. It's the bit where the macro checks if there is a space (" ") in front of the vowel. So, if you wanted to use this as a sample for your own combining character, you'd have to change all occurences of "A" to your new combining character (for example "L", which can have "strike through" in Polish and perhaps some other stuff) - mind you, in the pic there seem to be some As that are really alphas (this is the case everywhere it says "textCursor.setString("A")"). So, while we're at it, these are exactly the places you have to insert your new letter into.
You can then see a "While loop" beginning with "Do While". This is the part of the code that get's any combining signs that are in front of your new letter. So, let's say you wanted to L and / to combine to Ł - you'd then need the "While loop" to check for the /, which it already does. But you can also add a new symbol or replace an unneeded one (for example the "?"). Let's assume you don't want to only have the Polish Ł, but also the Ļ. (which is, among others, a Latvian letter - thanks to Wikipedia for the info). Since it looks a bit like it was made that way, we assume you want to map the cedilla (small hook under the L) to the comma. Thus, you should either replace one of the symbols (like the question mark) or add "or aString = ","" to the line. Theoretically you can do that for as many combining symbols as you like.
After you've done that find the "For loop" at the end of the snippet. The macro reads what you typed before the L and saves your combination in the variable aString. aString would now, assuming you want to write Ł, "/L". The "For loop" takes this string and compares it to an array that contains your replacement table. You'll have to create it later - we'll come to that in a moment.
You can see three instances of CapAComp in the snippet - short for Capital A Composed. This is the array that contains the replacement table for A. For L, I would call it CapLComp, but technically you can call it Hermione, Peter etc. for all that StarBasic cares (well, you may not call it Do, Loop, While and other reserved words - them being reserved because they make up the programming language).
Codesnippet from Graecise - defining a new arrayNow you can go and make your array. Place it where the other arrays are already located. You can copy and paste one of the existing ones, rename it and fill it. You should now be ready to use your new letters in the correspondence with your Polish and Latvian friends.

Valid HTML 4.01 Strict Valid CSS!
© 2009 by Christian Becker | Contact me via the OpenOffice.org Extension Site | OpenOffice.org and OpenOffice.org logos are trademarks of the respective owners.