DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:fontfamily

This is an old revision of the document!


fontfamily plugin

Compatible with DokuWiki

2005-07-01 - 2009-12-25

plugin With fontfamily you can control the typeface of your text

Last updated on
2009-02-04
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to typography, wrap

Tagged with typography

Der Toolbar Button funktioniert nur bis zur DokuWiki Version 2009-12-25 !
Diese Plugin wird nicht weiterentwickelt !

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

Description

Change the fontfamily by clicking a button in the edit toolbar.

To change the fontfamily , mark the text that you would like to change. Then click on the button fontfamily and choose one of the predefined styles. The result is: <ff fontfamily> Your own text</ff>

Code

code based on the plugin highlight http://www.dokuwiki.org/plugin:highlight

syntax.php

Put this code into lib/plugins/fontfamily/syntax.php:

<?php
<?php
/**
 * fontfamily Plugin: control the font-family of your text
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author      Thorsten Stratmann <thorsten.stratmann@web.de>
 * @link          http://wiki.splitbrain.org/plugin:fontfamily
 * @version    0.1
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_fontfamily extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){  // return some info
        return array(
            'author' => 'Thorsten Stratmann',
            'email'  => 'thorsten.stratmann@web.de',
            'date'   => '2009-02-04',
            'name'   => 'fontfamily Plugin',
            'desc'   => 'With fontfamily you can control the typeface of your text
                         Syntax: <ff Value>Your Text</ff>',
            'url'    => 'http://wiki.splitbrain.org/plugin:fontfamily',
        );
    }
 
     // What kind of syntax are we?
    function getType(){ return 'formatting'; }
 
    // What kind of syntax do we allow (optional)
    function getAllowedTypes() {
        return array('formatting', 'substition', 'disabled');
    }
 
   // What about paragraphs? (optional)
   function getPType(){ return 'normal'; }
 
    // Where to sort in?
    function getSort(){ return 92; }
 
 
    // Connect pattern to lexer
    function connectTo($mode) {
      $this->Lexer->addEntryPattern('(?i)<ff(?: .+?)?>(?=.+</ff>)',$mode,'plugin_fontfamily');
    }
    function postConnect() {
      $this->Lexer->addExitPattern('(?i)</ff>','plugin_fontfamily');
    }
 
 
    // Handle the match
    function handle($match, $state, $pos, &$handler)
    {
        switch ($state) 
        {
          case DOKU_LEXER_ENTER : 
            preg_match("/(?i)<ff (.+?)>/", $match, $ff);   // get the fontfamily
           if ( $this->_isValid($ff[1]) ) return array($state, $ff[1]);
			break;
			case DOKU_LEXER_MATCHED :
			break;
			case DOKU_LEXER_UNMATCHED :
			return array($state, $match);
			break;
			case DOKU_LEXER_EXIT :
			break;
			case DOKU_LEXER_SPECIAL :
			break;
		}
		return array($state, "");
	}
 
    // Create output
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
          list($state, $ff) = $data;
          switch ($state) {
            case DOKU_LEXER_ENTER : 
              $renderer->doc .= "<span style=\"font-family: $ff\">";
              break;
            case DOKU_LEXER_MATCHED :
              break;
            case DOKU_LEXER_UNMATCHED :
              $renderer->doc .= $renderer->_xmlEntities($ff);
              break;
            case DOKU_LEXER_EXIT :
              $renderer->doc .= "</span>";
              break;
            case DOKU_LEXER_SPECIAL :
              break;
          }
          return true;
        }
        return false;
    }
    function _isValid($c) {
 
        $c = trim($c);
 
        $pattern = "/^(Times New Roman|Arial|Brush Script MT|Comic Sans MS|Georgia|Impact|Trebuchet|Verdana|Webdings])/x";
 
  //      if (preg_match($pattern, $c)) return true;
    return true;
    }
}

script.js

Put this code into lib/plugins/fontsize2/script.js:

/* JavaScript function to create fontfamily toolbar in DokuWiki */
/* see http://wiki.splitbrain.org/plugin:fontfamily for more info */
 
var plugin_fontfamily = {
  "TimesNewRoman":        "Times New Roman",
  "Arial":        					"Arial",
  "BrushScriptMT":        "Brush Script MT",
  "ComicSansMS":        "Comic Sans MS",
  "Georgia":        "Georgia",
  "Impact":        "Impact",
  "Trebuchet ":        "Trebuchet " ,
  "Verdana":        "Verdana",
  "Webdings":        "Webdings"
};
 
if (isUndefined(user_fontfamily)) {
  var user_fontfamily = { };
}
 
function plugin_fontfamily_make_fontfamily_button(name, value) {
 
  var b_id = name;	// picker id that we're creating
  var b_ico = document.createElement('img');
  b_ico.src = DOKU_BASE + 'lib/plugins/fontfamily/images/'+name+'.png';
  var btn = document.createElement('button');
 
  btn.className = 'pickerbutton';
  btn.value = value;
  btn.title = name;
  btn.style.height = '2em';
  btn.style.padding = '0em';
  btn.name = value;
  btn.appendChild(b_ico);
 
  var open = "<ff " + value + ">";
  var close ="<\/ff>";
  var sample = name + " Fontfamily";
 
  btn.onclick = function(){
    insertTags('wiki__text',open,close,sample);
    return false; };
 
  return(btn);
 
}
 
function plugin_fontfamily_toolbar_picker() {
 
                  // Check that we are editing the page - is there a better way to do this?
                  var edbtn = document.getElementById('edbtn__save');
                  if (!edbtn) return;
 
                  var toolbar = document.getElementById('tool__bar');
                  if (!toolbar) return;
 
  // Create the picker button
  var p_id = 'picker_plugin_fontfamily';	// picker id that we're creating
  var p_ico = document.createElement('img');
  p_ico.src = DOKU_BASE + 'lib/plugins/fontfamily/images/toolbar_icon.png';
  var p_btn = document.createElement('button');
  p_btn.className = 'toolbutton';
  p_btn.title = 'Fontfamily';
  p_btn.appendChild(p_ico);
  p_btn.onclick = function() {
    showPicker(p_id,this); return false; };
 
  // Create the picker <div>
  var picker = document.createElement('div');
  picker.className = 'picker';
  picker.id = p_id;
  picker.style.position = 'absolute';
  picker.style.display = 'none';
 
  /// Add a button to the picker <div> for each of the colors
  for( var ff in plugin_fontfamily ) {
    if (!isFunction(plugin_fontfamily[ff])) {
      var btn = plugin_fontfamily_make_fontfamily_button(ff,
          plugin_fontfamily[ff]);
      picker.appendChild(btn);
    }
  }
 
 
 
  var body = document.getElementsByTagName('body')[0];
  body.appendChild(picker);	// attach the picker <div> to the page body
  toolbar.appendChild(p_btn);	// attach the picker button to the toolbar
}
 
addInitEvent(plugin_fontfamily_toolbar_picker);
 
//Setup VIM: ex: et ts=2 sw=2 enc=utf-8 :

Images

Additionally you need the images, displayed by clicking the fontfamily button. Please obtain this images from the installation packet.

Changelog

  • Version 0.1: Created

Question

Though the plugin works fine within the text, it does not show in the toolbar any more.

This happens in Release 2009-12-25c “Lemming” of DokuWiki.

Any ideas?(11/05/2010)

plugin/fontfamily.1286714963.txt.gz · Last modified: 2010-10-10 14:49 by lupo49

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki