//***************************************************************************** // //! Draws a released Button. //! //! \param context is a pointer to the drawing context to use. //! \param button is a pointer to the structure containing the extents of the //! button. //! //! This function draws a button using the released parameters. //! //! \return None. // //***************************************************************************** void Graphics_drawReleasedButton(const Graphics_Context *context, const Graphics_Button *button) { uint32_t origFrgnd = g_sContext.foreground; Graphics_Font *origFont = (Graphics_Font *) g_sContext.font; Graphics_Rectangle innerRect = { button->xMin + button->borderWidth, button->yMin + button->borderWidth, button->xMax - button->borderWidth, button->yMax - button->borderWidth, }; Graphics_setForegroundColor(&g_sContext,button->fillColor); Graphics_fillRectangle(&g_sContext, &innerRect); Graphics_setFont(&g_sContext,button->font); Graphics_setForegroundColor(&g_sContext,button->textColor); Graphics_drawString(&g_sContext, button->text, AUTO_STRING_LENGTH, button->textXPos, button->textYPos, TRANSPARENT_TEXT); Graphics_setFont(&g_sContext,origFont); Graphics_setForegroundColor(&g_sContext,origFrgnd); }
int HyperPage_picture (I, double width_inches, double height_inches, void (*draw) (Graphics g)) { iam (HyperPage); double topSpacing = 0.1, bottomSpacing = 0.1, minFooterDistance = 0.0; kGraphics_font font = my font; int size = my fontSize; width_inches *= width_inches < 0.0 ? -1.0 : size / 12.0; height_inches *= height_inches < 0.0 ? -1.0 : size / 12.0; if (! my printing) { my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; if (my d_y > PAGE_HEIGHT + height_inches || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) { my d_y -= height_inches; } else { my d_y -= height_inches; Graphics_setFont (my g, font); Graphics_setFontStyle (my g, 0); Graphics_setFontSize (my g, size); my d_x = width_inches > my rightMargin ? 0 : 0.5 * (my rightMargin - width_inches); Graphics_setWrapWidth (my g, 0); Graphics_setViewport (my g, my d_x, my d_x + width_inches, my d_y, my d_y + height_inches); draw (my g); Graphics_setViewport (my g, 0, 1, 0, 1); Graphics_setWindow (my g, 0, 1, 0, 1); Graphics_setTextAlignment (my g, Graphics_LEFT, Graphics_BOTTOM); } } else { Graphics_setFont (my ps, font); Graphics_setFontStyle (my ps, 0); Graphics_setFontSize (my ps, size); my d_y -= my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= height_inches; if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) { Graphics_nextSheetOfPaper (my ps); if (my d_printingPageNumber) my d_printingPageNumber ++; HyperPage_initSheetOfPaper (me); Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= height_inches; } my d_x = 3.7 - 0.5 * width_inches; if (my d_x < 0) my d_x = 0; Graphics_setWrapWidth (my ps, 0); Graphics_setViewport (my ps, my d_x, my d_x + width_inches, my d_y, my d_y + height_inches); draw (my ps); Graphics_setViewport (my ps, 0, 1, 0, 1); Graphics_setWindow (my ps, 0, 1, 0, 1); Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); } my previousBottomSpacing = bottomSpacing; return 1; }
autoTableEditor TableEditor_create (const char32 *title, Table table) { try { autoTableEditor me = Thing_new (TableEditor); Editor_init (me.get(), 0, 0, 700, 500, title, table); #if motif Melder_assert (XtWindow (my drawingArea -> d_widget)); #endif my topRow = 1; my leftColumn = 1; my selectedColumn = 1; my selectedRow = 1; my graphics = Graphics_create_xmdrawingarea (my drawingArea); double size_pixels = SIZE_INCHES * Graphics_getResolution (my graphics.get()); Graphics_setWsViewport (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setWsWindow (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setViewport (my graphics.get(), 0.0, size_pixels, 0.0, size_pixels); Graphics_setFont (my graphics.get(), kGraphics_font_COURIER); Graphics_setFontSize (my graphics.get(), 12); Graphics_setUnderscoreIsSubscript (my graphics.get(), false); Graphics_setAtSignIsLink (my graphics.get(), true); return me; } catch (MelderError) { Melder_throw (U"TableEditor not created."); } }
int HyperPage_formula (I, const wchar_t *formula) { iam (HyperPage); double topSpacing = 0.2, bottomSpacing = 0.2, minFooterDistance = 0.0; kGraphics_font font = my font; int size = my fontSize; if (! my printing) { my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= size * (1.2/72); if (my d_y > PAGE_HEIGHT + 2.0 || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) { } else { Graphics_setFont (my g, font); Graphics_setFontStyle (my g, 0); Graphics_setFontSize (my g, size); Graphics_setWrapWidth (my g, 0); Graphics_setTextAlignment (my g, Graphics_CENTRE, Graphics_BOTTOM); Graphics_text (my g, my rightMargin / 2, my d_y, formula); Graphics_setTextAlignment (my g, Graphics_LEFT, Graphics_BOTTOM); } } else { Graphics_setFont (my ps, font); Graphics_setFontStyle (my ps, 0); Graphics_setFontSize (my ps, size); my d_y -= my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= size * (1.2/72); if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) { Graphics_nextSheetOfPaper (my ps); if (my d_printingPageNumber) my d_printingPageNumber ++; HyperPage_initSheetOfPaper (me); Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= size * (1.2/72); } Graphics_setWrapWidth (my ps, 0); Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_BOTTOM); Graphics_text (my ps, 3.7, my d_y, formula); Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); } my previousBottomSpacing = bottomSpacing; return 1; }
static void logo (Graphics g) { Graphics_setWindow (g, 0, 1, 0.00, 0.80); Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF); Graphics_setFont (g, kGraphics_font_TIMES); Graphics_setFontSize (g, 45); Graphics_setColour (g, Graphics_MAROON); Graphics_text (g, 0.385, 0.66, L"P"); Graphics_text (g, 0.448, 0.66, L"\\s{R}"); Graphics_text (g, 0.510, 0.66, L"\\s{A}"); Graphics_text (g, 0.575, 0.66, L"\\s{A}"); Graphics_text (g, 0.628, 0.66, L"\\s{T}"); Graphics_setFontSize (g, 15); Graphics_text (g, 0.5, 0.55, L"%%doing phonetics by computer"); #define xstr(s) str(s) #define str(s) #s Graphics_text (g, 0.5, 0.45, L"version " xstr(PRAAT_VERSION_STR)); Graphics_setColour (g, Graphics_BLACK); Graphics_setFontSize (g, 14); Graphics_text (g, 0.5, 0.33, L"www.praat.org"); Graphics_setFont (g, kGraphics_font_HELVETICA); Graphics_setFontSize (g, 10); Graphics_text (g, 0.5, 0.16, L"Copyright \\co 1992-" xstr(PRAAT_YEAR) " by Paul Boersma and David Weenink"); }
static void logo_defaultDraw (Graphics g) { Graphics_setColour (g, Graphics_MAGENTA); Graphics_fillRectangle (g, 0, 1, 0, 1); Graphics_setGrey (g, 0.5); Graphics_fillRectangle (g, 0.05, 0.95, 0.1, 0.9); Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF); Graphics_setColour (g, Graphics_YELLOW); Graphics_setFont (g, kGraphics_font_TIMES); Graphics_setFontSize (g, 24); Graphics_setFontStyle (g, Graphics_ITALIC); Graphics_setUnderscoreIsSubscript (g, false); // because program names may contain underscores Graphics_text (g, 0.5, 0.6, praatP.title); Graphics_setFontStyle (g, 0); Graphics_setFontSize (g, 12); Graphics_text (g, 0.5, 0.25, U"\\s{Built on the} %%Praat shell%\\s{,© Paul Boersma, 1992-2015"); }
void HyperPage_initSheetOfPaper (HyperPage me) { int reflect = my mirror && (my d_printingPageNumber & 1) == 0; wchar_t *leftHeader = reflect ? my outsideHeader : my insideHeader; wchar_t *rightHeader = reflect ? my insideHeader : my outsideHeader; wchar_t *leftFooter = reflect ? my outsideFooter : my insideFooter; wchar_t *rightFooter = reflect ? my insideFooter : my outsideFooter; my d_y = PAPER_TOP - TOP_MARGIN; my d_x = 0; my previousBottomSpacing = 0.0; Graphics_setFont (my ps, kGraphics_font_TIMES); Graphics_setFontSize (my ps, 12); Graphics_setFontStyle (my ps, Graphics_ITALIC); if (leftHeader) { Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_TOP); Graphics_text (my ps, 0.7, PAPER_TOP, leftHeader); } if (my middleHeader) { Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_TOP); Graphics_text (my ps, 0.7 + 3, PAPER_TOP, my middleHeader); } if (rightHeader) { Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_TOP); Graphics_text (my ps, 0.7 + 6, PAPER_TOP, rightHeader); } if (leftFooter) { Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); Graphics_text (my ps, 0.7, PAPER_BOTTOM, leftFooter); } if (my middleFooter) { Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_BOTTOM); Graphics_text (my ps, 0.7 + 3, PAPER_BOTTOM, my middleFooter); } if (rightFooter) { Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_BOTTOM); Graphics_text (my ps, 0.7 + 6, PAPER_BOTTOM, rightFooter); } Graphics_setFontStyle (my ps, Graphics_NORMAL); if (my d_printingPageNumber) Graphics_text1 (my ps, 0.7 + ( reflect ? 0 : 6 ), PAPER_BOTTOM, Melder_integer (my d_printingPageNumber)); Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); }
void HyperPage_init (HyperPage me, const wchar_t *title, Data data) { resolution = Gui_getResolution (NULL); Editor_init (me, 0, 0, 6 * resolution + 30, 800, title, data); #if motif Melder_assert (XtWindow (my drawingArea -> d_widget)); #endif my g = Graphics_create_xmdrawingarea (my drawingArea); Graphics_setAtSignIsLink (my g, TRUE); Graphics_setDollarSignIsCode (my g, TRUE); Graphics_setFont (my g, kGraphics_font_TIMES); if (prefs_font != kGraphics_font_TIMES && prefs_font != kGraphics_font_HELVETICA) prefs_font = kGraphics_font_TIMES; // ensure Unicode compatibility my font = prefs_font; setFontSize (me, prefs_fontSize); struct structGuiDrawingAreaResizeEvent event = { my drawingArea, 0 }; event. width = my drawingArea -> f_getWidth (); event. height = my drawingArea -> f_getHeight (); gui_drawingarea_cb_resize (me, & event); updateVerticalScrollBar (me); // scroll to the top (my top == 0) }
void setFont(const Graphics_Font &font) { Graphics_setFont(this, &font); }
static void gui_drawingarea_cb_expose (I, GuiDrawingAreaExposeEvent event) { iam (RunnerMFC); Melder_assert (event -> widget == my d_drawingArea); if (my graphics == NULL) return; // Could be the case in the very beginning. ExperimentMFC experiment = (ExperimentMFC) my data; long iresponse; if (my data == NULL) return; Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); if (experiment -> trial == 0) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> startText); } else if (experiment -> pausing) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> pauseText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } else if (experiment -> trial <= experiment -> numberOfTrials) { const wchar_t *visibleText = experiment -> stimulus [experiment -> stimuli [experiment -> trial]]. visibleText; wchar_t *visibleText_dup = Melder_wcsdup_f (visibleText ? visibleText : L""), *visibleText_p = visibleText_dup; Graphics_setFont (my graphics, kGraphics_font_TIMES); Graphics_setFontSize (my graphics, 10); Graphics_setColour (my graphics, Graphics_BLACK); Graphics_setTextAlignment (my graphics, Graphics_LEFT, Graphics_TOP); Graphics_text3 (my graphics, 0, 1, Melder_integer (experiment -> trial), L" / ", Melder_integer (experiment -> numberOfTrials)); Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_TOP); Graphics_setFontSize (my graphics, 24); /* * The run text. */ if (visibleText_p [0] != '\0') { wchar_t *visibleText_q = wcschr (visibleText_p, '|'); if (visibleText_q) *visibleText_q = '\0'; Graphics_text (my graphics, 0.5, 1.0, visibleText_p [0] != '\0' ? visibleText_p : experiment -> runText); if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += wcslen (visibleText_p); } else { Graphics_text (my graphics, 0.5, 1.0, experiment -> runText); } Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); for (iresponse = 1; iresponse <= experiment -> numberOfDifferentResponses; iresponse ++) { ResponseMFC response = & experiment -> response [iresponse]; wchar_t *textToDraw = response -> label; // can be overridden if (visibleText_p [0] != '\0') { wchar_t *visibleText_q = wcschr (visibleText_p, '|'); if (visibleText_q) *visibleText_q = '\0'; textToDraw = visibleText_p; // override if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += wcslen (visibleText_p); } if (wcsnequ (textToDraw, L"\\FI", 3)) { structMelderFile file; MelderDir_relativePathToFile (& experiment -> rootDirectory, textToDraw + 3, & file); Graphics_imageFromFile (my graphics, Melder_fileToPath (& file), response -> left, response -> right, response -> bottom, response -> top); } else { Graphics_setColour (my graphics, response -> name [0] == '\0' ? Graphics_SILVER : experiment -> responses [experiment -> trial] == iresponse ? Graphics_RED : experiment -> ok_right > experiment -> ok_left || experiment -> responses [experiment -> trial] == 0 ? Graphics_YELLOW : Graphics_SILVER); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setFontSize (my graphics, response -> fontSize ? response -> fontSize : 24); Graphics_text (my graphics, 0.5 * (response -> left + response -> right), 0.5 * (response -> bottom + response -> top), textToDraw); } Graphics_setFontSize (my graphics, 24); } for (iresponse = 1; iresponse <= experiment -> numberOfGoodnessCategories; iresponse ++) { GoodnessMFC goodness = & experiment -> goodness [iresponse]; Graphics_setColour (my graphics, experiment -> responses [experiment -> trial] == 0 ? Graphics_SILVER : experiment -> goodnesses [experiment -> trial] == iresponse ? Graphics_RED : Graphics_YELLOW); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_text (my graphics, 0.5 * (goodness -> left + goodness -> right), 0.5 * (goodness -> bottom + goodness -> top), goodness -> label); } if (experiment -> replay_right > experiment -> replay_left && my numberOfReplays < experiment -> maximumNumberOfReplays) { drawControlButton (me, experiment -> replay_left, experiment -> replay_right, experiment -> replay_bottom, experiment -> replay_top, experiment -> replay_label); } if (experiment -> ok_right > experiment -> ok_left && experiment -> responses [experiment -> trial] != 0 && (experiment -> numberOfGoodnessCategories == 0 || experiment -> goodnesses [experiment -> trial] != 0)) { drawControlButton (me, experiment -> ok_left, experiment -> ok_right, experiment -> ok_bottom, experiment -> ok_top, experiment -> ok_label); } if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } Melder_free (visibleText_dup); } else { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> endText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } }
int HyperPage_script (I, double width_inches, double height_inches, const wchar_t *script) { iam (HyperPage); wchar_t *text = Melder_wcsdup_f (script); Interpreter interpreter = Interpreter_createFromEnvironment (NULL); double topSpacing = 0.1, bottomSpacing = 0.1, minFooterDistance = 0.0; kGraphics_font font = my font; int size = my fontSize; double true_width_inches = width_inches * ( width_inches < 0.0 ? -1.0 : size / 12.0 ); double true_height_inches = height_inches * ( height_inches < 0.0 ? -1.0 : size / 12.0 ); if (! my printing) { my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; if (my d_y > PAGE_HEIGHT + true_height_inches || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) { my d_y -= true_height_inches; } else { my d_y -= true_height_inches; Graphics_setFont (my g, font); Graphics_setFontStyle (my g, 0); Graphics_setFontSize (my g, size); my d_x = true_width_inches > my rightMargin ? 0 : 0.5 * (my rightMargin - true_width_inches); Graphics_setWrapWidth (my g, 0); long x1DCold, x2DCold, y1DCold, y2DCold; Graphics_inqWsViewport (my g, & x1DCold, & x2DCold, & y1DCold, & y2DCold); double x1NDCold, x2NDCold, y1NDCold, y2NDCold; Graphics_inqWsWindow (my g, & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold); { if (my praatApplication == NULL) my praatApplication = Melder_calloc_f (structPraatApplication, 1); if (my praatObjects == NULL) my praatObjects = Melder_calloc_f (structPraatObjects, 1); if (my praatPicture == NULL) my praatPicture = Melder_calloc_f (structPraatPicture, 1); theCurrentPraatApplication = (PraatApplication) my praatApplication; theCurrentPraatApplication -> batch = true; // prevent creation of editor windows theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs theCurrentPraatObjects = (PraatObjects) my praatObjects; theCurrentPraatPicture = (PraatPicture) my praatPicture; theCurrentPraatPicture -> graphics = my g; // has to draw into HyperPage rather than Picture window theCurrentPraatPicture -> font = font; theCurrentPraatPicture -> fontSize = size; theCurrentPraatPicture -> lineType = Graphics_DRAWN; theCurrentPraatPicture -> colour = Graphics_BLACK; theCurrentPraatPicture -> lineWidth = 1.0; theCurrentPraatPicture -> arrowSize = 1.0; theCurrentPraatPicture -> x1NDC = my d_x; theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches; theCurrentPraatPicture -> y1NDC = my d_y; theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches; Graphics_setViewport (my g, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); Graphics_setWindow (my g, 0.0, 1.0, 0.0, 1.0); long x1DC, y1DC, x2DC, y2DC; Graphics_WCtoDC (my g, 0.0, 0.0, & x1DC, & y2DC); Graphics_WCtoDC (my g, 1.0, 1.0, & x2DC, & y1DC); Graphics_resetWsViewport (my g, x1DC, x2DC, y1DC, y2DC); Graphics_setWsWindow (my g, 0, width_inches, 0, height_inches); theCurrentPraatPicture -> x1NDC = 0; theCurrentPraatPicture -> x2NDC = width_inches; theCurrentPraatPicture -> y1NDC = 0; theCurrentPraatPicture -> y2NDC = height_inches; Graphics_setViewport (my g, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); { // scope autoMelderProgressOff progress; autoMelderWarningOff warning; autoMelderSaveDefaultDir saveDir; if (! MelderDir_isNull (& my rootDirectory)) { Melder_setDefaultDir (& my rootDirectory); } try { Interpreter_run (interpreter, text); } catch (MelderError) { if (my scriptErrorHasBeenNotified) { Melder_clearError (); } else { Melder_flushError (NULL); my scriptErrorHasBeenNotified = true; } } } Graphics_setLineType (my g, Graphics_DRAWN); Graphics_setLineWidth (my g, 1.0); Graphics_setArrowSize (my g, 1.0); Graphics_setColour (my g, Graphics_BLACK); /*Graphics_Link *paragraphLinks; long numberOfParagraphLinks = Graphics_getLinks (& paragraphLinks); if (my links) for (long ilink = 1; ilink <= numberOfParagraphLinks; ilink ++) { HyperLink link = HyperLink_create (paragraphLinks [ilink]. name, paragraphLinks [ilink]. x1, paragraphLinks [ilink]. x2, paragraphLinks [ilink]. y1, paragraphLinks [ilink]. y2); Collection_addItem (my links, link); }*/ theCurrentPraatApplication = & theForegroundPraatApplication; theCurrentPraatObjects = & theForegroundPraatObjects; theCurrentPraatPicture = & theForegroundPraatPicture; } Graphics_resetWsViewport (my g, x1DCold, x2DCold, y1DCold, y2DCold); Graphics_setWsWindow (my g, x1NDCold, x2NDCold, y1NDCold, y2NDCold); Graphics_setViewport (my g, 0, 1, 0, 1); Graphics_setWindow (my g, 0, 1, 0, 1); Graphics_setTextAlignment (my g, Graphics_LEFT, Graphics_BOTTOM); } } else { Graphics_setFont (my ps, font); Graphics_setFontStyle (my ps, 0); Graphics_setFontSize (my ps, size); my d_y -= my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= true_height_inches; if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) { Graphics_nextSheetOfPaper (my ps); if (my d_printingPageNumber) my d_printingPageNumber ++; HyperPage_initSheetOfPaper (me); Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= true_height_inches; } my d_x = 3.7 - 0.5 * true_width_inches; if (my d_x < 0) my d_x = 0; Graphics_setWrapWidth (my ps, 0); long x1DCold, x2DCold, y1DCold, y2DCold; Graphics_inqWsViewport (my ps, & x1DCold, & x2DCold, & y1DCold, & y2DCold); double x1NDCold, x2NDCold, y1NDCold, y2NDCold; Graphics_inqWsWindow (my ps, & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold); { if (my praatApplication == NULL) my praatApplication = Melder_calloc_f (structPraatApplication, 1); if (my praatObjects == NULL) my praatObjects = Melder_calloc_f (structPraatObjects, 1); if (my praatPicture == NULL) my praatPicture = Melder_calloc_f (structPraatPicture, 1); theCurrentPraatApplication = (PraatApplication) my praatApplication; theCurrentPraatApplication -> batch = true; theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs theCurrentPraatObjects = (PraatObjects) my praatObjects; theCurrentPraatPicture = (PraatPicture) my praatPicture; theCurrentPraatPicture -> graphics = my ps; theCurrentPraatPicture -> font = font; theCurrentPraatPicture -> fontSize = size; theCurrentPraatPicture -> lineType = Graphics_DRAWN; theCurrentPraatPicture -> colour = Graphics_BLACK; theCurrentPraatPicture -> lineWidth = 1.0; theCurrentPraatPicture -> arrowSize = 1.0; theCurrentPraatPicture -> x1NDC = my d_x; theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches; theCurrentPraatPicture -> y1NDC = my d_y; theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches; Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); Graphics_setWindow (my ps, 0.0, 1.0, 0.0, 1.0); long x1DC, y1DC, x2DC, y2DC; Graphics_WCtoDC (my ps, 0.0, 0.0, & x1DC, & y2DC); Graphics_WCtoDC (my ps, 1.0, 1.0, & x2DC, & y1DC); long shift = (long) (Graphics_getResolution (my ps) * true_height_inches) + (y1DCold - y2DCold); Graphics_resetWsViewport (my ps, x1DC, x2DC, y1DC + shift, y2DC + shift); Graphics_setWsWindow (my ps, 0, width_inches, 0, height_inches); theCurrentPraatPicture -> x1NDC = 0; theCurrentPraatPicture -> x2NDC = width_inches; theCurrentPraatPicture -> y1NDC = 0; theCurrentPraatPicture -> y2NDC = height_inches; Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC); { // scope autoMelderProgressOff progress; autoMelderWarningOff warning; autoMelderSaveDefaultDir saveDir; if (! MelderDir_isNull (& my rootDirectory)) { Melder_setDefaultDir (& my rootDirectory); } try { Interpreter_run (interpreter, text); } catch (MelderError) { Melder_clearError (); } } Graphics_setLineType (my ps, Graphics_DRAWN); Graphics_setLineWidth (my ps, 1.0); Graphics_setArrowSize (my ps, 1.0); Graphics_setColour (my ps, Graphics_BLACK); theCurrentPraatApplication = & theForegroundPraatApplication; theCurrentPraatObjects = & theForegroundPraatObjects; theCurrentPraatPicture = & theForegroundPraatPicture; } Graphics_resetWsViewport (my ps, x1DCold, x2DCold, y1DCold, y2DCold); Graphics_setWsWindow (my ps, x1NDCold, x2NDCold, y1NDCold, y2NDCold); Graphics_setViewport (my ps, 0, 1, 0, 1); Graphics_setWindow (my ps, 0, 1, 0, 1); Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM); } my previousBottomSpacing = bottomSpacing; forget (interpreter); Melder_free (text); return 1; }
int HyperPage_any (I, const wchar_t *text, enum kGraphics_font font, int size, int style, double minFooterDistance, double x, double secondIndent, double topSpacing, double bottomSpacing, unsigned long method) { iam (HyperPage); double heightGuess; if (my rightMargin == 0) return 0; // Melder_assert (my rightMargin != 0); heightGuess = size * (1.2/72) * ((long) size * wcslen (text) / (int) (my rightMargin * 150)); if (! my printing) { Graphics_Link *paragraphLinks; int numberOfParagraphLinks, ilink; if (my entryHint && (method & HyperPage_USE_ENTRY_HINT) && wcsequ (text, my entryHint)) { my entryPosition = my d_y; } my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= size * (1.2/72); my d_x = x; if (/* my d_y > PAGE_HEIGHT + 2.0 + heightGuess || */ my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) { my d_y -= heightGuess; } else { Graphics_setFont (my g, font); Graphics_setFontSize (my g, size); Graphics_setWrapWidth (my g, my rightMargin - x - 0.1); Graphics_setSecondIndent (my g, secondIndent); Graphics_setFontStyle (my g, style); Graphics_text (my g, my d_x, my d_y, text); numberOfParagraphLinks = Graphics_getLinks (& paragraphLinks); if (my links) for (ilink = 1; ilink <= numberOfParagraphLinks; ilink ++) { HyperLink link = HyperLink_create (paragraphLinks [ilink]. name, paragraphLinks [ilink]. x1, paragraphLinks [ilink]. x2, paragraphLinks [ilink]. y1, paragraphLinks [ilink]. y2); Collection_addItem (my links, link); } if (method & HyperPage_ADD_BORDER) { Graphics_setLineWidth (my g, 2); Graphics_line (my g, 0.0, my d_y, my rightMargin, my d_y); Graphics_setLineWidth (my g, 1); } /* * The text may have wrapped. * Ask the Graphics manager by how much, and update our text position accordingly. */ my d_y = Graphics_inqTextY (my g); } } else { Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0; my d_y -= size * (1.2/72); if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance + size * (1.2/72) * (wcslen (text) / (6.0 * 10))) { Graphics_nextSheetOfPaper (my ps); if (my d_printingPageNumber) my d_printingPageNumber ++; HyperPage_initSheetOfPaper (me); Graphics_setFont (my ps, font); Graphics_setFontSize (my ps, size); my d_y -= size * (1.2/72); } my d_x = 0.7 + x; Graphics_setWrapWidth (my ps, 6.0 - x); Graphics_setSecondIndent (my ps, secondIndent); Graphics_setFontStyle (my ps, style); Graphics_text (my ps, my d_x, my d_y, text); if (method & HyperPage_ADD_BORDER) { Graphics_setLineWidth (my ps, 3); /*Graphics_line (my ps, 0.7, my d_y, 6.7, my d_y);*/ Graphics_line (my ps, 0.7, my d_y + size * (1.2/72) + 0.07, 6.7, my d_y + size * (1.2/72) + 0.07); Graphics_setLineWidth (my ps, 1); } my d_y = Graphics_inqTextY (my ps); } my previousBottomSpacing = bottomSpacing; return 1; }