Пример #1
0
static Lisp_Object
gtk_list_fonts (Lisp_Object pattern, Lisp_Object device)
{
  const char *patternext;

  TO_EXTERNAL_FORMAT (LISP_STRING, pattern, C_STRING_ALLOCA, patternext, Qbinary);

  return (__gtk_list_fonts_internal (patternext));
}
Пример #2
0
static int
gtk_valid_color_name_p (struct device *d, Lisp_Object color)
{
  GdkColor c;
  const char *extname;

  TO_EXTERNAL_FORMAT (LISP_STRING, color, C_STRING_ALLOCA, extname, Qctext);

  if (gdk_color_parse (extname, &c) != TRUE)
      return(0);
  return (1);
}
Пример #3
0
/* find a font spec that matches font spec FONT and also matches
   (the registry of) CHARSET. */
static Lisp_Object
gtk_find_charset_font (Lisp_Object device, Lisp_Object font, Lisp_Object charset)
{
  char **names;
  int count = 0;
  Lisp_Object result = Qnil;
  const char *patternext;
  int i;

  TO_EXTERNAL_FORMAT (LISP_STRING, font, C_STRING_ALLOCA, patternext, Qbinary);

  names = XListFonts (GDK_DISPLAY (),
		      patternext, MAX_FONT_COUNT, &count);
  /* ### This code seems awfully bogus -- mrb */
  for (i = 0; i < count; i ++)
    {
      const Bufbyte *intname;
      Bytecount intlen;

      TO_INTERNAL_FORMAT (C_STRING, names[i], ALLOCA, (intname, intlen),
			  Qctext);
      if (gtk_font_spec_matches_charset (XDEVICE (device), charset,
					 intname, Qnil, 0, -1))
	{
	  result = make_string ((char *) intname, intlen);
	  break;
	}
    }

  if (names)
    XFreeFontNames (names);

  /* Check for a short font name. */
  if (NILP (result)
      && gtk_font_spec_matches_charset (XDEVICE (device), charset, 0,
					font, 0, -1))
    return font;

  return result;
}
Пример #4
0
int
gtk_parse_nearest_color (struct device *d, GdkColor *color, Bufbyte *name,
			 Bytecount len, Error_behavior errb)
{
  GdkColormap *cmap;
  GdkVisual *visual;
  int result;

  cmap = DEVICE_GTK_COLORMAP(d);
  visual = DEVICE_GTK_VISUAL (d);

  xzero (*color);
  {
    const Extbyte *extname;
    Extcount extnamelen;

    TO_EXTERNAL_FORMAT (DATA, (name, len), ALLOCA, (extname, extnamelen), Qbinary);

    result = gdk_color_parse (extname, color);
  }
  
  if (result == FALSE)
    {
      maybe_signal_simple_error ("unrecognized color", make_string (name, len),
				 Qcolor, errb);
      return 0;
    }
  result = allocate_nearest_color (cmap, visual, color);
  if (!result)
    {
      maybe_signal_simple_error ("couldn't allocate color",
				 make_string (name, len), Qcolor, errb);
      return 0;
    }

  return result;
}
Пример #5
0
static ms_driver_data_t
media_sndfile_open(Lisp_Media_Stream *ms)
{
	mtype_audio_properties *mtap;
	media_substream *mss;
	/* libsndfile stuff */
	media_sndfile_data *sfd = NULL;
	SNDFILE *sf = NULL;
	SF_INFO *sfinfo;

	/* initialise */
	sfinfo = xnew_and_zero(SF_INFO);

	switch (media_stream_kind(ms)) {
	case MKIND_FILE: {
		mkind_file_properties *mkfp = NULL;
		const char *file = NULL;
		int file_len = 0;

		/* open the file */
		mkfp = media_stream_kind_properties(ms).fprops;
		TO_EXTERNAL_FORMAT(LISP_STRING, mkfp->filename,
				   ALLOCA, (file, file_len), Qnil);
		if ( file != NULL ) {
			sf = sf_open(file, SFM_READ, sfinfo);
		}
		break;
	}
	case MKIND_STRING: {
		mkind_string_properties *mksp = NULL;
		SF_VIRTUAL_IO *sfvio = NULL;
		/* our container for sfvio */
		media_data *sd = NULL;

		/* prepare sndfile's virtual-I/O */
		sfvio = xnew_and_zero(SF_VIRTUAL_IO);
		sfvio->get_filelen = &sndfile_vio_get_filelen;
		sfvio->seek = &sndfile_vio_seek;
		sfvio->read = &sndfile_vio_read;
		sfvio->write = &sndfile_vio_write;
		sfvio->tell = &sndfile_vio_tell;

		/* prepare our user_data */
		mksp = media_stream_kind_properties(ms).sprops;
		sd = xnew_and_zero(media_data);
		sd->length = mksp->size;
		sd->seek = 0;
		sd->data = mksp->stream_data;

		/* retrieve the main handle */
		sf = sf_open_virtual(sfvio, SFM_READ, sfinfo, (void*)sd);
		break;
	}

	case MKIND_UNKNOWN:
	case MKIND_FIFO:
	case MKIND_STREAM:
	case NUMBER_OF_MEDIA_KINDS:
	default:
		break;
	}

	if (!sf) {
		xfree(sfinfo);
		media_stream_set_meths(ms, NULL);
		media_stream_driver(ms) = MDRIVER_UNKNOWN;
		return NULL;
	}

	/* now create a substream and fill it with information */
	mss = make_media_substream_append(ms);
	media_substream_type(mss) = MTYPE_AUDIO;
	mtap = xnew_and_zero(mtype_audio_properties);

	mtap->channels = sfinfo->channels;
	mtap->samplerate = sfinfo->samplerate;

	/* try to find a read function */
	switch (sfinfo->format & 0xFF) {
	case SF_FORMAT_ULAW:
	case SF_FORMAT_ALAW:
	case SF_FORMAT_PCM_U8:
	case SF_FORMAT_PCM_S8:
		mtap->samplewidth = 8;
		mtap->framesize = mtap->channels;
		/* stuff is read in as S16 values anyway */
		mtap->msf = sxe_msf_S16;
		break;
	case SF_FORMAT_PCM_16:
		mtap->samplewidth = 16;
		mtap->framesize = mtap->channels * 2;
		mtap->msf = sxe_msf_S16;
		break;
	case SF_FORMAT_PCM_24:
		mtap->samplewidth = 32;
		mtap->framesize = mtap->channels * 4;
		mtap->msf = sxe_msf_S24;
		break;
	case SF_FORMAT_PCM_32:
		mtap->samplewidth = 32;
		mtap->framesize = mtap->channels * 4;
		mtap->msf = sxe_msf_S32;
		break;
	case SF_FORMAT_FLOAT:
		mtap->samplewidth = 32;
		mtap->framesize = mtap->channels * 4;
		mtap->msf = sxe_msf_FLT;
		break;
	default:
		xfree(sfinfo);
		xfree(mtap);
		media_stream_set_meths(ms, NULL);
		media_stream_driver(ms) = MDRIVER_UNKNOWN;
		return NULL;
		break;
	}
	mtap->name = NULL;
	mtap->endianness = 0;

	/* now assign */
	media_substream_type_properties(mss).aprops = mtap;
	media_stream_set_meths(ms, media_sndfile);

	/* keep the SNDFILE context */
	sfd = xnew_and_zero(media_sndfile_data);
	sfd->sf = sf;
	sfd->sfinfo = sfinfo;
	media_substream_data(mss) = sfd;
	media_stream_data(ms) = sfd;

	/* set me as driver indicator */
	media_stream_driver(ms) = MYSELF;

	return sf;
}
Пример #6
0
static ms_driver_data_t
media_sox_open(Lisp_Media_Stream *ms)
{
	media_substream *mss;
	mtype_audio_properties *mtap;
	char *name = NULL;
	/* libsndfile stuff */
	sxe_sox_t ft = NULL;
	sxe_sox_signalinfo_t *stinfo = NULL;

	/* initialise */
	switch (media_stream_kind(ms)) {
	case MKIND_FILE: {
		mkind_file_properties *mkfp = NULL;
		const char *file = NULL;
		int file_len __attribute__((unused)) = 0;

		/* open the file */
		mkfp = media_stream_kind_properties(ms).fprops;
		TO_EXTERNAL_FORMAT(LISP_STRING, mkfp->filename,
				   ALLOCA, (file, file_len), Qnil);
		if( file != NULL ) {
#if defined HAVE_SOX_OPEN_READ_3ARGS
			    ft = sxe_sox_open_read(file, NULL, NULL);
#elif defined HAVE_SOX_OPEN_READ_4ARGS
			    ft = sxe_sox_open_read(file, NULL, NULL, NULL);
#else
# error You shouldnt be here.  Wake up before you try to compile me.
#endif
		}
		break;
	}
	case MKIND_STRING: {
		/* not yet handable */
		break;
	}
	default:
		break;
	}

	if (!ft) {
		media_stream_set_meths(ms, NULL);
		media_stream_driver(ms) = MDRIVER_UNKNOWN;
		return NULL;
	}

	/* retrieve the signal information */
#if defined HAVE_STRUCT_SOX_FORMAT_T
	stinfo = &ft->signal;
#else
#  error "What's the matter with you?! How did you reach this?"
#endif

	/* create a substream */
	mss = make_media_substream_append(ms);
	media_substream_type(mss) = MTYPE_AUDIO;
	mtap = xnew_and_zero(mtype_audio_properties);

	mtap->channels = stinfo->channels;
	mtap->samplerate = stinfo->rate;

	/* try to find a read function */
#if defined HAVE_SOX_SIGNALINFO_T_PRECISION
	mtap->samplewidth = stinfo->precision;
	mtap->framesize = mtap->channels * (stinfo->precision / 8);
#else
	switch (stinfo->size) {
	case SXE_SIZE_8BIT:
		mtap->samplewidth = 8;
		mtap->framesize = mtap->channels;
		break;
	case SXE_SIZE_16BIT:
		mtap->samplewidth = 16;
		mtap->framesize = mtap->channels * 2;
		break;
	case SXE_SIZE_24BIT:
		mtap->samplewidth = 24;
		mtap->framesize = mtap->channels * 3;
		break;
	case SXE_SIZE_32BIT:
		mtap->samplewidth = 32;
		mtap->framesize = mtap->channels * 4;
		break;
	case SXE_SIZE_64BIT:
		mtap->samplewidth = 64;
		mtap->framesize = mtap->channels * 8;
		break;
	default:
		mtap->samplewidth = 32;
		mtap->framesize = mtap->channels * 4;
		break;
	}
#endif
	/* since SoX internally uses S32, we bang from S32 */
	mtap->msf = sxe_msf_S32;
#if 0
	mtap->samplewidth = 8 * sizeof(float);
	mtap->framesize = mtap->channels * sizeof(float);
#endif

	mtap->name = name;
	mtap->endianness = 0;

	/* now assign */
	media_substream_type_properties(mss).aprops = mtap;
	media_stream_set_meths(ms, media_sox);

	/* keep the sox handle */
	media_stream_data(ms) = ft;
	media_substream_data(mss) = ft;

	/* set me as driver indicator */
	media_stream_driver(ms) = MYSELF;

	return ft;
}
Пример #7
0
static int
gtk_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
			      Lisp_Object device, Error_behavior errb)
{
  GdkFont *gf;
  XFontStruct *xf;
  const char *extname;

  TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, extname, Qctext);

  gf = gdk_font_load (extname);

  if (!gf)
    {
      maybe_signal_simple_error ("couldn't load font", f->name,
				 Qfont, errb);
      return 0;
    }

  xf = GDK_FONT_XFONT (gf);

  /* Don't allocate the data until we're sure that we will succeed,
     or the finalize method may get f****d. */
  f->data = xnew (struct gtk_font_instance_data);
  FONT_INSTANCE_GTK_TRUENAME (f) = Qnil;
  FONT_INSTANCE_GTK_FONT (f) = gf;
  f->ascent = gf->ascent;
  f->descent = gf->descent;
  f->height = gf->ascent + gf->descent;

  /* Now lets figure out the width of the font */
  {
    /* following change suggested by Ted Phelps <*****@*****.**> */
    unsigned int def_char = 'n'; /*xf->default_char;*/
    unsigned int byte1, byte2;

  once_more:
    byte1 = def_char >> 8;
    byte2 = def_char & 0xFF;

    if (xf->per_char)
      {
	/* Old versions of the R5 font server have garbage (>63k) as
	   def_char. 'n' might not be a valid character. */
	if (byte1 < xf->min_byte1         ||
	    byte1 > xf->max_byte1         ||
	    byte2 < xf->min_char_or_byte2 ||
	    byte2 > xf->max_char_or_byte2)
	  f->width = 0;
	else
	  f->width = xf->per_char[(byte1 - xf->min_byte1) *
				  (xf->max_char_or_byte2 -
				   xf->min_char_or_byte2 + 1) +
				  (byte2 - xf->min_char_or_byte2)].width;
      }
    else
      f->width = xf->max_bounds.width;

    /* Some fonts have a default char whose width is 0.  This is no good.
       If that's the case, first try 'n' as the default char, and if n has
       0 width too (unlikely) then just use the max width. */
    if (f->width == 0)
      {
	if (def_char == xf->default_char)
	  f->width = xf->max_bounds.width;
	else
	  {
	    def_char = xf->default_char;
	    goto once_more;
	  }
      }
  }

  /* If all characters don't exist then there could potentially be
     0-width characters lurking out there.  Not setting this flag
     trips an optimization that would make them appear to have width
     to redisplay.  This is bad.  So we set it if not all characters
     have the same width or if not all characters are defined.
     */
  /* #### This sucks.  There is a measurable performance increase
     when using proportional width fonts if this flag is not set.
     Unfortunately so many of the f*****g X fonts are not fully
     defined that we could almost just get rid of this damn flag and
     make it an assertion. */
  f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
		       (/* x_handle_non_fully_specified_fonts */ 0 &&
			!xf->all_chars_exist));
#if 0
  f->width = gdk_char_width (gf, 'n');
  f->proportional_p = (gdk_char_width (gf, '|') != gdk_char_width (gf, 'W')) ? 1 : 0;
#endif
  return 1;
}