Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Metafiles and Word

Metafiles and Word

Scheduled Pinned Locked Moved Clever Code
graphicshelpalgorithmsdata-structuresbusiness
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Roger Allen
    wrote on last edited by
    #1

    I just tracked down a subtle bug in a reworked graphing component. One of the requirements has always been that the graph can be exported as a metafile either by clipboard or a file. This has always worked in the previous version of the component. Since it was redeveloped a random output isssue had been seen where you end up with the graph squeezed into one corner of the output and the rest of the area blank. After fiddling with the code for a while and commenting out sections I tracked it down to the line drawing algorithm within the control. We use the good old y = mx + c equation to clip the lines ourselves to the output rectangle (Regions are invalid for metafiles so cannot be used) but because of the GDI line drawing algorithm we plot the final pixel of the final line manually using SetPixel. This is because if you were drawing a line from (1,1) -> (3,3) using GDI it does not set the final pixel. The only problem was I was not checking to see whether this pixel was within the bounding rectangle before plotting it. In normal use mode (i.e not display etc) this pixel usually never has any affect but for Metafiles it has a big impact. If my target output rect was (0, 0) -> (200, 200) and a line was clipped to it but which wanted to be plotted from (x,x) -> (500, 500), the code would plot that pixel at (500, 500). When Word or anything else came to use the metafile it would determine the display rectangle based on the output of all the GDI function calls and would scale the picture to include that 1 pixel at (500, 500) thus giving the buggy output. Nice to see it fixed. Shame it came to light whilst doing a demo to a company director at the time :omg: The usual case when demoing recent developments. :rolleyes:

    If you vote me down, my score will only get lower

    M 1 Reply Last reply
    0
    • R Roger Allen

      I just tracked down a subtle bug in a reworked graphing component. One of the requirements has always been that the graph can be exported as a metafile either by clipboard or a file. This has always worked in the previous version of the component. Since it was redeveloped a random output isssue had been seen where you end up with the graph squeezed into one corner of the output and the rest of the area blank. After fiddling with the code for a while and commenting out sections I tracked it down to the line drawing algorithm within the control. We use the good old y = mx + c equation to clip the lines ourselves to the output rectangle (Regions are invalid for metafiles so cannot be used) but because of the GDI line drawing algorithm we plot the final pixel of the final line manually using SetPixel. This is because if you were drawing a line from (1,1) -> (3,3) using GDI it does not set the final pixel. The only problem was I was not checking to see whether this pixel was within the bounding rectangle before plotting it. In normal use mode (i.e not display etc) this pixel usually never has any affect but for Metafiles it has a big impact. If my target output rect was (0, 0) -> (200, 200) and a line was clipped to it but which wanted to be plotted from (x,x) -> (500, 500), the code would plot that pixel at (500, 500). When Word or anything else came to use the metafile it would determine the display rectangle based on the output of all the GDI function calls and would scale the picture to include that 1 pixel at (500, 500) thus giving the buggy output. Nice to see it fixed. Shame it came to light whilst doing a demo to a company director at the time :omg: The usual case when demoing recent developments. :rolleyes:

      If you vote me down, my score will only get lower

      M Offline
      M Offline
      Manfred Rudolf Bihy
      wrote on last edited by
      #2

      Yep! There's nothing like a demonstration with you customer to make these little devils rear their heads. :sigh:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups