Audacity  3.0.3
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SourceOutputStream Class Referencefinal

Helper class based on wxOutputStream used to get a png file in text format. More...

Inheritance diagram for SourceOutputStream:
Collaboration diagram for SourceOutputStream:

Public Member Functions

 SourceOutputStream ()
int OpenFile (const FilePath &Filename)
 Opens the file and also adds a standard comment at the start of it. More...
virtual ~SourceOutputStream ()
 Destructor. We close our text stream in here. More...

Protected Member Functions

size_t OnSysWrite (const void *buffer, size_t bufsize) override

Protected Attributes

wxFile File
int nBytes

Detailed Description

Helper class based on wxOutputStream used to get a png file in text format.

Allows us to capture output of the Save .png and 'pipe' it into our own output function which gives a series of numbers.

The trick used here is that wxWidgets can write a PNG image to a stream. By writing to a custom stream, we get to see each byte of data in turn, convert it to text, put in commas, and then write that out to our own text stream.

This class is currently used by Theme to pack its images into the image cache. Perhaps someday we will improve FlowPacker and make it more flexible, and use it for toolbar and window layouts too.

Definition at line 449 of file Theme.cpp.

Constructor & Destructor Documentation

◆ SourceOutputStream()

SourceOutputStream::SourceOutputStream ( )

Definition at line 452 of file Theme.cpp.

452 {;};

◆ ~SourceOutputStream()

SourceOutputStream::~SourceOutputStream ( )

Destructor. We close our text stream in here.

Definition at line 505 of file Theme.cpp.

506 {
507  File.Write( wxT("\r\n") );
508  File.Close();
509 }

References File.

Member Function Documentation

◆ OnSysWrite()

size_t SourceOutputStream::OnSysWrite ( const void *  buffer,
size_t  bufsize 

This is the 'callback' function called with each write of PNG data to the stream. This is where we conveet to text and add commas.

Definition at line 486 of file Theme.cpp.

487 {
488  wxString Temp;
489  for(int i=0;i<(int)bufsize;i++)
490  {
491  // Write one byte with a comma
492  Temp = wxString::Format( wxT("%i,"),(int)(((unsigned char*)buffer)[i]) );
493  File.Write( Temp );
494  nBytes++;
495  // New line if more than 20 bytes written since last time.
496  if( (nBytes %20)==0 )
497  {
498  File.Write( wxT("\r\n "));
499  }
500  }
501  return bufsize;
502 }

References File, and nBytes.

◆ OpenFile()

int SourceOutputStream::OpenFile ( const FilePath Filename)

Opens the file and also adds a standard comment at the start of it.

Definition at line 463 of file Theme.cpp.

464 {
465  nBytes = 0;
466  bool bOk;
467  bOk = File.Open( Filename, wxFile::write );
468  if( bOk )
469  {
470 // DA: Naming of output sourcery
472  File.Write( wxT("/// @file DarkThemeAsCeeCode.h\r\n") );
473 #else
474  File.Write( wxT("/// @file ThemeAsCeeCode.h\r\n") );
475 #endif
476  File.Write( wxT("/// @brief This file was Auto-Generated.\r\n") );
477  File.Write( wxT("///\r\n") );
478  File.Write( wxT("/// It is included by Theme.cpp.\r\n") );
479  File.Write( wxT("/// Only check this into Git if you've read and understood the guidelines!\r\n\r\n ") );
480  }
481  return bOk;
482 }

References File, and nBytes.

Referenced by ThemeBase::CreateImageCache().

Here is the caller graph for this function:

Member Data Documentation

◆ File

wxFile SourceOutputStream::File

Definition at line 458 of file Theme.cpp.

Referenced by OnSysWrite(), OpenFile(), and ~SourceOutputStream().

◆ nBytes

int SourceOutputStream::nBytes

Definition at line 459 of file Theme.cpp.

Referenced by OnSysWrite(), and OpenFile().

The documentation for this class was generated from the following file:
wxFile File
Definition: Theme.cpp:458
int nBytes
Definition: Theme.cpp:459