Beispiel #1
0
void LessStylesheet::process(Stylesheet &s, ProcessingContext &context) {
    std::list<Extension>* extensions;

    std::list<Ruleset*>::iterator r_it;
    std::list<Extension>::iterator e_it;

    context.pushScope(variables);

    this->context = &context;

    Stylesheet::process(s);

    context.popScope();


    // post processing
    extensions = &context.getExtensions();

    for (r_it = s.getRulesets().begin();
            r_it != s.getRulesets().end();
            r_it++) {
        for (e_it = extensions->begin();
                e_it != extensions->end();
                e_it++) {
            (*e_it).updateSelector((*r_it)->getSelector());
        }
    }
}
Beispiel #2
0
  /*!
   * \author Anders Fernström
   * \date 2006-04-21
   *
   * \brief Set the output style
   */
  void InputCell::setOutputStyle()
  {
    // Set the correct style for the QTextEdit output_
    output_->selectAll();

    Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
    CellStyle style = sheet->getStyle( "Output" );

    if( style.name() != "null" )
    {
      output_->setAlignment( (Qt::AlignmentFlag)style.alignment() );
      output_->mergeCurrentCharFormat( (*style.textCharFormat()) );
      output_->document()->rootFrame()->setFrameFormat( (*style.textFrameFormat()) );
    }
    else
    {
      // 2006-01-30 AF, add message box
      QString msg = "No Output style defened, please define a Output style in stylesheet.xml";
      QMessageBox::warning( 0, "Warning", msg, "OK" );
    }

    QTextCursor cursor = output_->textCursor();
    cursor.clearSelection();
    output_->setTextCursor( cursor );
  }
Beispiel #3
0
void writeOutput (ostream &out, LessStylesheet &stylesheet, bool format) {
  Stylesheet css;
  ProcessingContext context;
  CssWriter *w1;
  w1 = format ? new CssPrettyWriter(out) : new CssWriter(out);

  try{
    stylesheet.process(css, context);

  } catch(ParseException* e) {
#ifdef WITH_LIBGLOG
    LOG(ERROR) << e->getSource() << ": Line " << e->getLineNumber() << ", Column " << 
      e->getColumn() << " Parse Error: " << e->what();
#else
    cerr << e->getSource() << ": Line " << e->getLineNumber() << ", Column " << 
      e->getColumn() << " Parse Error: " << e->what();
#endif

    return;
  } catch(exception* e) {
#ifdef WITH_LIBGLOG
    LOG(ERROR) << "Error: " << e->what();
#else
    cerr << "Error: " << e->what();
#endif
    return;
  }

  css.write(*w1);
  out << endl;
  delete w1;
}
void stylesheet_new_style(const ustring & stylesheet, const ustring & marker)
// Adds a new style. Searches template for data.
{
  // Pointer to the styles object.
  extern Styles * styles;
  
  // The stylesheet to which to add data.
  Stylesheet * sheet = styles->stylesheet (stylesheet);
  
  // If the style is in the standard template, copy it over into the stylesheet.
  Stylesheet * standard = styles->stylesheet ("");
  for (unsigned int i = 0; i < standard->styles.size(); i++) {
    Style * style = standard->styles[i];
    if (style->marker == marker) {
      // Make deep copy and store it into the stylesheet.
      Style * newstyle = new Style (*style);
      sheet->insert (newstyle);
      sheet->save();
      return;
    }
  }

  // Create a default new style for the marker.
  Style *style = new Style(marker);
  sheet->insert (style);
  sheet->save();  
}
void stylesheet_delete_style(const ustring & stylesheet, const ustring & marker)
// Deletes a style.
{
  extern Styles * styles;
  Stylesheet * sheet = styles->stylesheet (stylesheet);
  sheet->erase (marker);
  sheet->save();
}
void stylesheet_save_style(const ustring & stylesheet, const Style & style_in)
{
  extern Styles * styles;
  Stylesheet * sheet = styles->stylesheet (stylesheet);
  Style * style_out = sheet->style (style_in.marker);
  if (style_out) { (*style_out) = style_in; } // deep copy
  sheet->save();
}
void stylesheet_load_style(const ustring & stylesheet, Style& style_to_load)
/*
Reads one Style.
stylesheet: which stylesheet to read from. If no stylesheet is given, it reads from the template.
style: the Style object to read. The marker is given in it.
*/
{
  extern Styles * styles;
  Stylesheet * sheet = styles->stylesheet (stylesheet);
  Style * style = sheet->style (style_to_load.marker);
  if (style) { style_to_load = (*style); } // deep copy
}
Beispiel #8
0
  /*!
   * \author Anders Fernström
   * \date 2005-10-28
   *
   * \brief Set cell style
   *
   * \param stylename The style name of the style that is to be applyed to the cell
   */
  void Cell::setStyle(const QString &stylename)
  {

    Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
    CellStyle style = sheet->getStyle( stylename );

    if( style.name() != "null" )
      setStyle( style );
    else
    {
      cout << "Can't set style, style name: " << stylename.toStdString() << " is not valid" << endl;
    }
  }
Beispiel #9
0
// At rules
TEST(CssParserTest, AtRule) {
  istringstream in("@import somefile;");
    
  CssTokenizer t(&in);
  CssParser p(&t);
  Stylesheet s;
  AtRule* at;

  p.parseStylesheet(&s);
  ASSERT_EQ(1, s.getAtRules()->size());
  
  at = s.getAtRules()->at(0);
  ASSERT_STREQ("@import", at->getKeyword()->c_str());
  ASSERT_STREQ("somefile", at->getRule()->toString()->c_str());
}
Beispiel #10
0
void LessAtRule::process(Stylesheet &s) {
  AtRule* target = s.createAtRule(getKeyword());
  
  target->setRule(getRule());

  getLessStylesheet()->getContext()->processValue(target->getRule());
}
Beispiel #11
0
XALAN_CPP_NAMESPACE_BEGIN



ElemTextLiteral::ElemTextLiteral(
            StylesheetConstructionContext&  constructionContext,
            Stylesheet&                     stylesheetTree,
            XalanFileLoc                    lineNumber, 
            XalanFileLoc                    columnNumber,
            const XMLCh*                    ch,
            XalanDOMString::size_type       start,
            XalanDOMString::size_type       length,
            bool                            fPreserveSpace,
            bool                            fDisableOutputEscaping) :
    ElemTemplateElement(
        constructionContext,
        stylesheetTree,
        StylesheetConstructionContext::ELEMNAME_TEXT_LITERAL_RESULT,
        stylesheetTree.getBaseIdentifier(),
        lineNumber,
        columnNumber),
    m_isWhitespace(isXMLWhitespace(ch, start, length)),
    // Always null-terminate our buffer, since we may need it that way.
    m_ch(constructionContext.allocateXalanDOMCharVector(ch + start, length, true)),
    m_length(length)
{
    disableOutputEscaping(fDisableOutputEscaping);

    preserveSpace(fPreserveSpace);
}
Beispiel #12
0
void
ElemVariable::addToStylesheet(
			StylesheetConstructionContext&	constructionContext,
			Stylesheet&						theStylesheet)
{
	// Processing a top-level element only...
	if (&theStylesheet != &getStylesheet())
	{
		constructionContext.error(
			XalanMessageLoader::getMessage(XalanMessages::ElemVariableInstanceAddedToWrongStylesheet),
			0,
			this);
	}
	else if (getParentNodeElem() != 0)
	{
		constructionContext.error(
			XalanMessageLoader::getMessage(XalanMessages::ElemVariableInstanceIsAlreadyParented),
			0,
			this);
	}
	else
	{
		theStylesheet.setTopLevelVariable(this);

		m_isTopLevel = true;
	}
}
Beispiel #13
0
// block in value
TEST(CssParserTest, BlockValue) {
  istringstream in("selector {key: {value}}");
    
  CssTokenizer t(&in);
  CssParser p(&t);
  Stylesheet s;
  Declaration* d;

  p.parseStylesheet(&s);
  ASSERT_EQ(1, s.getRulesets()->size());
  ASSERT_EQ(1, s.getRulesets()->at(0)->getDeclarations()->size());

  d = s.getRulesets()->at(0)->getDeclarations()->at(0);
  ASSERT_STREQ("key", d->getProperty()->c_str());
  ASSERT_STREQ("{value}", d->getValue()->toString()->c_str());
}
void
ElemTemplate::addToStylesheet(
            StylesheetConstructionContext&  constructionContext,
            Stylesheet&                     theStylesheet)
{
    theStylesheet.addTemplate(this, constructionContext); 
}
Beispiel #15
0
void
ElemAttributeSet::addToStylesheet(
            StylesheetConstructionContext&  /* constructionContext */,
            Stylesheet&                     theStylesheet)
{
    theStylesheet.getStylesheetRoot().addAttributeSet(*this);
}
Beispiel #16
0
void LessMediaQuery::process(Stylesheet &s) {
  MediaQuery* query = s.createMediaQuery();

  query->setSelector(*getSelector());
  getContext()->processValue(query->getSelector());

  LessStylesheet::process(*query, *parent->getContext());
}
Beispiel #17
0
void
ElemVariable::init(
			StylesheetConstructionContext&	constructionContext,
			Stylesheet&						stylesheetTree,
			const AttributeListType&		atts)
{
	const unsigned int	nAttrs = atts.getLength();
	
	for(unsigned int i = 0; i < nAttrs; i++)
	{
		const XalanDOMChar* const	aname = atts.getName(i);

		if (equals(aname, Constants::ATTRNAME_SELECT))
		{
			m_selectPattern = constructionContext.createXPath(getLocator(), atts.getValue(i), *this);
		}
		else if (equals(aname, Constants::ATTRNAME_NAME))
		{
			m_qname = constructionContext.createXalanQName(
						atts.getValue(i),
						stylesheetTree.getNamespaces(),
						getLocator());

			if (m_qname->isValid() == false)
			{
				constructionContext.error(
						XalanMessageLoader::getMessage(
							XalanMessages::AttributeValueNotValidQName_2Param,
							Constants::ATTRNAME_NAME.c_str(),
							atts.getValue(i)),
						0,
						this);
			}
		}
		else if(!(isAttrOK(aname, atts, i, constructionContext) || 
				 processSpaceAttr(aname, atts, i, constructionContext)))
		{
			constructionContext.error(
					XalanMessageLoader::getMessage(
						XalanMessages::TemplateHasIllegalAttribute_2Param,
						Constants::ELEMNAME_VARIABLE_WITH_PREFIX_STRING.c_str(),
						aname),
					0,
					this);
		}
	}

	if(m_qname == 0)
	{
		constructionContext.error(
			XalanMessageLoader::getMessage(
				XalanMessages::TemplateMustHaveAttribute_2Param,
				Constants::ELEMNAME_VARIABLE_WITH_PREFIX_STRING,
				Constants::ATTRNAME_NAME),
			0,
			this);
	}
}
Beispiel #18
0
// Rulesets
TEST(CssParserTest, Ruleset) {
  istringstream in("selector {key: value;}");
    
  CssTokenizer t(&in);
  CssParser p(&t);
  Stylesheet s;
  Ruleset* set;
  Declaration* d;

  p.parseStylesheet(&s);
  ASSERT_EQ(1, s.getRulesets()->size());
  set = s.getRulesets()->at(0);
  ASSERT_STREQ("selector", set->getSelector()->toString()->c_str());
  ASSERT_EQ(1, set->getDeclarations()->size());

  d = set->getDeclarations()->at(0);
  ASSERT_STREQ("key", d->getProperty()->c_str());
  ASSERT_STREQ("value", d->getValue()->toString()->c_str());
}
void stylesheet_save_style(const ustring & stylesheet, const ustring & marker, const ustring & name, const ustring & info, StyleType type, int subtype, double fontsize, const ustring & italic, const ustring & bold, const ustring & underline, const ustring & smallcaps, bool superscript, const ustring & justification, double spacebefore, double spaceafter, double leftmargin, double rightmargin, double firstlineindent, bool spancolumns, unsigned int color, bool print, bool userbool1, bool userbool2, bool userbool3, int userint1, int userint2, int userint3, ustring userstring1, ustring userstring2, ustring userstring3)
// Saves style information.
{
  extern Styles * styles;
  Stylesheet * sheet = styles->stylesheet (stylesheet);
  Style * style = sheet->style(marker);
  style->name = name;
  style->info = info;
  style->type = type;
  style->subtype = subtype;
  style->fontsize = fontsize;
  style->italic = italic;
  style->bold = bold;
  style->underline = underline;
  style->smallcaps = smallcaps;
  style->superscript = superscript;
  style->justification = justification;
  style->spacebefore = spacebefore;
  style->spaceafter = spaceafter;
  style->leftmargin = leftmargin;
  style->rightmargin = rightmargin;
  style->firstlineindent = firstlineindent;
  style->spancolumns = spancolumns;
  style->color = color;
  style->print = print;
  style->userbool1 = userbool1;
  style->userbool2 = userbool2;
  style->userbool3 = userbool3;
  style->userint1 = userint1;
  style->userint2 = userint2;
  style->userint3 = userint3;
  style->userstring1 = userstring1;
  style->userstring2 = userstring2;
  style->userstring3 = userstring3;
  sheet->save();  
}
Beispiel #20
0
void MediaQueryRuleset::process(Stylesheet &s, Selector* prefix, ProcessingContext &context) {
  MediaQuery* query;
  Ruleset* target;
  Selector selector;

#ifdef WITH_LIBGLOG
  VLOG(2) << "Processing Less Ruleset: " <<
    getSelector().toString();
#endif
  
  query = s.createMediaQuery();
  selector = getSelector();
  context.interpolate(selector);

  if (query->getSelector().size() > 0) {
    selector.pop_front();

    query->getSelector().push_back(Token(" ", Token::WHITESPACE));
    query->getSelector().push_back(Token("and", Token::IDENTIFIER));
    query->getSelector().insert(query->getSelector().end(),
                                 selector.begin(),
                                 selector.end());
  } else
    query->setSelector(selector);

  if (prefix != NULL) {
    target = query->createRuleset();
    target->setSelector(*prefix);

#ifdef WITH_LIBGLOG
    VLOG(3) << "Interpolating selector " <<
    target->getSelector().toString();
#endif
    context.interpolate(target->getSelector());
  
    insert(NULL, *target, context);
  } else
    insert(NULL, *query, context);
}
Beispiel #21
0
XALAN_CPP_NAMESPACE_BEGIN



ElemAttributeSet::ElemAttributeSet(
            StylesheetConstructionContext&  constructionContext,
            Stylesheet&                     stylesheetTree,
            const AttributeListType&        atts,
            XalanFileLoc                    lineNumber,
            XalanFileLoc                    columnNumber) :
    ElemUse(constructionContext,
            stylesheetTree,
            lineNumber,
            columnNumber,
            StylesheetConstructionContext::ELEMNAME_ATTRIBUTE_SET),
    m_qname(0)
{
    const XalanSize_t   nAttrs = atts.getLength();

    for (XalanSize_t i = 0; i < nAttrs; i++)
    {
        const XalanDOMChar* const   aname = atts.getName(i);

        if (equals(aname, Constants::ATTRNAME_NAME))
        {
            m_qname = constructionContext.createXalanQName(
                atts.getValue(i),
                stylesheetTree.getNamespaces(),
                getLocator());

            if (m_qname->isValid() == false)
            {
                error(
                    constructionContext,
                    XalanMessages::AttributeValueNotValidQName_2Param,
                    aname,
                    atts.getValue(i));
            }
        }
        else if (processUseAttributeSets(
                    constructionContext,
                    aname,
                    atts,
                    i) == false &&
                 isAttrOK(
                    aname,
                    atts,
                    i,
                    constructionContext) == false)
        {
            error(
                constructionContext,
                XalanMessages::ElementHasIllegalAttribute_2Param,
                Constants::ELEMNAME_ATTRIBUTESET_WITH_PREFIX_STRING.c_str(),
                aname);
        }
    }

    if (m_qname == 0)
    {
        error(
            constructionContext,
            XalanMessages::ElementMustHaveAttribute_2Param,
            Constants::ELEMNAME_ATTRIBUTESET_WITH_PREFIX_STRING,
            Constants::ATTRNAME_NAME);
    }
    assert(m_qname->isValid() == true);
}
Beispiel #22
0
  /*!
  * \author Ingemar Axelsson and Anders Fernström
  *
  *
  * \todo Remove document dependency from Cellstructure. It is only
  * used to point to a commandcenter (in this case the current
  * document) and for the click event to get the current
  * cursor. This can be done in some better way. Maybe by sending a
  * signal to the document instead.(Ingemar Axelsson)
  */
  Cell *CellFactory::createCell(const QString &style, Cell *parent)
  {
    if(style == "input" || style == "Input" || style == "ModelicaInput")
    {
      InputCell *text = new InputCell(doc_, parent);

      try
      {
        Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
        CellStyle cstyle = sheet->getStyle( "Input" );

        if( cstyle.name() != "null" )
          text->setStyle( cstyle );
        else
          throw runtime_error("No Input style defened, the inputcell may not work correctly, please define a Input style in stylesheet.xml");
      }
      catch( exception e )
      {
        QMessageBox::warning( 0, "Warning", e.what(), "OK" );
      }

      try
      {
        text->setDelegate(OmcInteractiveEnvironment::getInstance());
      }
      catch( exception e )
      {}

      QObject::connect(text, SIGNAL(cellselected(Cell *,Qt::KeyboardModifiers)),
        doc_, SLOT(selectedACell(Cell*,Qt::KeyboardModifiers)));
      QObject::connect(text, SIGNAL(clicked(Cell *)),
        doc_, SLOT(mouseClickedOnCell(Cell*)));
      QObject::connect(text, SIGNAL(clickedOutput(Cell *)),
        doc_, SLOT(mouseClickedOnCellOutput(Cell*)));

      // 2005-11-29 AF
      QObject::connect( text, SIGNAL( heightChanged() ),
        doc_, SLOT( updateScrollArea() ));

      // 2006-01-17 AF
      QObject::connect( text, SIGNAL( textChanged(bool) ),
        doc_, SLOT( setChanged(bool) ));

      // 2006-04-27 AF
      QObject::connect( text, SIGNAL( forwardAction(int) ),
        doc_, SIGNAL( forwardAction(int) ));

      //      CellDocument* d = dynamic_cast<CellDocument*>(doc_);
      //      DocumentView* d2 = d->observers_[0];
      //      NotebookWindow *d3 = dynamic_cast<NotebookWindow*>(d2);
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), doc_, SIGNAL(copyAvailable(bool)));
      QObject::connect(text->input_, SIGNAL(undoAvailable(bool)), doc_, SIGNAL(undoAvailable(bool)));
      QObject::connect(text->input_, SIGNAL(redoAvailable(bool)), doc_, SIGNAL(redoAvailable(bool)));
      QObject::connect(text->output_, SIGNAL(copyAvailable(bool)), doc_, SIGNAL(copyAvailable(bool)));

      //QObject::connect(doc_, SIGNAL(evaluate()), text->input_, SIGNAL(eval()));

      /*
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), d3->copyAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(copyAvailable(bool)), d3->cutAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(undoAvailable(bool)), d3->undoAction, SLOT(setEnabled(bool)));
      QObject::connect(text->input_, SIGNAL(redoAvailable(bool)), d3->redoAction, SLOT(setEnabled(bool)));

      QObject::connect(text->output_, SIGNAL(copyAvailable(bool)), d3->copyAction, SLOT(setEnabled(bool)));
      */
      return text;
    }
Beispiel #23
0
void
ElemLiteralResult::init(
			StylesheetConstructionContext&	constructionContext,
			Stylesheet&						stylesheetTree,
			const XalanDOMChar*				name,
			const AttributeListType&		atts)
{
	assert(name != 0);

	hasPrefix(indexOf(name, XalanUnicode::charColon) < length(name) ? true : false);

	const unsigned int	nAttrs = atts.getLength();

	// This over-allocates, but we probably won't waste that much space.
	m_avts = constructionContext.allocateAVTPointerVector(nAttrs);
	assert(m_avts != 0);

	const StylesheetConstructionContext::GetAndReleaseCachedString	theGuard(constructionContext);

	XalanDOMString&		theBuffer = theGuard.get();

	for(unsigned int i = 0; i < nAttrs; i++)
	{
		const XalanDOMChar*	const	aname = atts.getName(i);

		bool								needToProcess = true;
		const XalanDOMString::size_type		indexOfNSSep = indexOf(aname, XalanUnicode::charColon);
		const XalanDOMString::size_type		len = length(aname);

		if(indexOfNSSep < len)
		{
			substring(aname, theBuffer, 0, indexOfNSSep);

			if(!equals(theBuffer, DOMServices::s_XMLNamespace))
			{
				const XalanDOMString* const		ns =
						getNamespaceForPrefixInternal(theBuffer);

				if(ns == 0)
				{
					constructionContext.error(
						XalanMessageLoader::getMessage(XalanMessages::UndeclaredNamespacePrefix_1Param, theBuffer),
						0,
						this);
				}
				else if(equals(*ns, stylesheetTree.getXSLTNamespaceURI()))
				{
					theBuffer.assign(aname + indexOfNSSep + 1, len - (indexOfNSSep + 1));

					if(processPrefixControl(constructionContext, stylesheetTree, theBuffer, atts.getValue(i)) == true)
					{
						needToProcess = false;
					}
					else if (equals(theBuffer, Constants::ATTRNAME_VERSION) == true)
					{
						const XalanDOMChar*	const	value = atts.getValue(i);

						stylesheetTree.setXSLTVerDeclared(DoubleSupport::toDouble(value));
					}
				}
			}
			else
			{
				// don't process namespace decls
				needToProcess = false;
			}
		}

		if(needToProcess == true)
		{
			processSpaceAttr(aname, atts, i, constructionContext);

			// Add xmlns attribute(except xmlns:xsl), xml:space, etc... 
			// Ignore anything with xsl:xxx 
			if(! processUseAttributeSets(constructionContext, aname, atts, i) &&
					isAttrOK(aname, atts, i, constructionContext))
			{
				m_avts[m_avtsCount++] =
					constructionContext.createAVT(getLocator(), aname, atts.getValue(i), *this);
			}
		}
	}
}
Beispiel #24
0
XALAN_CPP_NAMESPACE_BEGIN



ElemWithParam::ElemWithParam(
			StylesheetConstructionContext&	constructionContext,
			Stylesheet&						stylesheetTree,
			const AttributeListType&		atts,
			int								lineNumber,
			int								columnNumber) :
	ElemTemplateElement(constructionContext,
						stylesheetTree,
						lineNumber,
						columnNumber,
						StylesheetConstructionContext::ELEMNAME_WITH_PARAM),
	m_selectPattern(0),
	m_qname(0)
{
	const unsigned int	nAttrs = atts.getLength();

	for(unsigned int i = 0; i < nAttrs; i++)
	{
		const XalanDOMChar* const	aname = atts.getName(i);

		if(equals(aname, Constants::ATTRNAME_SELECT))
		{
			m_selectPattern = constructionContext.createXPath(getLocator(), atts.getValue(i), *this);
		}
		else if(equals(aname, Constants::ATTRNAME_NAME))
		{
			m_qname = constructionContext.createXalanQName(
						atts.getValue(i),
						stylesheetTree.getNamespaces(),
						getLocator());

			if (m_qname->isValid() == false)
			{
				constructionContext.error(
						XalanMessageLoader::getMessage(
							XalanMessages::AttributeValueNotValidQName_2Param,
							Constants::ATTRNAME_NAME.c_str(),
							atts.getValue(i)),
						0,
						this);
			}
		}
		else if(!isAttrOK(aname, atts, i, constructionContext))
		{
			constructionContext.error(
					XalanMessageLoader::getMessage(
						XalanMessages::TemplateHasIllegalAttribute_2Param,
						Constants::ELEMNAME_WITHPARAM_WITH_PREFIX_STRING.c_str(),
						aname),
					0,
					this);
		}
	}

	if(m_qname == 0)
	{
		constructionContext.error(
			XalanMessageLoader::getMessage(
				XalanMessages::TemplateMustHaveAttribute_2Param,
				Constants::ELEMNAME_WITHPARAM_WITH_PREFIX_STRING,
				Constants::ATTRNAME_NAME),
			0,
			this);
	}
}