1<?php
2/**
3 * ODT (Open Document format) export for Typography plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Lars (LarsDW223)
7 */
8
9if (!defined('DOKU_INC')) die();
10
11class helper_plugin_typography_odt extends DokuWiki_Plugin
12{
13    protected $closing_stack = NULL; // used in odt_render()
14
15    public function render(Doku_Renderer $renderer, $data)
16    {
17        list($state, $tag_data) = $data;
18
19        if (is_null($this->closing_stack)) {
20            $this->closing_stack = new SplStack(); //require PHP 5 >= 5.3.0
21        }
22
23        switch ($state) {
24            case DOKU_LEXER_ENTER:
25                // build inline css
26                $css = array();
27                foreach ($tag_data['declarations'] as $name => $value) {
28                    $css[] = $name.':'.$value.';';
29                }
30                $style = implode(' ', $css);
31
32                if (isset($data['line-height'])) {
33                    $renderer->p_close();
34                    if (method_exists ($renderer, '_odtParagraphOpenUseCSSStyle')) {
35                        $renderer->_odtParagraphOpenUseCSSStyle($style);
36                    } else {
37                        $renderer->_odtParagraphOpenUseCSS('p', 'style="'.$style.'"');
38                    }
39                    $this->closing_stack->push('p');
40                } else {
41                    if (method_exists ($renderer, '_odtSpanOpenUseCSSStyle')) {
42                        $renderer->_odtSpanOpenUseCSSStyle($style);
43                    } else {
44                        $renderer->_odtSpanOpenUseCSS('span', 'style="'.$style.'"');
45                    }
46                    $this->closing_stack->push('span');
47                }
48                break;
49
50            case DOKU_LEXER_EXIT:
51                try {
52                    $content = $this->closing_stack->pop();
53                    if ($content == 'p') {
54                        // For closing paragraphs use the renderer's function otherwise the internal
55                        // counter in the ODT renderer is corrupted and so would be the ODT file.
56                        $renderer->p_close();
57                        $renderer->p_open();
58                    } else {
59                        // Close the span.
60                        $renderer->_odtSpanClose();
61                    }
62                } catch (Exception $e) {
63                    // May be included for debugging purposes.
64                    //$renderer->doc .= $e->getMessage();
65                }
66                break;
67        }
68        return true;
69    }
70}
71