Adding fonts to TinyMCE

Adding fonts to TinyMCE

by Abanoub Ghipriel -
Number of replies: 8

Hello Mary, I read this forum post and attempted to do the same thing however I was unsuccessful.  I also attempted to do this (http://stackoverflow.com/questions/26172413/using-braillie-font-in-tinymce-editor) and it still did not work.  I am using the Decaf theme. Any ideas? It shows the Coptic as a font in the TinyMCE editor but the Coptic Characters do not appear. I purged the cache as well.

I want to be able to write things in Coptic and have users view it in Coptic as well.  For example, title a post in Coptic and for it to appear in Coptic . Also, the option of installing the Coptic Font in the TinyMCE editor so my students can complete there assignments in Coptic. Thank you Mary.

I included some pictures for clarification. 


Click here for pics



Average of ratings: -
In reply to Abanoub Ghipriel

Re: Decaf Custom Font

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This is an old post and not relevant for Essential theme as the latest  version has a setting wherw you can up loadthe font you want to add.

In reply to Mary Evans

Re: Decaf Custom Font

by Abanoub Ghipriel -

Thanks so much for the response Mary. I may have posted this in the wrong section. I am trying to do the same thing in the Decaf theme. 

In reply to Abanoub Ghipriel

Re: Decaf Custom Font

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Ok...well fonts only work in Moodle 2.6 onwards, so if you are using 2.5 they will not work.

You said you tried to add them but they don't work?

To save time tell me what you have done so Far.Also, it may be that you need to refresh your browser wondow, as sometImes you cannot see the fonts.

So try Ctrl + F5 (Control key plus Function 5 key) may fix the problem!

Mary

In reply to Mary Evans

Re: Decaf Custom Font

by Abanoub Ghipriel -

Thank you so much for your help Mary..


Here is what I've done so far

1. I've created a fonts folder in my theme folder. I have put the font coptic.tff in there.

2. I have added the @font-face code to the following areas.. Core.css, Custom.css and fonts.css

3. I edited the /lib/editor/tinymce/lib.php code to include the following lines

         $contentcss .= ' , /theme/decaf/style/fonts.css

         $fontselectlist .= ' ; Coptic=coptic ' ;

As menionted in the stackexchange link I provided.


Yes.. I am running the latest build of 2.6


If you need any other additional information let me know.

I can PM you if you need to see certain files. The Max Size here is only 100kb which is not large enough to include anything



In reply to Mary Evans

Re: Decaf Custom Font

by Abanoub Ghipriel -

Thank you so much for your help Mary..


Here is what I've done so far

1. I've created a fonts folder in my theme folder. I have put the font coptic.ttf in there.

2. I have added the @font-face code to the following areas.. Core.css, Custom.css and fonts.css

3. I edited the /lib/editor/tinymce/lib.php code to include the following lines

         $contentcss .= ' , /theme/decaf/style/fonts.css

         $fontselectlist .= ' ; Coptic=coptic ' ;

As menionted in the stackexchange link I provided.



Example code:

@font-face {

    font-family:'coptic';

    src:url('/theme/decaf/fonts/coptic.eot') format('eot'),

        url('/theme/decaf/fonts/coptic.woff') format('woff'),

        url('/theme/decaf/fonts/coptic.ttf') format('truetype'),

        url('/theme/decaf/fonts/coptic.svg#yourfont') format('svg');

    font-weight:normal;

    font-style:normal;

Yes.. I am running the latest build of 2.6


If you need any other additional information let me know.

I can PM you if you need to see certain files. The Max Size here is only 100kb which is not large enough to include anything



In reply to Abanoub Ghipriel

Re: Decaf Custom Font

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

This part is wrong!

@font-face {
    font-family:'coptic';
    src:url('/theme/decaf/fonts/coptic.eot') format('eot'),
        url('/theme/decaf/fonts/coptic.woff') format('woff'),
        url('/theme/decaf/fonts/coptic.ttf') format('truetype'),
        url('/theme/decaf/fonts/coptic.svg#yourfont') format('svg');
    font-weight:normal;
    font-style:normal;

It should actually look like this as you are only adding one font type, which in your case is True Type Font (ttf).

@font-face {
    font-family: Coptic;
    src: url([[font:theme|coptic.ttf]]) format('truetype');
    font-weight: normal;
    font-style: normal;
}

You only need to add the above CSS one so the font.css file is fine.

To make it work in your theme you need to add CSS to tell Moodle where you need this font to show up on a page. So if this is everywhere, then add it to the body like this:

body { font-family: Coptic, Arial, sans-serif; }

and also headers...

h1, h2, h3, h4, h5, h6 { font-family: Coptic, Arial, sans-serif;}

Hope that helps?

Cheers

Mary

In reply to Abanoub Ghipriel

Re: Decaf Custom Font

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Further to my last comment, I misunderstood what you were saying but after looking at the images I am even more confused! LOL

I think I need to have my lunch and a strong cup of coffee and came back to this later.

Just so that you know I have tested the TinyMCE just adding the code to the TinyMCE lib.php which enabled the Papyrus font I have on my computer, and allowed me to add that font in ANY theme, so that bit works.

I need now to add a separate font that I do not have on my computer and test that with my theme.

Here is proof of my first test...

    protected function get_init_params($elementid, array $options=null) {
        global $CFG, $PAGE, $OUTPUT;

        //TODO: we need to implement user preferences that affect the editor setup too

        $directionality = get_string('thisdirection', 'langconfig');
        $strtime        = get_string('strftimetime');
        $strdate        = get_string('strftimedaydate');
        $lang           = current_language();
        $contentcss     = $PAGE->theme->editor_css_url()->out(false);

        $context = empty($options['context']) ? context_system::instance() : $options['context'];

        $config = get_config('editor_tinymce');
        if (!isset($config->disabledsubplugins)) {
            $config->disabledsubplugins = '';
        }

        $fontselectlist = empty($config->fontselectlist) ? '' : $config->fontselectlist;
        $contentcss .= ', /theme/clean/style/fonts.css';
        $fontselectlist .= ';Papyrus=papyrus';

And here is a screen-shot of the front page summary ...

TinyMCE font

Cheers

Mary

In reply to Abanoub Ghipriel

Re: Decaf Custom Font

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

OK...

Adding the font to the theme and adding the font name and CSS to TinyMCE lib.php will allow the font to show up in the Text Editor in Moodle IF and ONLY IF you add the css to editor.css  and make sure your theme config.php has the editor.css file listed in the stylesheets like this...

$THEME->editor_sheets = array('editor');

I have just successfully added this to Clean theme smile

Cheers

Mary