mam prośbę o pomoc w rozwiązaniu problemu z (chyba) kodowaniem polskich znaków w niektórych fontach, których używam do tworzenia plików png.
skrypt wygląda tak (jes to tylko część kodu php, służąca do wglądu, całość można znależźć tutaj
http://www.stewartspeak.com/projects/dtr/ ):
<?php /* Dynamic Heading Generator By Stewart Rosenberger <a href="http://www.stewartspeak.com/headings/" target="_blank">http://www.stewartspeak.com/headings/</a> This script generates PNG images of text, written in the font/size that you specify. These PNG images are passed back to the browser. Optionally, they can be cached for later use. If a cached image is found, a new image will not be generated, and the existing copy will be sent to the browser. Additional documentation on php's image handling capabilities can be found at <a href="http://www.php.net/image/" target="_blank">http://www.php.net/image/</a> */ //include ('includes/configure.php'); $font_file = 'fonts/BKANT.TTF' ; $font_size = 20 ; $font_color = '#ff005e' ; $background_color = '#ffffff'; $transparent_background = true ; $cache_images = false ; $cache_folder = 'c:/usr/apache/httpd/html/salony/cache/' ; /* --------------------------------------------------------------------------- For basic usage, you should not need to edit anything below this comment. If you need to further customize this script's abilities, make sure you are familiar with php and its image handling capabilities. --------------------------------------------------------------------------- */ $mime_type = 'image/png' ; $extension = '.png' ; $send_buffer_size = 4096 ; // check for GD support if(!function_exists('ImageCreate')) fatal_error('Error: Server does not support php image generation') ; // clean up text fatal_error('Error: No text specified.') ; $text = $_GET['text'] ; $text = javascript_to_html($text) ; // look for cached copy, send if it exists $background_color . $transparent_background . $text) ; $cache_filename = $cache_folder . '/' . $hash . $extension ; { exit ; } // check font availability if(!$font_found) { fatal_error('Error: The server is missing the specified font.') ; } // create image $background_rgb = hex_to_rgb($background_color) ; $font_rgb = hex_to_rgb($font_color) ; $dip = get_dip($font_file,$font_size) ; $box = @ImageTTFBBox($font_size,0,$font_file,$text) ; if(!$image || !$box) { fatal_error('Error: The server could not create this heading image.') ; } // allocate colors and draw text $background_color = @ImageColorAllocate($image,$background_rgb['red'], $background_rgb['green'],$background_rgb['blue']) ; $font_color = ImageColorAllocate($image,$font_rgb['red'], $font_rgb['green'],$font_rgb['blue']) ; $font_color,$font_file,$text) ; // set transparency if($transparent_background) ImageColorTransparent($image,$background_color) ; ImagePNG($image) ; // save copy of image for cache if($cache_images) { @ImagePNG($image,$cache_filename) ; } ImageDestroy($image) ; exit ; /* try to determine the "dip" (pixels dropped below baseline) of this font for this size. */ function get_dip($font,$size) { $test_chars = 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . '1234567890' . '!@#$%^&*()'"/;.,`~<>[]{}-+_-=' ; $box = @ImageTTFBBox($size,0,$font,$test_chars) ; return $box[3] ; } /* attempt to create an image containing the error message given. if this works, the image is sent to the browser. if not, an error is logged, and passed back to the browser as a 500 code instead. */ function fatal_error($message) { // send an image if(function_exists('ImageCreate')) { $width = ImageFontWidth(5) * strlen($message) + 10 ; $height = ImageFontHeight(5) + 10 ; if($image = ImageCreate($width,$height)) { $background = ImageColorAllocate($image,255,255,255) ; $text_color = ImageColorAllocate($image,0,0,0) ; ImageString($image,5,5,5,$message,$text_color) ; header('Content-type: image/png') ; ImagePNG($image) ; ImageDestroy($image) ; exit ; } } // send 500 code header("HTTP/1.0 500 Internal Server Error") ; print($message) ; exit ; } /* decode an HTML hex-code into an array of R,G, and B values. accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff */ function hex_to_rgb($hex) { // remove '#' if(substr($hex,0,1) == '#') $hex = substr($hex,1) ; // expand short form ('fff') color if(strlen($hex) == 3) { $hex = substr($hex,0,1) . substr($hex,0,1) . substr($hex,1,1) . substr($hex,1,1) . substr($hex,2,1) . substr($hex,2,1) ; } if(strlen($hex) != 6) fatal_error('Error: Invalid color "'.$hex.'"') ; // convert $rgb['red'] = hexdec(substr($hex,0,2)) ; $rgb['green'] = hexdec(substr($hex,2,2)) ; $rgb['blue'] = hexdec(substr($hex,4,2)) ; return $rgb ; } /* convert embedded, javascript unicode characters into embedded HTML entities. (e.g. '%u2018' => '‘'). returns the converted string. */ function javascript_to_html($text) { $matches = null ; preg_match_all('/%u([0-9A-F]{4})/i',$text,$matches) ; if(!empty($matches)) for($i=0;$i<sizeof($matches[0]);$i++) $text = str_replace($matches[0][$i], '&#'.hexdec($matches[1][$i]).';',$text) ; return $text ; } ?>
czcionki, z którymi mam problem można pobrać w celach testowych stąd :
http://www.domtar.pl/fonty.zip
w dokumentacji do skryptu można znaleźć taką uwagę :
"Some fonts do not contain glyphs for every character you may need. When this happens, such as with certain non-English characters, you will see blocks instead of words. The only fix for this problem is to use a different font."
Używane przezemnie czcionki są polskojęzyczne, W windowsie czy Photoshopie nie ma problemu z polskimi znakami, więc teoretycznie nie powinno być ich również w php.
Moje przypuszczenia : istnieją różne sposoby kodowania znaków w plikach ttf (tak samo jak istnieje ttf type 1 i ttf type 2, o czym wiele osób nie ma zielonego pojęcia), tylko jak zmienić kodowanie w takiej czcionce ?
Jeżeli ktoś wie o jakimś programie do konwersji czcionek (nawet komercyjnym) lub o jakimś innym skrypcie który nie będzie mieć problemów z polskimi znakami, niech da znać.
Dziękuję za wszytskie odpowiedzi.
Sprawa rozwiązana, problem tkwi w tzw mapowaniu fontów (czyli zdaje się coś jak kodowanie).
Na krasnalu propblemy ze znakami znikają po zapisaniu w czciokach takich dwóch mapowań, wygenerownych z PostScriptu :
Macitosh Roman
Microsoft Unicode BMP only.
Można to zrobić wersją testową programu FontCreator 5.5
Pradowpodbnie pod unixami również problemy znikną.