Ticket #126: libview_fix_1_of_1_rev_96a744e08e25_Issue__126__Removing_hack__correctly_calculating_masDisplayBuffer_and_having_fallback_maxDisplayBuffer_is_set_to_107_characters_.patch

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

A patch containing all the changes in one file - hopefully last patch

  • Depth16Image.st

    # HG changeset patch
    # User Patrik Svestka <patrik.svestka@gmail.com>
    # Date 1531321109 -7200
    #      Wed Jul 11 16:58:29 2018 +0200
    # Branch jv
    # Node ID 96a744e08e254618e8379227ece61aa370ac44b9
    # Parent  86cba794dee3702290fd51dc382300ceb241d54c
    Issue #126: Removing hack, correctly calculating masDisplayBuffer and having fallback maxDisplayBuffer is set to 107 characters.
    
    On windows (7 and up) there is undocumented, you can't find this information anywhere, limit for raster size when using TextOutA or TextOutW.
    Experimentally, I have come to the conclusion that the limit is most likely set to 16384 points of the raster.
    
    To correctly calculate the maximum display buffer (maxDisplayBuffer) I have come to a formula:
    maxDisplayBuffer = 16384 / (maxWidth + tmet.tmOverhang);
    
    maxWidth is the maximum selected font width
    tmet.tmOverhang is the "extra width per string that may be added to some synthesized fonts." -> If you want to get the actual width you have to add it to maxWidth. You will get the whole extent then. (For most fonts tmOverhang will be 0.)
    
    The whole definition of tmOverhang from MSND - https://msdn.microsoft.com/en-us/library/windows/desktop/dd145132(v=vs.85).aspx
    
    diff -r 86cba794dee3 -r 96a744e08e25 Depth16Image.st
    a b  
    11"
    22 COPYRIGHT (c) 1995 by Claus Gittinger
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    204205    "return the number of bytes in one scanline of the image"
    205206
    206207    ^ width * 2.
     208!
     209
     210isDepth16Image
     211    "return true if the image is instance of Depth16Image"
     212   (self bitsPerPixel == 16) ifTrue:[^ true]. 
     213    ^ false
     214
     215    "Created: / 16-04-2018 / 16:59:55 / svestkap"
    207216! !
    208217
    209218!Depth16Image class methodsFor:'documentation'!
     
    214223
    215224version_CVS
    216225    ^ '$Header$'
     226!
     227
     228version_HG
     229
     230    ^ '$Changeset: <not expanded> $'
    217231! !
    218232
  • Depth1Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth1Image.st
    a b  
    11"
    22 COPYRIGHT (c) 1993 by Claus Gittinger
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    683684    ^ super colorFromValue:pixelValue.
    684685!
    685686
     687isDepth1Image
     688    "return true if the image is instance of Depth1Image"
     689   (self bitsPerPixel == 1) ifTrue:[^ true]. 
     690    ^ false
     691
     692    "Created: / 16-04-2018 / 17:02:34 / svestkap"
     693!
     694
    686695rgbFromValue:pixelValue
    687696    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
    688697     Pixel values start with 0."
  • Depth24Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth24Image.st
    a b  
    22
    33"
    44 COPYRIGHT (c) 1993 by Claus Gittinger
     5 COPYRIGHT (c) 2018 Patrik Svestka
    56              All Rights Reserved
    67
    78 This software is furnished under a license and may be used
     
    33523353    ^ -8
    33533354!
    33543355
     3356isDepth24Image
     3357    "return true if the image is instance of Depth24Image"
     3358   (self bitsPerPixel == 24) ifTrue:[^ true]. 
     3359    ^ false
     3360
     3361    "Created: / 16-04-2018 / 16:53:00 / svestkap"
     3362!
     3363
    33553364redBitsOf:pixel
    33563365    "given a pixel-value, return the red component as byteValue (0..255)"
    33573366
  • Depth2Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth2Image.st
    a b  
    11"
    22 COPYRIGHT (c) 1993 by Claus Gittinger
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    968969    ^ super colorFromValue:colorValue.
    969970!
    970971
     972isDepth2Image
     973    "return true if the image is instance of Depth2Image"
     974   (self bitsPerPixel == 2) ifTrue:[^ true]. 
     975    ^ false
     976
     977    "Created: / 16-04-2018 / 17:02:16 / svestkap"
     978!
     979
    971980usedColors
    972981    "return a collection of colors used in the receiver.
    973982     For depth2 images, we return the colorMap here, assuming all
  • Depth32Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth32Image.st
    a b  
    11"
    22 COPYRIGHT (c) 1995 by Claus Gittinger
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34 COPYRIGHT (c) 2016 Jan Vrany
    45              All Rights Reserved
    56
     
    10801081    ^ true
    10811082!
    10821083
     1084isDepth32Image
     1085    "return true if the image is instance of Depth32Image"
     1086   (self bitsPerPixel == 32) ifTrue:[^ true]. 
     1087    ^ false
     1088
     1089    "Created: / 16-04-2018 / 17:00:39 / svestkap"
     1090!
     1091
    10831092redBitsOf:pixel
    10841093    "given a pixel-value, return the red component as byteValue (0..255)"
    10851094
  • Depth48Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth48Image.st
    a b  
    11"
    22 COPYRIGHT (c) 2009 by eXept Software AG
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    134135    "return the number of bytes in one scanline of the image"
    135136
    136137    ^ width * 6.
     138!
     139
     140isDepth48Image
     141    "return true if the image is instance of Depth48Image"
     142   (self bitsPerPixel == 48) ifTrue:[^ true]. 
     143    ^ false
     144
     145    "Created: / 16-04-2018 / 17:02:03 / svestkap"
    137146! !
    138147
    139148!Depth48Image class methodsFor:'documentation'!
    140149
    141150version
    142151    ^ '$Header$'
     152!
     153
     154version_HG
     155
     156    ^ '$Changeset: <not expanded> $'
    143157! !
    144158
  • Depth4Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth4Image.st
    a b  
    11"
    22 COPYRIGHT (c) 1993 by Claus Gittinger
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    10241025    ^ super colorFromValue:pixelValue
    10251026!
    10261027
     1028isDepth4Image
     1029    "return true if the image is instance of Depth4Image"
     1030   (self bitsPerPixel == 4) ifTrue:[^ true]. 
     1031    ^ false
     1032
     1033    "Created: / 16-04-2018 / 17:01:45 / svestkap"
     1034!
     1035
    10271036usedValues
    10281037    "return a collection of color values used in the receiver."
    10291038
  • Depth64Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth64Image.st
    a b  
    11"
    22 COPYRIGHT (c) 2009 by eXept Software AG
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    140141
    141142hasAlphaChannel
    142143    ^ true
     144!
     145
     146isDepth64Image
     147    "return true if the image is instance of Depth64Image"
     148   (self bitsPerPixel == 64) ifTrue:[^ true]. 
     149    ^ false
     150
     151    "Created: / 16-04-2018 / 17:01:31 / svestkap"
    143152! !
    144153
    145154!Depth64Image class methodsFor:'documentation'!
  • Depth8Image.st

    diff -r 86cba794dee3 -r 96a744e08e25 Depth8Image.st
    a b  
    22
    33"
    44 COPYRIGHT (c) 1993 by Claus Gittinger
     5 COPYRIGHT (c) 2018 Patrik Svestka
    56              All Rights Reserved
    67
    78 This software is furnished under a license and may be used
     
    25862587    ^ super colorFromValue:pixelValue
    25872588!
    25882589
     2590isDepth8Image
     2591    "return true if the image is instance of Depth8Image"
     2592   (self bitsPerPixel == 8) ifTrue:[^ true]. 
     2593    ^ false
     2594
     2595    "Created: / 16-04-2018 / 17:01:10 / svestkap"
     2596!
     2597
    25892598nColorsUsed
    25902599    ^ colorMap size
    25912600!
  • DeviceWorkstation.st

    diff -r 86cba794dee3 -r 96a744e08e25 DeviceWorkstation.st
    a b  
    11"
    22COPYRIGHT (c) 1993 by Claus Gittinger
    33COPYRIGHT (c) 2016-2017 Jan Vrany
     4COPYRIGHT (c) 2018 Patrik Svestka
    45              All Rights Reserved
    56
    67 This software is furnished under a license and may be used
     
    4344!
    4445
    4546Object subclass:#DeviceFontMetrics
    46         instanceVariableNames:'encoding ascent descent maxAscent maxDescent minWidth maxWidth
    47                 averageWidth minCode maxCode direction'
     47        instanceVariableNames:'ascent descent maxAscent maxDescent minWidth maxWidth
     48                averageWidth minCode maxCode direction encoding overHang'
    4849        classVariableNames:''
    4950        poolDictionaries:''
    5051        privateIn:DeviceWorkstation
     
    5657"
    5758COPYRIGHT (c) 1993 by Claus Gittinger
    5859COPYRIGHT (c) 2016-2017 Jan Vrany
     60COPYRIGHT (c) 2018 Patrik Svestka
    5961              All Rights Reserved
    6062
    6163 This software is furnished under a license and may be used
     
    55805582    ^ info
    55815583!
    55825584
     5585fontDetailMetricsOf:fontId userInputString:aString
     5586    "return a average font Width and overHang for a specified character fonts metrics
     5587     info object"
     5588
     5589    |info|
     5590
     5591    info := DeviceWorkstation::DeviceFontMetrics new.
     5592    info
     5593      avgWidth:(self widthOf:aString inFont:fontId)
     5594      overHang:(self overHangOf:aString inFont:fontId).
     5595
     5596    ^ info
     5597!
     5598
    55835599fontResolutionOf:fontId
    55845600    "return the resolution (as dpiX @ dpiY) of the font - this is usually the displays resolution,
    55855601     but due to errors in some XServer installations, some use 75dpi fonts on higher
     
    58945910    "return the width in pixels of a string in a specific font"
    58955911
    58965912    ^ self widthOf:aString from:1 to:(aString size) inFont:aFontId
     5913!
     5914
     5915overHangOf:aString from:index1 to:index2 inFont:aFontId
     5916    "return the overHang in pixels of a substring in a specific font"
     5917
     5918    ^ self subclassResponsibility
     5919!
     5920
     5921overHangOf:aString inFont:aFontId
     5922    "return the overHang in pixels of a string in a specific font"
     5923
     5924    ^ self overHangOf:aString from:1 to:(aString size) inFont:aFontId
    58975925! !
    58985926
    58995927!DeviceWorkstation methodsFor:'grabbing'!
     
    84848512    encoding := encodingArg.
    84858513!
    84868514
    8487 averageWidth
    8488     "return the averageWidth"
    8489 
    8490     ^ averageWidth
     8515ascent:ascentArg descent:descentArg maxAscent:maxAscentArg maxDescent:maxDescentArg
     8516minWidth:minWidthArg maxWidth:maxWidthArg avgWidth:avgWidthArg minCode:minCodeArg maxCode:maxCodeArg
     8517direction:directionArg encoding:encodingArg overHang:overHangArg
     8518    "set corresponding instance variables"
     8519
     8520    ascent := ascentArg.
     8521    descent := descentArg.
     8522    maxAscent := maxAscentArg.
     8523    maxDescent := maxDescentArg.
     8524    minWidth := minWidthArg.
     8525    maxWidth := maxWidthArg.
     8526    averageWidth := avgWidthArg.
     8527    minCode := minCodeArg.
     8528    maxCode := maxCodeArg.
     8529    direction := directionArg.
     8530    encoding := encodingArg.
     8531    overHang := overHangArg.
    84918532!
    84928533
    84938534descent
     
    84968537    ^ descent
    84978538!
    84988539
     8540maxAscent
     8541    "return the maxAscent"
     8542
     8543    ^ maxAscent
     8544!
     8545
     8546maxDescent
     8547    "return the maxDescent"
     8548
     8549    ^ maxDescent
     8550!
     8551
     8552minWidth
     8553    "return the minWidth"
     8554
     8555    ^ minWidth
     8556!
     8557
     8558maxWidth
     8559    "return the maxWidth"
     8560
     8561    ^ maxWidth
     8562!
     8563
     8564averageWidth
     8565    "return the averageWidth"
     8566
     8567    ^ averageWidth
     8568!
     8569
     8570minCode
     8571    ^ minCode ? 0
     8572!
     8573
     8574maxCode
     8575    ^ maxCode ? 16rFFFF
     8576!
     8577
    84998578direction
    85008579    "return the drawing direction (think of hebrew and arabic !!)"
    85018580
     
    85088587    ^ encoding
    85098588!
    85108589
    8511 maxAscent
    8512     "return the maxAscent"
    8513 
    8514     ^ maxAscent
    8515 !
    8516 
    8517 maxCode
    8518     ^ maxCode ? 16rFFFF
    8519 !
    8520 
    8521 maxDescent
    8522     "return the maxDescent"
    8523 
    8524     ^ maxDescent
    8525 !
    8526 
    8527 maxWidth
    8528     "return the maxWidth"
    8529 
    8530     ^ maxWidth
    8531 !
    8532 
    8533 minCode
    8534     ^ minCode ? 0
    8535 !
    8536 
    8537 minWidth
    8538     "return the minWidth"
    8539 
    8540     ^ minWidth
     8590overHang
     8591    "return font the overHang"
     8592
     8593    ^ overHang
    85418594! !
    85428595
    85438596!DeviceWorkstation class methodsFor:'documentation'!
  • WinWorkstation.st

    diff -r 86cba794dee3 -r 96a744e08e25 WinWorkstation.st
    a b  
    11"
    22COPYRIGHT (c) 1996 by Claus Gittinger
    3 COPYRIGHT (c) 2017 Patrik Svestka
     3COPYRIGHT (c) 2017-2018 Patrik Svestka
    44COPYRIGHT (c) 2015-2018 Jan Vrany
    55              All Rights Reserved
    66
     
    172172#include <stdlib.h>
    173173#include <stdio.h>
    174174#include <errno.h>
     175#include <assert.h>
    175176/* #include <malloc.h> */
    176177/* #include <math.h> */
    177178/* #include <string.h> */
     
    52845285copyright
    52855286"
    52865287COPYRIGHT (c) 1996 by Claus Gittinger
    5287 COPYRIGHT (c) 2017 Patrik Svestka
     5288COPYRIGHT (c) 2017-2018 Patrik Svestka
    52885289COPYRIGHT (c) 2015-2018 Jan Vrany
    52895290              All Rights Reserved
    52905291
     
    80878088    ] valueUninterruptably.
    80888089
    80898090    windowId notNil ifTrue:[
    8090         self addKnownView:aView withId:windowId
     8091        self addKnownView:aView withId:windowId.
     8092        (aView windowStyle == #toolWindow) ifTrue:[
     8093            self raiseWindowToTopMost: aView id. 
     8094        ]. 
    80918095    ].
    80928096    ^ windowId
    80938097
    80948098    "Modified: / 28-01-2012 / 10:20:30 / cg"
     8099    "Modified: / 25-01-2018 / 10:19:46 / jv"
    80958100!
    80968101
    80978102dcGetClipBoxForGC: gcId
     
    1077310778
    1077410779    unsigned char *cp;
    1077510780    OBJ cls;
    10776     int i1, i2, n, l, toDisplay;
     10781    SIZE size;
     10782    TEXTMETRICW tmet;
     10783    short maxDisplayBuffer;
     10784    int i1, i2, n, l;
     10785    int maxWidth, toDisplay;
    1077710786    int nInstBytes;
    1077810787
    10779 
    1078010788    if (__isExternalAddress(aGCId)
    1078110789     && __isNonNilObject(aString)
    1078210790     && __bothSmallInteger(index1, index2)
     
    1078710795        HDC hDC;
    1078810796        HFONT hOldFont;
    1078910797
    10790         /* Windows (as in 7 or newer) limits the string size for TextOut* to 3275 */
    10791         const int MAX_DISPLAY_BUFFER = 3275;
    10792 
    1079310798        i1 = __intVal(index1) - 1;
    1079410799        i2 = __intVal(index2) - 1;
    1079510800        if ((i1 < 0) || (i2 < i1)) {
     
    1081310818                gcData->bkMode = BK_TRANSPARENT;
    1081410819            }
    1081510820        }
     10821
     10822  /* The Windows (as in 7 or newer) limits the string size for TextOut*.  There is apparently
     10823   * an undocumented limit to the overall raster size.  It changes according to the font size (width)!
     10824   * The maximum value for the raster size is apparently 16384 (experimentally tested on Windows 7).
     10825   */
     10826
     10827
     10828  /* GetTextMetricsW gives all needed font metrics (has a fallback when fails)
     10829   * - a maxWidth parameter takes in account the worst case scenario - user prints
     10830   * with the widest possible characters from the selected font.
     10831   * - a overHang is a parameter which allows the font to grow outside the maxWidth size
     10832   */
     10833
     10834  if (GetTextMetricsW(hDC, &tmet)) {
     10835      maxWidth = tmet.tmMaxCharWidth;
     10836      // Dynamically calculate the maximum buffer size for the selected font and its size
     10837      maxDisplayBuffer = 16384 / (maxWidth + tmet.tmOverhang);
     10838  } else {
     10839      /* A fallback when GetTextMetricsW fails.  Should not normally happen!
     10840       * The works case scenario, experimentally tested from 1170 fonts, is Microsoft Uighur-build-italic-288
     10841       * with maxWidth = 2179.  That would mean only 7 characters at the maxDisplayBuffer (16384 / 2179).
     10842       * Such a buffer would be rediculously slow!. A compromise is needed (speed vs. functionality)
     10843       * Taking an avgWidth from all 1170 with fonts size 96pt -> avgWidth = 152,
     10844       * which should suffice 99.9% of time. The buffer would then be int(16384/152) = 107, which is reasonable.
     10845       */
     10846      maxDisplayBuffer = 107;
     10847  }
     10848
    1081610849#if 0
    1081710850        /* leftover code from tries to make TextOut honor the gc-mode,
    1081810851         * until I googled, that TextOut does not (by purpose, or backward-bug compatibility)
     
    1084110874                cp += i1;
    1084210875                do {
    1084310876                    /* TA_UPDATECP used => pX, pY ignored */
    10844                     if (! TextOutA(hDC, 0, 0, (char *)cp, MIN(toDisplay, MAX_DISPLAY_BUFFER))) {
     10877                    if (! TextOutA(hDC, 0, 0, (char *)cp, MIN(toDisplay, maxDisplayBuffer))) {
    1084510878                        PRINTF(("WinWorkstation [warning]: TextOutA failed. [%d]\n", __LINE__));
    1084610879                        PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d leftToShow=%d\n", GetLastError(), pX, pY, l, toDisplay));
    1084710880                        goto error;
    1084810881                    }
    10849                     cp += MAX_DISPLAY_BUFFER;
    10850                     toDisplay -= MAX_DISPLAY_BUFFER;
     10882                    cp += maxDisplayBuffer;
     10883                    toDisplay -= maxDisplayBuffer;
    1085110884                } while(toDisplay > 0);
    1085210885            }
    1085310886            goto ret;
     
    1086910902                w_cp += i1;
    1087010903                do {
    1087110904                    /* TA_UPDATECP used => pX, pY ignored */
    10872                     if (! TextOutW(hDC, 0, 0, w_cp, MIN(toDisplay, MAX_DISPLAY_BUFFER))) {
     10905                    if (! TextOutW(hDC, 0, 0, w_cp, MIN(toDisplay, maxDisplayBuffer))) {
    1087310906                        PRINTF(("WinWorkstation [warning]: TextOutW failed. [%d]\n", __LINE__));
    1087410907                        PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d leftToShow=%d\n", GetLastError(), pX, pY, l, toDisplay));
    1087510908                        goto error;
    1087610909                    }
    10877                     w_cp += MAX_DISPLAY_BUFFER;
    10878                     toDisplay -= MAX_DISPLAY_BUFFER;
     10910                    w_cp += maxDisplayBuffer;
     10911                    toDisplay -= maxDisplayBuffer;
    1087910912                } while (toDisplay > 0);
    1088010913            }
    1088110914            goto ret;
     
    1327013303      minCode:(rawData at:8)
    1327113304      maxCode:16rFFFF "(rawData at:9)"
    1327213305      direction:nil
    13273       encoding:(rawData at:11).
     13306      encoding:(rawData at:11)
     13307      overHang:(rawData at:12).
    1327413308    ^ info
    1327513309!
    1327613310
    1327713311fontsInFamily:aFamilyName face:aFaceName filtering:filter
    1327813312    "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)."
     13313     On WinWorkStations there is currently Face
     13314     But only these matching filter (if nonNil)."
    1328113315
    1328213316    |allFonts fonts|
    1328313317
     
    1377713811      maxDescent -> (data at:4)
    1377813812      minWidth   -> (data at:5)
    1377913813      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).
     13814      avgWidth   -> (data at:7)
     13815      minChar    -> (data at:8)
     13816      maxChar    -> (data at:9)
     13817      defaultChar-> (data at:10)
     13818      charSet    -> (data at:11)
     13819      overHang   -> (data at:12)
    1378513820"
    1378613821
    1378713822%{
     
    1384413879        __ArrayInstPtr(rawData)->a_element[9] = __MKSMALLINT(tmet.tmDefaultChar);   /* default    -> (data at:10) */
    1384513880        t = __charSetSymbolFor(tmet.tmCharSet);
    1384613881        __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",
     13882  __ArrayInstPtr(rawData)->a_element[11]= __MKSMALLINT(tmet.tmOverhang);      /* overHang   -> (data at:12) */
     13883
     13884        DPRINTF(("textMetrics h=%x  avgAsc=%d avgDesc=%d minW=%d maxW=%d avgW=%d overHang=%d\n",
    1384913885                    hFont, tmet.tmAscent, tmet.tmDescent, avgWidth, tmet.tmMaxCharWidth,
    13850                     tmet.tmAveCharWidth));
     13886                    tmet.tmAveCharWidth, tmet.tmOverhang));
    1385113887        RETURN (self);
    1385213888    }
    1385313889    RETURN (nil);
  • new file tests/FontTests.st

    diff -r 86cba794dee3 -r 96a744e08e25 tests/FontTests.st
    - +  
     1"{ Encoding: utf8 }"
     2
     3"{ Package: 'stx:libview/tests' }"
     4
     5"{ NameSpace: Smalltalk }"
     6
     7TestCase subclass:#FontTests
     8        instanceVariableNames:'testFontSize fontList testString startTimer topView textView'
     9        classVariableNames:''
     10        poolDictionaries:''
     11        category:'TestCases'
     12!
     13
     14!FontTests class methodsFor:'documentation'!
     15
     16documentation
     17"
     18    documentation to be added.
     19
     20    [author:]
     21        svestkap
     22
     23    [instance variables:]
     24
     25    [class variables:]
     26
     27    [see also:]
     28
     29"
     30! !
     31
     32!FontTests methodsFor:'initialize / release'!
     33
     34setUp
     35
     36    | numberOfTestedFonts windowWidthX windowHightY |
     37    self skipIf: Screen current isNil description: 'No display connection'.
     38   
     39    "/init
     40    startTimer := Time now.
     41    numberOfTestedFonts := 100.
     42   
     43    "/random font size to circumvent ascanding or descending font size bugs
     44    testFontSize := #(6 12 24 48 96 288) shuffled.
     45   
     46    "/pick random fonts available at system
     47    fontList := (Display listOfAvailableFonts) shuffled.
     48    fontList := ((fontList size) > numberOfTestedFonts) ifTrue: [fontList copyFrom:1 to: numberOfTestedFonts].
     49
     50    "/Japanese characters for UTF-16 testing
     51    testString := Unicode16String new.
     52    testString := 'コーヒーアイスクリームケーキビールすしかき空'.
     53
     54    "/creating a long string to be displayed at textView
     55    10 timesRepeat:[testString := testString,testString]. 
     56
     57    "/set testing window size -> large for large font testing (will probably fail for smaller)
     58    windowWidthX := 640.
     59    windowHightY := 400.
     60
     61    topView := StandardSystemView new.
     62    topView extent:windowWidthX @ windowHightY.
     63    topView label:'TextOut Raster testing with different font sizes and large strings'.
     64    textView := EditTextView origin:0.0 @ 0.0 extent:1.0 @ 1.0 in:topView.
     65    "/if styles are present, make sure we have correct setup
     66    textView backgroundColor: Color white;
     67             foregroundColor: Color black.
     68
     69    topView open.
     70    topView waitUntilVisible.
     71
     72    "Modified: / 25-04-2018 / 14:35:23 / svestkap"
     73!
     74
     75tearDown
     76    "common cleanup - invoked after testing."
     77    | endTimer message |
     78    endTimer := Time now.
     79   
     80    "/left here for user overview when run manually
     81    "/Transcript showCR: 'FontTests time duration: '; showCR:(endTimer - startTimer) asString.
     82   
     83    message := 'FontTests time duration: ', (endTimer - startTimer) asString.
     84    Logger log: message severity: #info.
     85   
     86    topView isOpen ifTrue:[ topView close ].
     87
     88    "Modified (format): / 25-04-2018 / 12:05:24 / svestkap"
     89! !
     90
     91!FontTests methodsFor:'tests'!
     92
     93test_issue_126_TextOut_raster_size_24bit
     94    " Testing long strings display. 
     95      The test takes shown textView and tries to find out non-white pixels.
     96 
     97    For more visit: https://swing.fit.cvut.cz/projects/stx-jv/ticket/126"
     98    | imageSnapshot |
     99 
     100    self skipIf: (DeviceWorkstation current isWindowsPlatform not) description: 'Not a Windows platform'.
     101    self skipIf: Screen current depth ~~ 24 description: 'Different than 24bit resulution'.
     102
     103    fontList do:[:font |
     104        testFontSize do:[:preselectedFontSize |   | setFontSize fontAtSize bits |
     105               [   textView contents: testString.
     106                   (font size = 0.0) ifTrue:[setFontSize := preselectedFontSize]  "/TrueType font
     107                                     ifFalse:[setFontSize := font size].          "/Raster font
     108                   fontAtSize := (font copy asSize:setFontSize) onDevice:textView device.
     109                   textView font:fontAtSize.
     110
     111                   imageSnapshot := Image fromView:textView grab:false.
     112                   self assert:(imageSnapshot photometric == #rgb).
     113                   self assert:(imageSnapshot isDepth24Image).
     114
     115                   bits := imageSnapshot bits.
     116                   self assert:(bits contains:[:bit | bit ~~ 255 ]).
     117               ] ensure:[textView contents:nil].
     118        ]
     119    ].
     120
     121    "
     122     FontTests run: #test_issue_126_TextOut_raster_size_24bit 
     123     FontTests debug: #test_issue_126_TextOut_raster_size_24bit 
     124    "
     125
     126    "Created: / 05-04-2018 / 12:16:57 / svestkap"
     127    "Modified: / 25-04-2018 / 14:37:12 / svestkap"
     128! !
     129
     130!FontTests class methodsFor:'documentation'!
     131
     132version_HG
     133
     134    ^ '$Changeset: <not expanded> $'
     135! !
     136
  • tests/stx_libview_tests.st

    diff -r 86cba794dee3 -r 96a744e08e25 tests/stx_libview_tests.st
    a b  
    11"
    22 COPYRIGHT (c) 2016-2018 Jan Vrany
     3 COPYRIGHT (c) 2018 Patrik Svestka
    34              All Rights Reserved
    45
    56 This software is furnished under a license and may be used
     
    101102    ^ #(
    102103        "<className> or (<className> attributes...) in load order"
    103104        FcPatternTests
     105        FontTests
    104106        FormTests
    105107        ImageTests
    106108        ResourcePackTests