Ticket #126: libview_fix_1_of_1_rev_d97ece7b69c3__126_Copy_to_workspace__same_thing_in_the_Inspector__this_line___becomes_invisible.patch

File libview_fix_1_of_1_rev_d97ece7b69c3__126_Copy_to_workspace__same_thing_in_the_Inspector__this_line___becomes_invisible.patch, 9.2 KB (added by patrik.svestka@…, 6 years ago)

the maximum display buffer adjusting for all font sizes.

  • DeviceWorkstation.st

    # HG changeset patch
    # User Patrik Svestka <patrik.svestka@gmail.com>
    # Date 1521448256 -3600
    #      Mon Mar 19 09:30:56 2018 +0100
    # Branch jv
    # Node ID d97ece7b69c3f98107c37e7c8cf8b4c07cee2e35
    # Parent  b99e94212cb56bdff4d5477249e5d46740a5305d
    #126 Copy to workspace (same thing in the Inspector) this line - becomes invisible
    
    diff -r b99e94212cb5 -r d97ece7b69c3 DeviceWorkstation.st
    a b  
    4242!
    4343
    4444Object subclass:#DeviceFontMetrics
    45         instanceVariableNames:'encoding ascent descent maxAscent maxDescent minWidth maxWidth
    46                 averageWidth minCode maxCode direction'
     45        instanceVariableNames:'ascent descent maxAscent maxDescent minWidth maxWidth
     46                averageWidth minCode maxCode direction encoding overHang'
    4747        classVariableNames:''
    4848        poolDictionaries:''
    4949        privateIn:DeviceWorkstation
     
    55785578    ^ info
    55795579!
    55805580
     5581fontDetailMetricsOf:fontId userInputString:aString
     5582    "return a average font Width and overHang for a specified character fonts metrics
     5583     info object"
     5584
     5585    |info|
     5586
     5587    info := DeviceWorkstation::DeviceFontMetrics new.
     5588    info
     5589      avgWidth:(self widthOf:aString inFont:fontId)
     5590      overHang:(self overHangOf:aString inFont:fontId).
     5591
     5592    ^ info
     5593!
     5594
    55815595fontResolutionOf:fontId
    55825596    "return the resolution (as dpiX @ dpiY) of the font - this is usually the displays resolution,
    55835597     but due to errors in some XServer installations, some use 75dpi fonts on higher
     
    58925906    "return the width in pixels of a string in a specific font"
    58935907
    58945908    ^ self widthOf:aString from:1 to:(aString size) inFont:aFontId
     5909!
     5910
     5911overHangOf:aString from:index1 to:index2 inFont:aFontId
     5912    "return the overHang in pixels of a substring in a specific font"
     5913
     5914    ^ self subclassResponsibility
     5915!
     5916
     5917overHangOf:aString inFont:aFontId
     5918    "return the overHang in pixels of a string in a specific font"
     5919
     5920    ^ self overHangOf:aString from:1 to:(aString size) inFont:aFontId
    58955921! !
    58965922
    58975923!DeviceWorkstation methodsFor:'grabbing'!
     
    84828508    encoding := encodingArg.
    84838509!
    84848510
    8485 averageWidth
    8486     "return the averageWidth"
    8487 
    8488     ^ averageWidth
     8511ascent:ascentArg descent:descentArg maxAscent:maxAscentArg maxDescent:maxDescentArg
     8512minWidth:minWidthArg maxWidth:maxWidthArg avgWidth:avgWidthArg minCode:minCodeArg maxCode:maxCodeArg
     8513direction:directionArg encoding:encodingArg overHang:overHangArg
     8514    "set corresponding instance variables"
     8515
     8516    ascent := ascentArg.
     8517    descent := descentArg.
     8518    maxAscent := maxAscentArg.
     8519    maxDescent := maxDescentArg.
     8520    minWidth := minWidthArg.
     8521    maxWidth := maxWidthArg.
     8522    averageWidth := avgWidthArg.
     8523    minCode := minCodeArg.
     8524    maxCode := maxCodeArg.
     8525    direction := directionArg.
     8526    encoding := encodingArg.
     8527    overHang := overHangArg.
    84898528!
    84908529
    84918530descent
     
    84948533    ^ descent
    84958534!
    84968535
     8536maxAscent
     8537    "return the maxAscent"
     8538
     8539    ^ maxAscent
     8540!
     8541
     8542maxDescent
     8543    "return the maxDescent"
     8544
     8545    ^ maxDescent
     8546!
     8547
     8548minWidth
     8549    "return the minWidth"
     8550
     8551    ^ minWidth
     8552!
     8553
     8554maxWidth
     8555    "return the maxWidth"
     8556
     8557    ^ maxWidth
     8558!
     8559
     8560averageWidth
     8561    "return the averageWidth"
     8562
     8563    ^ averageWidth
     8564!
     8565
     8566minCode
     8567    ^ minCode ? 0
     8568!
     8569
     8570maxCode
     8571    ^ maxCode ? 16rFFFF
     8572!
     8573
    84978574direction
    84988575    "return the drawing direction (think of hebrew and arabic !!)"
    84998576
     
    85068583    ^ encoding
    85078584!
    85088585
    8509 maxAscent
    8510     "return the maxAscent"
    8511 
    8512     ^ maxAscent
    8513 !
    8514 
    8515 maxCode
    8516     ^ maxCode ? 16rFFFF
    8517 !
    8518 
    8519 maxDescent
    8520     "return the maxDescent"
    8521 
    8522     ^ maxDescent
    8523 !
    8524 
    8525 maxWidth
    8526     "return the maxWidth"
    8527 
    8528     ^ maxWidth
    8529 !
    8530 
    8531 minCode
    8532     ^ minCode ? 0
    8533 !
    8534 
    8535 minWidth
    8536     "return the minWidth"
    8537 
    8538     ^ minWidth
     8586overHang
     8587    "return font the overHang"
     8588
     8589    ^ overHang
    85398590! !
    85408591
    85418592!DeviceWorkstation class methodsFor:'documentation'!
  • WinWorkstation.st

    diff -r b99e94212cb5 -r d97ece7b69c3 WinWorkstation.st
    a b  
    170170#include <stdlib.h>
    171171#include <stdio.h>
    172172#include <errno.h>
     173#include <assert.h>
    173174/* #include <malloc.h> */
    174175/* #include <math.h> */
    175176/* #include <string.h> */
     
    1077310774
    1077410775    unsigned char *cp;
    1077510776    OBJ cls;
    10776     int i1, i2, n, l, toDisplay;
     10777    SIZE size;
     10778    TEXTMETRICW tmet;
     10779    short maxDisplayBuffer;
     10780    int i1, i2, n, l, getMetricsResult, avgWidth, toDisplay;
    1077710781    int nInstBytes;
    1077810782
    1077910783
     
    1078710791        HDC hDC;
    1078810792        HFONT hOldFont;
    1078910793
    10790         /* Windows (as in 7 or newer) limits the string size for TextOut* to 3275 */
    10791         const int MAX_DISPLAY_BUFFER = 3275;
     10794        /* Windows (as in 7 or newer) limits the string size for TextOut* changes
     10795  according to the font size!  There is apparently an undocumented limit to
     10796  the overall raster size.  The maximum value for the raster size is 16384. */
     10797
     10798
     10799  // GetTextMetricsW gives all needed font metrics
     10800  // If for any reason it does not work there is a fallback
     10801  if (GetTextMetricsW(__tmpDC, &tmet)) {
     10802      avgWidth = tmet.tmAveCharWidth;
     10803  } else {
     10804      static char *s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzコーヒーアイスクリームケーキビールすしかき";
     10805      static int len;
     10806
     10807      if (len == 0) {
     10808          len = strlen(s);
     10809      }
     10810      assert(GetTextExtentPoint32(__tmpDC, s, len, &size) != 0 && "GetTextExtentPoint32 != 0, fix me");
     10811      avgWidth = (size.cx / (len / 2) + 1) / 2;
     10812  }
     10813
     10814  // Calculate the maximum buffer size for the selected font size
     10815  maxDisplayBuffer = 16384 / (avgWidth + tmet.tmOverhang);
    1079210816
    1079310817        i1 = __intVal(index1) - 1;
    1079410818        i2 = __intVal(index2) - 1;
     
    1084110865                cp += i1;
    1084210866                do {
    1084310867                    /* TA_UPDATECP used => pX, pY ignored */
    10844                     if (! TextOutA(hDC, 0, 0, (char *)cp, MIN(toDisplay, MAX_DISPLAY_BUFFER))) {
     10868                    if (! TextOutA(hDC, 0, 0, (char *)cp, MIN(toDisplay, maxDisplayBuffer))) {
    1084510869                        PRINTF(("WinWorkstation [warning]: TextOutA failed. [%d]\n", __LINE__));
    1084610870                        PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d leftToShow=%d\n", GetLastError(), pX, pY, l, toDisplay));
    1084710871                        goto error;
    1084810872                    }
    10849                     cp += MAX_DISPLAY_BUFFER;
    10850                     toDisplay -= MAX_DISPLAY_BUFFER;
     10873                    cp += maxDisplayBuffer;
     10874                    toDisplay -= maxDisplayBuffer;
    1085110875                } while(toDisplay > 0);
    1085210876            }
    1085310877            goto ret;
     
    1086910893                w_cp += i1;
    1087010894                do {
    1087110895                    /* TA_UPDATECP used => pX, pY ignored */
    10872                     if (! TextOutW(hDC, 0, 0, w_cp, MIN(toDisplay, MAX_DISPLAY_BUFFER))) {
     10896                    if (! TextOutW(hDC, 0, 0, w_cp, MIN(toDisplay, maxDisplayBuffer))) {
    1087310897                        PRINTF(("WinWorkstation [warning]: TextOutW failed. [%d]\n", __LINE__));
    1087410898                        PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d leftToShow=%d\n", GetLastError(), pX, pY, l, toDisplay));
    1087510899                        goto error;
    1087610900                    }
    10877                     w_cp += MAX_DISPLAY_BUFFER;
    10878                     toDisplay -= MAX_DISPLAY_BUFFER;
     10901                    w_cp += maxDisplayBuffer;
     10902                    toDisplay -= maxDisplayBuffer;
    1087910903                } while (toDisplay > 0);
    1088010904            }
    1088110905            goto ret;
     
    1327013294      minCode:(rawData at:8)
    1327113295      maxCode:16rFFFF "(rawData at:9)"
    1327213296      direction:nil
    13273       encoding:(rawData at:11).
     13297      encoding:(rawData at:11)
     13298      overHang:(rawData at:12).
    1327413299    ^ info
    1327513300!
    1327613301
    1327713302fontsInFamily:aFamilyName face:aFaceName filtering:filter
    1327813303    "return a set of all available fonts in aFamily/aFace on this display.
    13279      On WinWorkStations there is curently Face
    13280      But only thise matching filter (if nonNil)."
     13304     On WinWorkStations there is currently Face
     13305     But only these matching filter (if nonNil)."
    1328113306
    1328213307    |allFonts fonts|
    1328313308
     
    1377713802      maxDescent -> (data at:4)
    1377813803      minWidth   -> (data at:5)
    1377913804      maxWidth   -> (data at:6)
    13780       avgWidth   -> (data at:7).
    13781       minChar    -> (data at:8).
    13782       maxChar    -> (data at:9).
    13783       defaultChar-> (data at:10).
    13784       charSet    -> (data at:11).
     13805      avgWidth   -> (data at:7)
     13806      minChar    -> (data at:8)
     13807      maxChar    -> (data at:9)
     13808      defaultChar-> (data at:10)
     13809      charSet    -> (data at:11)
     13810      overHang   -> (data at:12)
    1378513811"
    1378613812
    1378713813%{
     
    1381913845            static int len;
    1382013846
    1382113847            if (len == 0) {
    13822                 len = strlen(s);
     13848                len = strlen(s);
    1382313849            }
    1382413850            GetTextExtentPoint32(__tmpDC, s, len, &size);
    1382513851            avgWidth = (size.cx / (len / 2) + 1) / 2;
     
    1384413870        __ArrayInstPtr(rawData)->a_element[9] = __MKSMALLINT(tmet.tmDefaultChar);   /* default    -> (data at:10) */
    1384513871        t = __charSetSymbolFor(tmet.tmCharSet);
    1384613872        __ArrayInstPtr(rawData)->a_element[10]= t; __STORE(rawData, t);             /* charSet    -> (data at:11) */
    13847 
    13848         DPRINTF(("textMetrics h=%x  avgAsc=%d avgDesc=%d minW=%d maxW=%d avgW=%d\n",
     13873  __ArrayInstPtr(rawData)->a_element[11]= __MKSMALLINT(tmet.tmOverhang);      /* overHang   -> (data at:12) */
     13874
     13875        DPRINTF(("textMetrics h=%x  avgAsc=%d avgDesc=%d minW=%d maxW=%d avgW=%d overHang=%d\n",
    1384913876                    hFont, tmet.tmAscent, tmet.tmDescent, avgWidth, tmet.tmMaxCharWidth,
    13850                     tmet.tmAveCharWidth));
     13877                    tmet.tmAveCharWidth, tmet.tmOverhang));
    1385113878        RETURN (self);
    1385213879    }
    1385313880    RETURN (nil);