comparison src/objects-x.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 9ee227acff29
children 1ce6082ce73f
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
285 FONT_INSTANCE_X_FONT (f) = xf; 285 FONT_INSTANCE_X_FONT (f) = xf;
286 f->ascent = xf->ascent; 286 f->ascent = xf->ascent;
287 f->descent = xf->descent; 287 f->descent = xf->descent;
288 f->height = xf->ascent + xf->descent; 288 f->height = xf->ascent + xf->descent;
289 { 289 {
290 /* following change suggested by Ted Phelps <phelps@dstc.edu.au> */ 290 unsigned int def_char = xf->default_char;
291 unsigned int def_char = 'n'; /*xf->default_char;*/
292 int byte1, byte2; 291 int byte1, byte2;
293 292
294 once_more: 293 once_more:
295 byte1 = def_char >> 8; 294 byte1 = def_char >> 8;
296 byte2 = def_char & 0xFF; 295 byte2 = def_char & 0xFF;
314 /* Some fonts have a default char whose width is 0. This is no good. 313 /* Some fonts have a default char whose width is 0. This is no good.
315 If that's the case, first try 'n' as the default char, and if n has 314 If that's the case, first try 'n' as the default char, and if n has
316 0 width too (unlikely) then just use the max width. */ 315 0 width too (unlikely) then just use the max width. */
317 if (f->width == 0) 316 if (f->width == 0)
318 { 317 {
319 if (def_char == xf->default_char) 318 if (def_char == 'n')
320 f->width = xf->max_bounds.width; 319 f->width = xf->max_bounds.width;
321 else 320 else
322 { 321 {
323 def_char = xf->default_char; 322 def_char = 'n';
324 goto once_more; 323 goto once_more;
325 } 324 }
326 } 325 }
327 } 326 }
328 /* If all characters don't exist then there could potentially be 327 /* If all characters don't exist then there could potentially be
758 if (names) 757 if (names)
759 XFreeFontNames (names); 758 XFreeFontNames (names);
760 return result; 759 return result;
761 } 760 }
762 761
762 #ifdef MULE
763
764 static int
765 x_font_spec_matches_charset (struct device *d, Lisp_Object charset,
766 CONST Bufbyte *nonreloc, Lisp_Object reloc,
767 Bytecount offset, Bytecount length)
768 {
769 if (UNBOUNDP (charset))
770 return 1;
771 /* Hack! Short font names don't have the registry in them,
772 so we just assume the user knows what they're doing in the
773 case of ASCII. For other charsets, you gotta give the
774 long form; sorry buster.
775 */
776 if (EQ (charset, Vcharset_ascii))
777 {
778 CONST Bufbyte *the_nonreloc = nonreloc;
779 int i;
780 Bytecount the_length = length;
781
782 if (!the_nonreloc)
783 the_nonreloc = XSTRING_DATA (reloc);
784 fixup_internal_substring (nonreloc, reloc, offset, &the_length);
785 the_nonreloc += offset;
786 if (!memchr (the_nonreloc, '*', the_length))
787 {
788 for (i = 0;; i++)
789 {
790 CONST Bufbyte *new_nonreloc =
791 memchr (the_nonreloc, '-', the_length);
792 if (!new_nonreloc)
793 break;
794 new_nonreloc++;
795 the_length -= new_nonreloc - the_nonreloc;
796 the_nonreloc = new_nonreloc;
797 }
798
799 /* If it has less than 5 dashes, it's a short font.
800 Of course, long fonts always have 14 dashes or so, but short
801 fonts never have more than 1 or 2 dashes, so this is some
802 sort of reasonable heuristic. */
803 if (i < 5)
804 return 1;
805 }
806 }
807
808 return (fast_string_match (XCHARSET_REGISTRY (charset),
809 nonreloc, reloc, offset, length, 1,
810 ERROR_ME, 0) >= 0);
811 }
812
813 /* find a font spec that matches font spec FONT and also matches
814 (the registry of) CHARSET. */
815 static Lisp_Object
816 x_find_charset_font (Lisp_Object device, Lisp_Object font,
817 Lisp_Object charset)
818 {
819 char **names;
820 int count = 0;
821 Lisp_Object result = Qnil;
822 CONST char *patternext;
823 int i;
824
825 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext);
826
827 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)),
828 patternext, MAX_FONT_COUNT, &count);
829 for (i = 0; i < count; i ++)
830 {
831 CONST char *intname;
832
833 GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA (names[i], intname);
834 if (x_font_spec_matches_charset (XDEVICE (device), charset,
835 (unsigned char *) intname,
836 Qnil, 0, -1))
837 {
838 result = build_string (intname);
839 break;
840 }
841 }
842
843 if (names)
844 XFreeFontNames (names);
845
846 /* Check for a short font name. */
847 if (NILP (result)
848 && x_font_spec_matches_charset (XDEVICE (device), charset, 0,
849 font, 0, -1))
850 return font;
851
852 return result;
853 }
854
855 #endif /* MULE */
856
763 857
764 /************************************************************************/ 858 /************************************************************************/
765 /* initialization */ 859 /* initialization */
766 /************************************************************************/ 860 /************************************************************************/
767 861
788 CONSOLE_HAS_METHOD (x, print_font_instance); 882 CONSOLE_HAS_METHOD (x, print_font_instance);
789 CONSOLE_HAS_METHOD (x, finalize_font_instance); 883 CONSOLE_HAS_METHOD (x, finalize_font_instance);
790 CONSOLE_HAS_METHOD (x, font_instance_truename); 884 CONSOLE_HAS_METHOD (x, font_instance_truename);
791 CONSOLE_HAS_METHOD (x, font_instance_properties); 885 CONSOLE_HAS_METHOD (x, font_instance_properties);
792 CONSOLE_HAS_METHOD (x, list_fonts); 886 CONSOLE_HAS_METHOD (x, list_fonts);
887 #ifdef MULE
888 CONSOLE_HAS_METHOD (x, find_charset_font);
889 CONSOLE_HAS_METHOD (x, font_spec_matches_charset);
890 #endif
793 } 891 }
794 892
795 void 893 void
796 vars_of_objects_x (void) 894 vars_of_objects_x (void)
797 { 895 {