Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting UTF-8 text files to display on all browsers

I would like my Web page

http://www.gmarks.org/math_in_e-mail.txt

on my Apache 2.2.14 server to display correctly in all browsers on all platforms (or something approaching this).  I have included the line

AddDefaultCharset utf-8

in the appropriate .htaccess file.  I find, however, that on my own machine, running Ubuntu 10.04, the page displays exactly as I would like only in the Google Chrome browser.  Problems in other browsers: in Opera the last two lines do not display, in Firefox the subscripted aleph’s are too small, in rekonq the last two lines display incorrectly with various Fraktur characters repeated and others not displayed, in Midori the Opera and Firefox problems both occur, in Arora the Firefox and rekonq problems both occur, in Epiphany the Opera problem occurs.

Is there something else I could put in my .htaccess file, or some other configuration I might set up, to get that Web page to display correctly everywhere?  I suppose I must rely on the font set each user has installed on his or her computer (obviously it defeats the purpose of the Web page to use something like GIF images).  I find the differences among the browsers strange: does each browser include its own set of fonts in some configuration file, or do they access some directory containing fonts for the entire computer?  (And is the answer to the last question OS-dependent?)

Further questions: would I do better to change the line in my .htaccess file to

AddCharset UTF-8 .txt

and is there a way I can make the .txt file display by default with an increased font size?

like image 474
Greg Marks Avatar asked Oct 07 '22 06:10

Greg Marks


1 Answers

A browser will not know the text is UTF-8 encoded unless the text starts with a UTF-8 BOM (assuming the browser even looks for that) or the HTTP Content-Type header specifies UTF-8 as the Charset, ie: Content-Type: text/plain; charset=utf-8. If AddCharset tells Apache to generate that attribute for .txt files, then great.

There is no way to specify a font for a .txt file by itself. You have to use HTML for that. To specify a font for a .txt file, you would have to write a server-side script that outputs an HTML wrapper around the .txt file content and then sets the HTTP Content-Type header to specify text/html instead of text/plain as the data type.

like image 118
Remy Lebeau Avatar answered Oct 12 '22 11:10

Remy Lebeau