void Transition_drawAsNumbers (I, Graphics g, int iformat, int precision) { iam (Transition); double maxTextWidth = 0, maxTextHeight = 0; Graphics_setInner (g); Graphics_setWindow (g, 0.5, my numberOfStates + 0.5, 0, 1); double leftMargin = Graphics_dxMMtoWC (g, 1); double lineSpacing = Graphics_dyMMtoWC (g, 1.5 * Graphics_inqFontSize (g) * 25.4 / 72); Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_BOTTOM); for (long col = 1; col <= my numberOfStates; col ++) { if (my stateLabels && my stateLabels [col] && my stateLabels [col] [0]) { Graphics_text (g, col, 1, my stateLabels [col]); if (! maxTextHeight) maxTextHeight = lineSpacing; } } for (long row = 1; row <= my numberOfStates; row ++) { double y = 1 - lineSpacing * (row - 1 + 0.7); Graphics_setTextAlignment (g, Graphics_RIGHT, Graphics_HALF); if (my stateLabels && my stateLabels [row]) { double textWidth = Graphics_textWidth (g, my stateLabels [row]); if (textWidth > maxTextWidth) maxTextWidth = textWidth; Graphics_text (g, 0.5 - leftMargin, y, my stateLabels [row]); } Graphics_setTextAlignment (g, Graphics_CENTRE, Graphics_HALF); for (long col = 1; col <= my numberOfStates; col ++) { wchar text [40]; print4 (text, my data [row] [col], iformat, 0, precision); Graphics_text (g, col, y, text); } } if (maxTextWidth) Graphics_line (g, 0.5 - maxTextWidth - leftMargin, 1, my numberOfStates + 0.5, 1); if (maxTextHeight) Graphics_line (g, 0.5, 1 + maxTextHeight, 0.5, 1 - lineSpacing * (my numberOfStates + 0.2)); Graphics_unsetInner (g); }
void structTableEditor :: v_draw () { Table table = static_cast<Table> (data); double spacing = 2.0; // millimetres at both edges double columnWidth, cellWidth; /* * We fit 200 rows in 40 inches, which is 14.4 points per row. */ long rowmin = topRow, rowmax = rowmin + 197; long colmin = leftColumn, colmax = colmin + (kTableEditor_MAXNUM_VISIBLE_COLUMNS - 1); if (rowmax > table -> rows.size) rowmax = table -> rows.size; if (colmax > table -> numberOfColumns) colmax = table -> numberOfColumns; Graphics_clearWs (graphics.get()); Graphics_setTextAlignment (graphics.get(), Graphics_CENTRE, Graphics_HALF); Graphics_setWindow (graphics.get(), 0.0, 1.0, rowmin + 197.5, rowmin - 2.5); Graphics_setColour (graphics.get(), Graphics_SILVER); Graphics_fillRectangle (graphics.get(), 0.0, 1.0, rowmin - 2.5, rowmin - 0.5); Graphics_setColour (graphics.get(), Graphics_BLACK); Graphics_line (graphics.get(), 0.0, rowmin - 0.5, 1.0, rowmin - 0.5); Graphics_setWindow (graphics.get(), 0.0, Graphics_dxWCtoMM (graphics.get(), 1.0), rowmin + 197.5, rowmin - 2.5); /* * Determine the width of the column with the row numbers. */ columnWidth = Graphics_textWidth (graphics.get(), U"row"); for (long irow = rowmin; irow <= rowmax; irow ++) { cellWidth = Graphics_textWidth (graphics.get(), Melder_integer (irow)); if (cellWidth > columnWidth) columnWidth = cellWidth; } columnLeft [0] = columnWidth + 2 * spacing; Graphics_setColour (graphics.get(), Graphics_SILVER); Graphics_fillRectangle (graphics.get(), 0.0, columnLeft [0], rowmin - 0.5, rowmin + 197.5); Graphics_setColour (graphics.get(), Graphics_BLACK); Graphics_line (graphics.get(), columnLeft [0], rowmin - 0.5, columnLeft [0], rowmin + 197.5); /* * Determine the width of the columns. */ for (long icol = colmin; icol <= colmax; icol ++) { const char32 *columnLabel = table -> columnHeaders [icol]. label; columnWidth = Graphics_textWidth (graphics.get(), Melder_integer (icol)); if (! columnLabel) columnLabel = U""; cellWidth = Graphics_textWidth (graphics.get(), columnLabel); if (cellWidth > columnWidth) columnWidth = cellWidth; for (long irow = rowmin; irow <= rowmax; irow ++) { const char32 *cell = Table_getStringValue_Assert (table, irow, icol); Melder_assert (cell); if (cell [0] == U'\0') cell = U"?"; cellWidth = Graphics_textWidth (graphics.get(), cell); if (cellWidth > columnWidth) columnWidth = cellWidth; } columnRight [icol - colmin] = columnLeft [icol - colmin] + columnWidth + 2 * spacing; if (icol < colmax) columnLeft [icol - colmin + 1] = columnRight [icol - colmin]; } /* Text can be "graphic" or not. */ Graphics_setPercentSignIsItalic (our graphics.get(), our p_useTextStyles); Graphics_setNumberSignIsBold (our graphics.get(), our p_useTextStyles); Graphics_setCircumflexIsSuperscript (our graphics.get(), our p_useTextStyles); Graphics_setUnderscoreIsSubscript (our graphics.get(), our p_useTextStyles); /* * Show the row numbers. */ Graphics_text (graphics.get(), columnLeft [0] / 2, rowmin - 1, U"row"); for (long irow = rowmin; irow <= rowmax; irow ++) { Graphics_text (graphics.get(), columnLeft [0] / 2, irow, irow); } /* * Show the column labels. */ for (long icol = colmin; icol <= colmax; icol ++) { double mid = (columnLeft [icol - colmin] + columnRight [icol - colmin]) / 2; const char32 *columnLabel = table -> columnHeaders [icol]. label; if (! columnLabel || columnLabel [0] == U'\0') columnLabel = U"?"; Graphics_text (graphics.get(), mid, rowmin - 2, icol); Graphics_text (graphics.get(), mid, rowmin - 1, columnLabel); } /* * Show the cell contents. */ for (long irow = rowmin; irow <= rowmax; irow ++) { for (long icol = colmin; icol <= colmax; icol ++) { double mid = (columnLeft [icol - colmin] + columnRight [icol - colmin]) / 2; const char32 *cell = Table_getStringValue_Assert (table, irow, icol); Melder_assert (cell); if (cell [0] == U'\0') cell = U"?"; Graphics_text (graphics.get(), mid, irow, cell); } } }