comparison src/hardcopy.c @ 31667:b89cfd86e18e v9.0.1166

patch 9.0.1166: code is indented more than necessary Commit: https://github.com/vim/vim/commit/1cfb14aa972ccf3235ac67f07b7db1175b7c5384 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Jan 9 19:04:23 2023 +0000 patch 9.0.1166: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11792)
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Jan 2023 20:15:03 +0100
parents 9716c7d24c12
children ca6bc7c04163
comparison
equal deleted inserted replaced
31666:feb8dcde5ff2 31667:b89cfd86e18e
332 #endif // FEAT_SYN_HL 332 #endif // FEAT_SYN_HL
333 333
334 static void 334 static void
335 prt_set_fg(long_u fg) 335 prt_set_fg(long_u fg)
336 { 336 {
337 if (fg != curr_fg) 337 if (fg == curr_fg)
338 { 338 return;
339 curr_fg = fg; 339
340 mch_print_set_fg(fg); 340 curr_fg = fg;
341 } 341 mch_print_set_fg(fg);
342 } 342 }
343 343
344 static void 344 static void
345 prt_set_bg(long_u bg) 345 prt_set_bg(long_u bg)
346 { 346 {
347 if (bg != curr_bg) 347 if (bg == curr_bg)
348 { 348 return;
349 curr_bg = bg; 349
350 mch_print_set_bg(bg); 350 curr_bg = bg;
351 } 351 mch_print_set_bg(bg);
352 } 352 }
353 353
354 static void 354 static void
355 prt_set_font(int bold, int italic, int underline) 355 prt_set_font(int bold, int italic, int underline)
356 { 356 {
357 if (curr_bold != bold 357 if (curr_bold == bold
358 || curr_italic != italic 358 && curr_italic == italic
359 || curr_underline != underline) 359 && curr_underline == underline)
360 { 360 return;
361 curr_underline = underline; 361
362 curr_italic = italic; 362 curr_underline = underline;
363 curr_bold = bold; 363 curr_italic = italic;
364 mch_print_set_font(bold, italic, underline); 364 curr_bold = bold;
365 } 365 mch_print_set_font(bold, italic, underline);
366 } 366 }
367 367
368 /* 368 /*
369 * Print the line number in the left margin. 369 * Print the line number in the left margin.
370 */ 370 */
432 { 432 {
433 int u = PRT_UNIT_NONE; 433 int u = PRT_UNIT_NONE;
434 int i; 434 int i;
435 static char *(units[4]) = PRT_UNIT_NAMES; 435 static char *(units[4]) = PRT_UNIT_NAMES;
436 436
437 if (printer_opts[idx].present) 437 if (!printer_opts[idx].present)
438 for (i = 0; i < 4; ++i) 438 return PRT_UNIT_NONE;
439 if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0) 439
440 { 440 for (i = 0; i < 4; ++i)
441 u = i; 441 if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0)
442 break; 442 {
443 } 443 u = i;
444 break;
445 }
444 return u; 446 return u;
445 } 447 }
446 448
447 /* 449 /*
448 * Print the page header. 450 * Print the page header.
1572 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0)) 1574 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0))
1573 1575
1574 static void 1576 static void
1575 prt_flush_buffer(void) 1577 prt_flush_buffer(void)
1576 { 1578 {
1577 if (prt_ps_buffer.ga_len > 0) 1579 if (prt_ps_buffer.ga_len <= 0)
1578 { 1580 return;
1579 // Any background color must be drawn first 1581
1580 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) 1582 // Any background color must be drawn first
1581 { 1583 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE))
1582 int r, g, b; 1584 {
1583 1585 int r, g, b;
1584 if (prt_do_moveto) 1586
1585 {
1586 prt_write_real(prt_pos_x_moveto, 2);
1587 prt_write_real(prt_pos_y_moveto, 2);
1588 prt_write_string("m\n");
1589 prt_do_moveto = FALSE;
1590 }
1591
1592 // Size of rect of background color on which text is printed
1593 prt_write_real(prt_text_run, 2);
1594 prt_write_real(prt_line_height, 2);
1595
1596 // Lastly add the color of the background
1597 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16;
1598 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8;
1599 b = prt_new_bgcol & 0xff;
1600 prt_write_real(r / 255.0, 3);
1601 prt_write_real(g / 255.0, 3);
1602 prt_write_real(b / 255.0, 3);
1603 prt_write_string("bg\n");
1604 }
1605 // Draw underlines before the text as it makes it slightly easier to
1606 // find the starting point.
1607 if (prt_do_underline)
1608 {
1609 if (prt_do_moveto)
1610 {
1611 prt_write_real(prt_pos_x_moveto, 2);
1612 prt_write_real(prt_pos_y_moveto, 2);
1613 prt_write_string("m\n");
1614 prt_do_moveto = FALSE;
1615 }
1616
1617 // Underline length of text run
1618 prt_write_real(prt_text_run, 2);
1619 prt_write_string("ul\n");
1620 }
1621 // Draw the text
1622 if (prt_out_mbyte)
1623 prt_write_string("<");
1624 else
1625 prt_write_string("(");
1626 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len);
1627 if (prt_out_mbyte)
1628 prt_write_string(">");
1629 else
1630 prt_write_string(")");
1631 // Add a moveto if need be and use the appropriate show procedure
1632 if (prt_do_moveto) 1587 if (prt_do_moveto)
1633 { 1588 {
1634 prt_write_real(prt_pos_x_moveto, 2); 1589 prt_write_real(prt_pos_x_moveto, 2);
1635 prt_write_real(prt_pos_y_moveto, 2); 1590 prt_write_real(prt_pos_y_moveto, 2);
1636 // moveto and a show 1591 prt_write_string("m\n");
1637 prt_write_string("ms\n");
1638 prt_do_moveto = FALSE; 1592 prt_do_moveto = FALSE;
1639 } 1593 }
1640 else // Simple show 1594
1641 prt_write_string("s\n"); 1595 // Size of rect of background color on which text is printed
1642 1596 prt_write_real(prt_text_run, 2);
1643 ga_clear(&prt_ps_buffer); 1597 prt_write_real(prt_line_height, 2);
1644 ga_init2(&prt_ps_buffer, sizeof(char), prt_bufsiz); 1598
1645 } 1599 // Lastly add the color of the background
1600 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16;
1601 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8;
1602 b = prt_new_bgcol & 0xff;
1603 prt_write_real(r / 255.0, 3);
1604 prt_write_real(g / 255.0, 3);
1605 prt_write_real(b / 255.0, 3);
1606 prt_write_string("bg\n");
1607 }
1608 // Draw underlines before the text as it makes it slightly easier to
1609 // find the starting point.
1610 if (prt_do_underline)
1611 {
1612 if (prt_do_moveto)
1613 {
1614 prt_write_real(prt_pos_x_moveto, 2);
1615 prt_write_real(prt_pos_y_moveto, 2);
1616 prt_write_string("m\n");
1617 prt_do_moveto = FALSE;
1618 }
1619
1620 // Underline length of text run
1621 prt_write_real(prt_text_run, 2);
1622 prt_write_string("ul\n");
1623 }
1624 // Draw the text
1625 if (prt_out_mbyte)
1626 prt_write_string("<");
1627 else
1628 prt_write_string("(");
1629 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len);
1630 if (prt_out_mbyte)
1631 prt_write_string(">");
1632 else
1633 prt_write_string(")");
1634 // Add a moveto if need be and use the appropriate show procedure
1635 if (prt_do_moveto)
1636 {
1637 prt_write_real(prt_pos_x_moveto, 2);
1638 prt_write_real(prt_pos_y_moveto, 2);
1639 // moveto and a show
1640 prt_write_string("ms\n");
1641 prt_do_moveto = FALSE;
1642 }
1643 else // Simple show
1644 prt_write_string("s\n");
1645
1646 ga_clear(&prt_ps_buffer);
1647 ga_init2(&prt_ps_buffer, sizeof(char), prt_bufsiz);
1646 } 1648 }
1647 1649
1648 1650
1649 static void 1651 static void
1650 prt_resource_name(char_u *filename, void *cookie) 1652 prt_resource_name(char_u *filename, void *cookie)
3445 } 3447 }
3446 3448
3447 void 3449 void
3448 mch_print_set_fg(long_u fgcol) 3450 mch_print_set_fg(long_u fgcol)
3449 { 3451 {
3450 if (fgcol != (long_u)prt_fgcol) 3452 if (fgcol == (long_u)prt_fgcol)
3451 { 3453 return;
3452 prt_fgcol = (int)fgcol; 3454
3453 prt_attribute_change = TRUE; 3455 prt_fgcol = (int)fgcol;
3454 prt_need_fgcol = TRUE; 3456 prt_attribute_change = TRUE;
3455 } 3457 prt_need_fgcol = TRUE;
3456 } 3458 }
3457 3459
3458 # endif //FEAT_POSTSCRIPT 3460 # endif //FEAT_POSTSCRIPT
3459 #endif //FEAT_PRINTER 3461 #endif //FEAT_PRINTER