FLTK logo

RE: [fltk.general] bug in fl_measure?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

RE: bug in fl_measure? "MacArthur, Ian (SELEX) (UK)" Apr 26, 2006  
 
> here is code, it is strange, if text is text without spaces
> it returns good
> w value, but if there are spaces "sadfsdfasdf adsfasdf" it
> gives w some
> about "sadfsdfasdf" but not all... h value is alvays good...

You might want to set w = 0; before calling fl_measure. If w is non-zero when measure is called, it will think you are wanting to pass a clipping width... Check the docs for this, might be what is happening?

Other than that, I don't see what might be wrong, and there's no way we can test the code you have posted so...
Things that might be worth checking are that you have loaded the fonts, and the font index you are passing does point to a valid font. And the chosen font can support the size you are requesting. And the text string you pass in *is* what you think it is.
I don't know what else...

Anyway:
Here's an example that seems to work OK as far as I can tell...
------------------
#include <stdio.h>

#include <Fl/Fl.H>
#include <Fl/Fl_Double_Window.H>
#include <Fl/Fl_Button.H>
#include <Fl/fl_draw.H>

static Fl_Double_Window *outer_win  = (Fl_Double_Window *)0;
static Fl_Button* but1 = 0;

static void cb_Okay(Fl_Button*, void*) {
	outer_win->hide();
}

int main(int argc, char **argv) {
	char text_sp[] = "Here is a text string with spaces";
	char text_ns[] = "Here.is.a.text.string.without.spa";
	int tw, th;

	Fl::get_system_colors();

	outer_win = new Fl_Double_Window(100, 100, 260, 150, "Test Window");
	outer_win->begin();

	but1 = new Fl_Button(43, 119, 82, 27, "OK");
	but1->callback((Fl_Callback*)cb_Okay);
	outer_win->end();
	outer_win->show(argc, argv);

	fl_font(FL_COURIER, 14);
	printf("Courier (fixed)\n");
	tw = 0;
	th = 0;
	fl_measure(text_ns, tw, th);
	printf("No Spaces: W: %d  H: %d\n", tw, th);

	tw = 0;
	th = 0;
	fl_measure(text_sp, tw, th);
	printf("Spaces:    W: %d  H: %d\n", tw, th);

	fl_font(FL_HELVETICA, 14);
	printf("\nHelvetica (Proportional)\n");
	tw = 0;
	th = 0;
	fl_measure(text_ns, tw, th);
	printf("No Spaces: W: %d  H: %d\n", tw, th);

	tw = 0;
	th = 0;
	fl_measure(text_sp, tw, th);
	printf("Spaces:    W: %d  H: %d\n", tw, th);
	fflush(stdout);

	return Fl::run();
}
/* End of File */

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************


Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.