Orb/Doxygen/src/xmlditacodegenerator.cpp
changeset 0 42188c7ea2d9
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4  *
       
     5  * Permission to use, copy, modify, and distribute this software and its
       
     6  * documentation under the terms of the GNU General Public License is hereby 
       
     7  * granted. No representations are made about the suitability of this software 
       
     8  * for any purpose. It is provided "as is" without express or implied warranty.
       
     9  * See the GNU General Public License for more details.
       
    10  *
       
    11  */
       
    12 #include "xmlditacodegenerator.h"
       
    13 
       
    14 XMLDITACodeGenerator::XMLDITACodeGenerator(XmlStream &t) : m_xs(t),
       
    15 															m_xes(t),
       
    16 															m_lineNumber(-1),
       
    17 															m_insideCodeLine(FALSE),
       
    18 															m_normalHLNeedStartTag(TRUE),
       
    19 															m_insideSpecialHL(FALSE)
       
    20 {
       
    21 #if DITA_CODE_GENERATE
       
    22 #endif
       
    23 }
       
    24 
       
    25 XMLDITACodeGenerator::~XMLDITACodeGenerator()
       
    26 {
       
    27 #if DITA_CODE_GENERATE
       
    28 #endif
       
    29 }
       
    30 
       
    31 void XMLDITACodeGenerator::codify(const char *text)
       
    32 {
       
    33 #if DITA_CODE_GENERATE
       
    34 	if (m_insideCodeLine && !m_insideSpecialHL && m_normalHLNeedStartTag) {
       
    35 		m_xes.push("highlight", "class", "normal");
       
    36 		m_normalHLNeedStartTag=FALSE;
       
    37 	}
       
    38 	writeXMLDITACodeString(m_xs, text, col);
       
    39 #endif
       
    40 }
       
    41 
       
    42 void XMLDITACodeGenerator::writeCodeLink(const char *ref,const char *file,
       
    43                    const char *anchor,const char *name,
       
    44                    const char *tooltip) 
       
    45 {
       
    46 #if DITA_CODE_GENERATE
       
    47 	if (m_insideCodeLine && !m_insideSpecialHL && m_normalHLNeedStartTag) {
       
    48 		m_xes.push("highlight", "class", "normal");
       
    49 		m_normalHLNeedStartTag=FALSE;
       
    50 	}
       
    51 	writeXMLDITALink(m_xs, ref, file, anchor, name, tooltip);
       
    52 	col += strlen(name);
       
    53 #endif
       
    54 }
       
    55 
       
    56 void XMLDITACodeGenerator::startCodeLine()
       
    57 {
       
    58 #if DITA_CODE_GENERATE
       
    59 	AttributeMap codeAttrs;
       
    60 	if (m_lineNumber!=-1) {
       
    61 		QString lineNum;
       
    62 		lineNum.setNum(m_lineNumber);
       
    63 		codeAttrs["lineno"] = lineNum;
       
    64 		if (!m_refId.isEmpty()) {
       
    65 			codeAttrs["refid"] = m_refId;
       
    66 			if (m_isMemberRef) {
       
    67 				codeAttrs["refkind"] = "member";
       
    68 			} else {
       
    69 				codeAttrs["refkind"] = "compound";
       
    70 			}
       
    71 		}
       
    72 		if (!m_external.isEmpty()) {
       
    73 			codeAttrs["external"] = m_external;
       
    74 		}
       
    75 	}
       
    76 	m_xes.push("codeline", codeAttrs);
       
    77 	m_insideCodeLine = TRUE;
       
    78 	col = 0;
       
    79 #endif
       
    80 }
       
    81 
       
    82 void XMLDITACodeGenerator::endCodeLine() {
       
    83 #if DITA_CODE_GENERATE
       
    84 	if (!m_insideSpecialHL && !m_normalHLNeedStartTag) {
       
    85 		m_xes.pop("highlight");
       
    86 		m_normalHLNeedStartTag = TRUE;
       
    87 	}
       
    88 	m_xes.pop("codeline");
       
    89 	m_lineNumber = -1;
       
    90 	m_refId.resize(0);
       
    91 	m_external.resize(0);
       
    92 	m_insideCodeLine = FALSE;
       
    93 #endif
       
    94 }
       
    95 
       
    96 void XMLDITACodeGenerator::startCodeAnchor(const char *id)
       
    97 {
       
    98 #if DITA_CODE_GENERATE
       
    99 	if (m_insideCodeLine && !m_insideSpecialHL && m_normalHLNeedStartTag) {
       
   100 		m_xes.push("highlight", "class", "normal");
       
   101 		m_normalHLNeedStartTag = FALSE;
       
   102 	}
       
   103 	m_xes.push("anchor", "id", id);
       
   104 #endif
       
   105 }
       
   106 
       
   107 void XMLDITACodeGenerator::endCodeAnchor()
       
   108 {
       
   109 #if DITA_CODE_GENERATE
       
   110 	m_xes.pop("anchor");
       
   111 #endif
       
   112 }
       
   113 
       
   114 void XMLDITACodeGenerator::startFontClass(const char *colorClass)
       
   115 {
       
   116 #if DITA_CODE_GENERATE
       
   117 	if (m_insideCodeLine && !m_insideSpecialHL && !m_normalHLNeedStartTag) {
       
   118 		m_xes.pop("highlight");
       
   119 		m_normalHLNeedStartTag=TRUE;
       
   120 	}
       
   121 	m_xes.push("highlight", "class", colorClass );
       
   122 	m_insideSpecialHL = TRUE;
       
   123 #endif
       
   124 }
       
   125 
       
   126 void XMLDITACodeGenerator::endFontClass()
       
   127 {
       
   128 #if DITA_CODE_GENERATE
       
   129 	m_xes.pop("highlight");
       
   130 	m_insideSpecialHL = FALSE;
       
   131 #endif
       
   132 }
       
   133 
       
   134 void XMLDITACodeGenerator::writeLineNumber(const char *extRef,const char *compId,
       
   135                      const char *anchorId,int l)
       
   136 {
       
   137 #if DITA_CODE_GENERATE
       
   138 	// we remember the information provided here to use it 
       
   139 	// at the <codeline> start tag.
       
   140 	m_lineNumber = l;
       
   141 	if (compId) {
       
   142 		m_refId=compId;
       
   143 		if (anchorId) {
       
   144 			m_refId += (QCString)"_1"+anchorId;
       
   145 		}
       
   146 		m_isMemberRef = anchorId!=0;
       
   147 		if (extRef) {
       
   148 			m_external=extRef;
       
   149 		}
       
   150 	}
       
   151 #endif
       
   152 }
       
   153 
       
   154 void XMLDITACodeGenerator::finish()
       
   155 {
       
   156 #if DITA_CODE_GENERATE
       
   157 	if (m_insideCodeLine) {
       
   158 		endCodeLine();
       
   159 	}
       
   160 #endif
       
   161 }
       
   162 
       
   163 void XMLDITACodeGenerator::writeXMLDITACodeString(XmlStream &xt, const char *s, int &col)
       
   164 {
       
   165 #if DITA_CODE_GENERATE
       
   166 	char c;
       
   167 	while ((c=*s++)) {
       
   168 		switch(c) {
       
   169 			case '\t':  { 
       
   170 				int spacesToNextTabStop = Config_getInt("TAB_SIZE") - (col % Config_getInt("TAB_SIZE")); 
       
   171 				col += spacesToNextTabStop;
       
   172 				while (spacesToNextTabStop--) {
       
   173 					XmlElement(xt, "sp");
       
   174 				}
       
   175 				break;
       
   176 			}
       
   177 			case ' ':
       
   178 				XmlElement(xt, "sp");
       
   179 				col++; 
       
   180 				break;
       
   181 			default:
       
   182 				xt << c;
       
   183 				col++;
       
   184 				break;
       
   185 		}
       
   186 	} 
       
   187 #endif
       
   188 }
       
   189 
       
   190 void XMLDITACodeGenerator::linkableSymbol(int, const char *,Definition *,Definition *)
       
   191 {
       
   192 #if DITA_CODE_GENERATE
       
   193 #endif
       
   194 }
       
   195 
       
   196 void XMLDITACodeGenerator::writeCodeAnchor(const char *)
       
   197 {
       
   198 #if DITA_CODE_GENERATE
       
   199 #endif
       
   200 }
       
   201