Hyphenator v0.3 (c) 2004 Valentin Schmidt contact: fluxus@freenet.de *************************************************************** DESCRIPTION *************************************************************** Hyphenator is a scripting xtra for director that provides automatic hyphenation of field and text members in director at runtime. It can be used to enhance the look of (database driven) applications which dynamically present great amounts of text. The xtra itself only returns a version of the text where all possible positions for hyphenation are marked with a delimiter char ('+' as default). The hyphenation and line breaking itself has to be done by lingo code. The xtra uses a simplified version of the 'TeX hyphenation algorithm' which many professional layout programs (like eg. QuarkXPress) use as well. It's based on language specific lists of patterns, the german pattern list is included in the xtra, pattern lists for other languages can be loaded as external files (see method description). At the moment only an english (uk) pattern file is provided, others will follow soon. They can easily be created by reformating the pattern files that come with (La)TeX. *************************************************************** METHOD OVERVIEW ([...] = optional parameters, can be omitted) *************************************************************** --------------------------------------------------------------- new(xtra "Hyphenator") --------------------------------------------------------------- Description: ============ Creates new xtra instance. Example usage: ============== hx = new(xtra "Hyphenator") --------------------------------------------------------------- hyphenate(object me, text [, delimiter, patternFile, noHyphenAtStart, noHyphenAtEnd]) --------------------------------------------------------------- Description: ============ Returns hyphenated version of text where all possible hyphenation positions are marked with a special char. If the optional paramter 'delimiter' is set, it's used as marker, if it's not set or empty (""), the default delimiter '+' is used (a good alternative is to use numtochar(173), the "official" ansi char for "soft hyphen"). The optional parameter 'patternFile' specifies the full path to a file containing a list of patterns for a certain language. If it's not set or empty (""), the default patterns for german are used. With the optional third and forth parameters the minimum length of the first and last syllable can be specified (default for both: 2). In case of an error the method returns an integer error code (see below). To bullet proof your lingo code against errors check the type (ilk) of the returned result before further use. Example usage: ============== -- returns hyphenated version of text of member "info_german" using default separator '+' -- and german hyphenation rules. hyphenatedText = hx.hyphenate(member("info_german").text) if ilk(hyphenatedText)<>#string then ... -- HANDLE ERROR -- returns hyphenated version of string 'txt' using NumToChar(173) (=­) as separator -- and english (uk) hyphenation rules. Minimum for first and last syllable = 3 chars. hyphenatedText = hx.hyphenate(txt,numtochar(173), the moviepath & "uk.pattern", 3, 3) *************************************************************** ERROR CODES *************************************************************** 1 TEXT ERROR (empty text supplied) 2 PATTERN ERROR (can't find pattern file) 10 OTHER ERROR (unknown error) *************************************************************** DEMO *************************************************************** The demo shows hyphenation of a field member (lingo code see movie script 'HYPHENATOR'). The width of the field can be adjusted by clicking and dragging close to its right border. Clicking the 'hyphenate!' button starts hyphenation and line breaking. If the 'Auto hyphenate' radio button is checked, the text is automatically rehyphenated after scaling (on mouseUp).