Permalink
Browse files

Adds first ideas of Version 2.0

  • Loading branch information...
1 parent f107103 commit 958dded062c9534793c313207938622384ec039f @heiglandreas committed Nov 2, 2011
View
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<docblox>
+ <files>
+ <directory>src/</directory>
+ </files>
+ <parser>
+ <target>doc/api/</target>
+ <markers>
+ <item>TODO</item>
+ <item>FIXME</item>
+ <item>@todo</item>
+ </markers>
+ <extensions>
+ <extension>php</extension>
+ </extensions>
+ <visibility></visibility>
+ </parser>
+ <transformer>
+ <target>doc/api/</target>
+ </transformer>
+ <logging>
+ <level>warn</level>
+ <paths>
+ <default>{APP_ROOT}/doc/api/docblox.{DATE}.log</default>
+ <errors>{APP_ROOT}/doc/api/docblox.{DATE}.errors.log</errors>
+ </paths>
+ </logging>
+ <transformations>
+ <template name="default" />
+ </transformations>
+ <title>Org_Heigl_Hyphenator</title>
+</docblox>
View
@@ -0,0 +1,157 @@
+<?php
+/**
+ * $Id$
+ *
+ *
+ */
+
+ini_set ( 'display_errors', true );
+ini_set ( 'include_path', ini_get ( 'include_path') . PATH_SEPARATOR . './src' );
+require_once 'Org/Heigl/Hyphenator.php';
+
+if ( ! isset ( $_REQUEST ['language'] ) ) {
+ $_REQUEST ['language'] = 'de_DE';
+}
+if ( ! isset ( $_REQUEST ['text'] ) ) {
+ $_REQUEST ['text'] = '';
+}
+if ( ! isset ( $_REQUEST ['quality'] ) ) {
+ $_REQUEST ['quality'] = '5';
+}
+if ( ! isset ( $_REQUEST ['leftMin'] ) ) {
+ $_REQUEST ['leftMin'] = '5';
+}
+if ( ! isset ( $_REQUEST ['rightMin'] ) ) {
+ $_REQUEST ['rightMin'] = '5';
+}
+if ( ! isset ( $_REQUEST ['wordMin'] ) ) {
+ $_REQUEST ['wordMin'] = '5';
+}
+if ( ! isset ( $_REQUEST ['customHyphen'] ) ) {
+ $_REQUEST ['customHyphen'] = '--';
+}
+if ( ! isset ( $_REQUEST ['noHyphenateMarker'] ) ) {
+ $_REQUEST ['noHyphenateMarker'] = 'nbr:';
+}
+if ( ! isset ( $_REQUEST ['usePdflib'] ) ) {
+ $_REQUEST ['usePdflib'] = false;
+}
+if ( ! isset ( $_REQUEST ['fontsize'] ) ) {
+ $_REQUEST ['fontsize'] = 9;
+}
+if ( ! isset ( $_REQUEST ['adjustmethod'] ) ) {
+ $_REQUEST ['adjustmethod'] = 'auto';
+}
+if ( ! isset ( $_REQUEST ['alignment'] ) ) {
+ $_REQUEST['alignment'] = 'left';
+}
+if ( ! isset ( $_REQUEST ['maxspacing'] ) ) {
+ $_REQUEST['maxspacing'] = '500';
+}
+if ( ! isset ( $_REQUEST ['minspacing'] ) ) {
+ $_REQUEST['minspacing'] = '50';
+}
+if ( ! isset ( $_REQUEST ['nofitlimit'] ) ) {
+ $_REQUEST['nofitlimit'] = '50';
+}
+if ( ! isset ( $_REQUEST ['shrinklimit'] ) ) {
+ $_REQUEST['shrinklimit'] = '85';
+}
+if ( ! isset ( $_REQUEST ['spreadlimit'] ) ) {
+ $_REQUEST['spreadlimit'] = '0';
+}
+if ( ! isset ( $_REQUEST ['charspacing'] ) ) {
+ $_REQUEST['charspacing'] = '100';
+}
+
+
+?><?xml version="1.0" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Hyphenation-Tests</title>
+ <link rel="stylesheet" href="style.css" type="text/css" />
+ <meta http-equiv="Content-type" value="text/html; charset=ISO-8895-1"/>
+ </head>
+ <body>
+ <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
+ <fieldset>
+ <legend>Text to hyphenate</legend>
+ <textarea name="text"><?php echo $_REQUEST['text']; ?></textarea>
+ </fieldset>
+ <fieldset>
+ <legend>Hyphenator-Options</legend>
+ <label for="language">Language</label>
+ <select size="1" name="language">
+ <option <?php echo ('de_DE' === $_REQUEST['language'])?'selected="selected"':'';?>value="de_DE">German</option>
+ <option <?php echo ('en_EN' === $_REQUEST['language'])?'selected="selected"':'';?>value="en_EN">English</option>
+ </select>
+ <label for="quality">Quality</label>
+ <select size="1" name="quality">
+ <option <?php echo ('1' === $_REQUEST['quality'])?'selected="selected"':'';?>value="1">Best</option>
+ <option <?php echo ('3' === $_REQUEST['quality'])?'selected="selected"':'';?>value="3">Better</option>
+ <option <?php echo ('5' === $_REQUEST['quality'])?'selected="selected"':'';?>value="5">Normal</option>
+ <option <?php echo ('7' === $_REQUEST['quality'])?'selected="selected"':'';?>value="7">Poorer</option>
+ <option <?php echo ('9' === $_REQUEST['quality'])?'selected="selected"':'';?>value="9">Poorest</option>
+ </select>
+ <label for="leftMin">Minimum Characters on the left</label>
+ <select size="1" name="leftMin">
+ <option <?php echo ('2' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="2">2</option>
+ <option <?php echo ('3' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="3">3</option>
+ <option <?php echo ('4' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="4">4</option>
+ <option <?php echo ('5' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="5">5</option>
+ <option <?php echo ('6' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="6">6</option>
+ <option <?php echo ('7' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="7">7</option>
+ <option <?php echo ('8' === $_REQUEST['leftMin'])?'selected="selected"':'';?>value="8">8</option>
+
+ </select>
+ <label for="rightMin">Minimum Characters on the right</label>
+ <select size="1" name="rightMin">
+ <option <?php echo ('2' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="2">2</option>
+ <option <?php echo ('3' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="3">3</option>
+ <option <?php echo ('4' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="4">4</option>
+ <option <?php echo ('5' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="5">5</option>
+ <option <?php echo ('6' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="6">6</option>
+ <option <?php echo ('7' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="7">7</option>
+ <option <?php echo ('8' === $_REQUEST['rightMin'])?'selected="selected"':'';?>value="8">8</option>
+
+ </select>
+ <label for="wordMin">Minimum length of a word</label>
+ <select size="1" name="wordMin">
+ <option <?php echo ('2' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="2">2</option>
+ <option <?php echo ('3' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="3">3</option>
+ <option <?php echo ('4' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="4">4</option>
+ <option <?php echo ('5' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="5">5</option>
+ <option <?php echo ('6' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="6">6</option>
+ <option <?php echo ('7' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="7">7</option>
+ <option <?php echo ('8' === $_REQUEST['wordMin'])?'selected="selected"':'';?>value="8">8</option>
+
+ </select>
+ <label for="customHyphen">Custom Hyphen-String</label>
+ <input type="text" name="customHyphen" value="<?php echo $_REQUEST['customHyphen']; ?>" />
+ <label for="noHyphenateMarker">String that markes a Word not to be hyphenated</label>
+ <input type="text" name="noHyphenateMarker" value="<?php echo $_REQUEST['noHyphenateMarker']; ?>" />
+ </fieldset>
+ <fieldset class="buttons">
+ <input type="submit" name="submit" value="Submit" />
+ <input type="reset" name="reset" value="Reset" />
+ </fieldset>
+ </form>
+ <div class="result">
+ <?php
+ $hyphenator = Org_Heigl_Hyphenator::getInstance ( $_REQUEST['language'] );
+ $hyphenator -> setHyphen ( '-' )
+ -> setLeftMin ( $_REQUEST ['leftMin'] )
+ -> setRightMin ( $_REQUEST ['rightMin'] )
+ -> setWordMin ( $_REQUEST ['wordMin'] )
+ -> setSpecialChars ( 'äöüß' )
+ -> setQuality ( $_REQUEST ['quality'] )
+ -> setNoHyphenateMarker ( $_REQUEST ['noHyphenateMarker'] )
+ -> setCustomHyphen ( $_REQUEST ['customHyphen'] );
+ $hyphenated = $hyphenator -> hyphenate ( $_REQUEST['text'] );
+ echo '<span>' . $hyphenated . '</span>';
+ ?>
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,3 @@
+<?php
+phpinfo();
+?>
@@ -0,0 +1,155 @@
+<?php
+/**
+ * Copyright (c) 2008-2011 Andreas Heigl<andreas@heigl.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @category Hyphenation
+ * @package Org_Heigl_Hyphenator
+ * @subpackage Algorithm
+ * @author Andreas Heigl <andreas@heigl.org>
+ * @copyright 2008-2011 Andreas Heigl<andreas@heigl.org>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT-License
+ * @version SVN: $Revision: 1114 $
+ * @since 05.09.2011
+ */
+
+/**
+ * Base class for the Hyphenation-Algorithms
+ *
+ * @category Hyphenation
+ * @package Org_Heigl_Hyphenator
+ * @subpackage Algorithm
+ * @author Andreas Heigl <andreas@heigl.org>
+ * @copyright 2008-2011 Andreas Heigl<andreas@heigl.org>
+ * @license http://www.opensource.org/licenses/mit-license.php MIT-License
+ * @version SVN: $Revision: 1114 $
+ * @since 05.09.2011
+ */
+abstract class Org_Heigl_Hyphenator_Algorithm_Abstract
+{
+ /**
+ * Store the Options to be used during the processing
+ *
+ * @var Org_Heigl_Hyphenation_Options $_options
+ */
+ protected $_options = null;
+
+ /**
+ * Store the Hyphenation-Table
+ *
+ * @var array $_table
+ */
+ protected $_table = null;
+
+
+ /**
+ * Provide one interface to the Public
+ *
+ * @param string $word The word to hyphenate
+ *
+ * @return array
+ */
+ public function hyphenate($word)
+ {
+ if ( '' === trim ( $word ) ) {
+ // Hyphenating an empty string does not make sense ;-)
+ return '';
+ }
+ if($this->getOptions()->getMinWordLength() >= strlen(utf8_decode($word))){
+ // Word does not meet the minimum length requirement
+ return $word;
+ }
+ if (false!==mb_strpos($word,$this->getOptions()->getHyphen())){
+ // Word seems already to be hyphenated, so simply return 'AS IS'.
+ return $word;
+ }
+ if(0===mb_strpos($word,$this->getOptions()->getNoHyphenateString())){
+ // Word starts with a no-hyphenate-string
+ return mb_substr($word,mb_strlen($this->getOptions()->getNoHyphenateString()));
+ }
+ foreach($this->getOptions()->getCustomHyphens() as $hyphen){
+ if(false!==mb_strpos($word,$hyphen)){
+ return str_replace($hyphen,$this->getOptions()->getHyphen(),$word);
+ }
+ }
+ return $this->_hyphenate($word);
+ }
+
+ /**
+ * Invoke the actual hyphenation algorithm for the given word
+ *
+ * @param string $word
+ *
+ * @return string
+ */
+ protected abstract function _hyphenate($word);
+
+
+ /**
+ * Set the Options
+ *
+ * @param Org_Heigl_Hyphenator_Options $options
+ *
+ * @return Org_Heigl_Hyphenator_Algoritm_Abstract
+ */
+ public function setOptions(Org_Heigl_Hyphenator_Options $options)
+ {
+ $this->_options = $options;
+ return $this;
+ }
+
+ /**
+ * Get the Options
+ *
+ * @return Org_Heigl_Hyphenator_Options
+ */
+ public function getOptions()
+ {
+ if(null==$this->_options){
+ $this->_options = new Org_Heigl_Hyphenator_Options();
+ }
+ return $this->_options;
+ }
+
+ /**
+ * Set the Hyphenation table
+ *
+ * @param Org_Heigl_Hyphenator_Algorithm_Textutf8_Table $table
+ *
+ * @return Org_Heigl_Hyphenator_Algoritm_Abstract
+ */
+ public function setTable(Org_Heigl_Hyphenator_Algorithm_Texutf8_Table $table)
+ {
+ $this->_table = $table;
+ return $this;
+ }
+
+ /**
+ * Get the Hyphenation table
+ *
+ * @return Org_Heigl_Hyphenator_Algorithm_Texutf8_Table
+ */
+ public function getTable()
+ {
+ return $this->_table;
+ }
+
+
+}
Oops, something went wrong.

0 comments on commit 958dded

Please sign in to comment.