bool CSkinImage::Validate() { if (!m_bmpBitmap.Ok()) { if (!m_strDesiredBitmap.IsEmpty()) { m_bmpBitmap = wxBitmap(wxImage(m_strDesiredBitmap, wxBITMAP_TYPE_ANY)); } if (!m_bmpBitmap.Ok()) { if (show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load '%s' image. Using default.\n", (const char *)m_strComponentName.mb_str()); } m_bmpBitmap = wxBitmap(m_ppDefaultBitmap); wxASSERT(m_bmpBitmap.Ok()); } } if (!m_colBackgroundColor.Ok()) { if (!m_strDesiredBackgroundColor.IsEmpty()) { m_colBackgroundColor = ParseColor(m_strDesiredBackgroundColor); } if (!m_colBackgroundColor.Ok()) { if (show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load '%s' background color. Using default.\n", (const char *)m_strComponentName.mb_str()); } m_colBackgroundColor = ParseColor(m_strDefaultBackgroundColor); wxASSERT(m_colBackgroundColor.Ok()); } } return true; }
/************* * DESCRIPTION: read a material-chunk * INPUT: pointer to chunk * OUTPUT: - *************/ static void ParsePropMat(HANDLER_DATA *data, CHUNK *mainchunk) { CHUNK chunk; SURFACE *surf; float perc; COLOR color, diffuse; char buf[80]; surf = data->link->SurfaceAdd(data->rc); if (!surf) { data->err = ERR_MEM; return; } do { BeginChunk(data, &chunk); switch (chunk.id) { case ID_PROPNAME: ReadASCIIZ(data, buf); if (!data->link->SurfaceName(data->rc, surf,buf)) { data->err = ERR_MEM; return; } break; case ID_AMBIENT: ParseColor(data, &color); data->link->SurfaceAmbient(data->rc, surf,color.r,color.g,color.b); break; case ID_DIFFUSE: ParseColor(data, &diffuse); data->link->SurfaceDiffuse(data->rc, surf,diffuse.r,diffuse.g,diffuse.b); break; case ID_SPECULAR: ParseColor(data, &color); data->link->SurfaceSpecular(data->rc, surf,color.r,color.g,color.b); break; case ID_SHININESS: perc = ParsePercentage(data); data->link->SurfaceRefPhong(data->rc, surf,perc*100.f); break; case ID_TRANSPARENCY: perc = ParsePercentage(data); data->link->SurfaceTranspar(data->rc, surf,perc*diffuse.r,perc*diffuse.g,perc*diffuse.b); break; } EndChunk(data, &chunk); } while (INCHUNK); }
/** Load a gradient background. */ void LoadGradientBackground(BackgroundNode *bp) { XColor color1; XColor color2; char *temp; char *sep; int len; sep = strchr(bp->value, ':'); if(!sep) { bp->pixmap = None; bp->window = None; return; } /* Get the first color. */ len = (int)(sep - bp->value); temp = AllocateStack(len + 1); memcpy(temp, bp->value, len); temp[len] = 0; ParseColor(temp, &color1); ReleaseStack(temp); /* Get the second color. */ len = strlen(sep + 1); temp = AllocateStack(len + 1); memcpy(temp, sep + 1, len); temp[len] = 0; ParseColor(temp, &color2); ReleaseStack(temp); /* Create the window. */ bp->window = JXCreateSimpleWindow(display, rootWindow, 0, 0, rootWidth, rootHeight, 0, 0, 0); bp->pixmap = JXCreatePixmap(display, bp->window, rootWidth, rootHeight, rootDepth); if(color1.pixel == color2.pixel) { JXSetForeground(display, rootGC, color1.pixel); JXFillRectangle(display, bp->pixmap, rootGC, 0, 0, rootWidth, rootHeight); } else { DrawHorizontalGradient(bp->pixmap, rootGC, color1.pixel, color2.pixel, 0, 0, rootWidth, rootHeight); } }
bool cGuiSkin::LoadInputSkin(){ inputSections[0] = ParseSection("APGUI_SKIN_INPUT_DISABLED"); inputSections[1] = ParseSection("APGUI_SKIN_INPUT_DISABLED_LEFT"); inputSections[2] = ParseSection("APGUI_SKIN_INPUT_DISABLED_RIGHT"); inputSections[3] = ParseSection("APGUI_SKIN_INPUT_NORMAL"); inputSections[4] = ParseSection("APGUI_SKIN_INPUT_NORMAL_LEFT"); inputSections[5] = ParseSection("APGUI_SKIN_INPUT_NORMAL_RIGHT"); inputSections[6] = ParseSection("APGUI_SKIN_INPUT_OVER_NONSELECTE"); inputSections[7] = ParseSection("APGUI_SKIN_INPUT_OVER_NONSELECTE_LEFT"); inputSections[8] = ParseSection("APGUI_SKIN_INPUT_OVER_NONSELECTE_RIGHT"); inputSections[9] = ParseSection("APGUI_SKIN_INPUT_OVER_SELECTED"); inputSections[10] = ParseSection("APGUI_SKIN_INPUT_OVER_SELECTED_LEFT"); inputSections[11] = ParseSection("APGUI_SKIN_INPUT_OVER_SELECTED_RIGHT"); inputSections[12] = ParseSection("APGUI_SKIN_INPUT_SELECTED"); inputSections[13] = ParseSection("APGUI_SKIN_INPUT_SELECTED_LEFT"); inputSections[14] = ParseSection("APGUI_SKIN_INPUT_SELECTED_RIGHT"); ParseColor("APGUI_SKIN_INPUT_TEXT_COLOR", &inputSections[15], &inputSections[16], &inputSections[17]); return inputSections[0] != 0 && inputSections[1] != 0 && inputSections[2] != 0 && inputSections[3] != 0 && inputSections[4] != 0 && inputSections[5] != 0 && inputSections[6] != 0 && inputSections[7] != 0 && inputSections[8] != 0 && inputSections[9] != 0 && inputSections[10] != 0 && inputSections[11] != 0 && inputSections[11] != 0 && inputSections[12] != 0 && inputSections[13] != 0 && inputSections[14] != 0; }
bool cGuiSkin::LoadComboBoxSkin(){ comboBoxSections[0] = ParseSection("APGUI_SKIN_COMBOBOX_DISABLED"); comboBoxSections[1] = ParseSection("APGUI_SKIN_COMBOBOX_DISABLED_LEFT"); comboBoxSections[2] = ParseSection("APGUI_SKIN_COMBOBOX_DISABLED_RIGHT"); comboBoxSections[3] = ParseSection("APGUI_SKIN_COMBOBOX_ARROW_DISABLED"); comboBoxSections[4] = ParseSection("APGUI_SKIN_COMBOBOX_NORMAL"); comboBoxSections[5] = ParseSection("APGUI_SKIN_COMBOBOX_NORMAL_LEFT"); comboBoxSections[6] = ParseSection("APGUI_SKIN_COMBOBOX_NORMAL_RIGHT"); comboBoxSections[7] = ParseSection("APGUI_SKIN_COMBOBOX_ARROW_NORMAL"); comboBoxSections[8] = ParseSection("APGUI_SKIN_COMBOBOX_OVER"); comboBoxSections[9] = ParseSection("APGUI_SKIN_COMBOBOX_OVER_LEFT"); comboBoxSections[10] = ParseSection("APGUI_SKIN_COMBOBOX_OVER_RIGHT"); comboBoxSections[11] = ParseSection("APGUI_SKIN_COMBOBOX_ARROW_OVER"); comboBoxSections[12] = ParseSection("APGUI_SKIN_COMBOBOX_ARROW_DOWN"); comboBoxSections[13] = ParseSection("APGUI_SKIN_COMBOBOX_EXTENDED"); comboBoxSections[14] = ParseSection("APGUI_SKIN_COMBOBOX_EXTENDED_BOTTOM"); comboBoxSections[15] = ParseSection("APGUI_SKIN_COMBOBOX_ITEM_OVER"); ParseColor("APGUI_SKIN_COMBOBOX_TEXT_COLOR", &comboBoxSections[16], &comboBoxSections[17], &comboBoxSections[18]); return comboBoxSections[0] != 0 && comboBoxSections[1] != 0 && comboBoxSections[2] != 0 && comboBoxSections[3] != 0 && comboBoxSections[4] != 0 && comboBoxSections[5] != 0 && comboBoxSections[6] != 0 && comboBoxSections[7] != 0 && comboBoxSections[8] != 0 && comboBoxSections[9] != 0 && comboBoxSections[10] != 0 && comboBoxSections[11] != 0 && comboBoxSections[11] != 0 && comboBoxSections[12] != 0 && comboBoxSections[13] != 0 && comboBoxSections[14] != 0 && comboBoxSections[15]; }
void ColorThemeEngine::FillQML (QSettings& settings) { QMLColors_.clear (); for (const auto& group : settings.childGroups ()) { settings.beginGroup (group); auto& hash = QMLColors_ [group]; for (const auto& key : settings.childKeys ()) hash [key] = ParseColor (settings.value (key)); settings.endGroup (); } auto fixup = [this, &settings] (const QString& section, const QString& name, const QString& fallback) -> void { auto& sec = QMLColors_ [section]; if (sec.contains (name)) return; qWarning () << Q_FUNC_INFO << settings.fileName () << "lacks" << (section + "_" + name) << "; falling back to" << fallback; sec [name] = sec [fallback]; }; fixup ("ToolButton", "HoveredTopColor", "SelectedTopColor"); fixup ("ToolButton", "HoveredBottomColor", "SelectedBottomColor"); }
/* ============= FormatCheck ============= This is called when we hit a \ in the string. It checks for \b+, \b-, \i+, \i-, \c(int int int) and \a(int int int int). It is very picky about things so if there is anything wrong with the passed string it will return 0, an error. If everything is parsed without problem it will return an enum from font.h that represents what was just read in. */ GLint GLFont::FormatCheck(char **where, GLubyte *clr) { if (**where != '\\') return 0; GLint res = 0; char *start = *where; char curr; if (!*++(*where)) { *where = start; return 0; } curr = **where; if (curr == 'b' || curr == 'i') { GLboolean b = curr == 'b'; res = IsToggle(where); if (res == toggleOn) return b ? formatBoldOn : formatItalicOn; else if (res == toggleOff) return b ? formatBoldOff : formatItalicOff; } else if ((curr == 'c' || curr == 'a') && ParseColor(clr, where, curr == 'c' ? 3 : 4)) return curr == 'c' ? formatColor : formatColorA; *where = start; return 0; }
void add_text( vertex_buffer_t * buffer, texture_font_t * font, char* fileBuffer, int bufferSizeBytes, const char* text, vec2 * pen, int currentSize ) { vec2 startPos = *pen; size_t length = strlen(text); Color vertColor = Color::White; for(size_t i=0; i < length; ++i) { if(text[i] == '\n') { pen->x = startPos.x; pen->y -= currentSize; continue; } if(text[i] == '<') { if(i + 1 < length && text[i + 1] == '#') { vertColor = ParseColor(text, i); i += 11; } } float r = vertColor.r; float g = vertColor.g; float b = vertColor.b; float a = vertColor.a; texture_glyph_t *glyph = texture_font_get_glyph( font, fileBuffer, bufferSizeBytes, text[i] ); if( glyph != NULL ) { float kerning = 0; if( i > 0) { kerning = texture_glyph_get_kerning( glyph, text[i-1] ); } pen->x += kerning; int x0 = (int)( pen->x + glyph->offset_x ); int y0 = (int)( pen->y + glyph->offset_y ); int x1 = (int)( x0 + glyph->width ); int y1 = (int)( y0 - glyph->height ); float s0 = glyph->s0; float t0 = glyph->t0; float s1 = glyph->s1; float t1 = glyph->t1; GLuint indices[6] = {0,1,2, 0,2,3}; vertex_t vertices[4] = { {(float)x0, (float)y0, 1.0f, s0, t0, r, g, b, a}, {(float)x0, (float)y1, 1.0f, s0, t1, r, g, b, a}, {(float)x1, (float)y1, 1.0f, s1, t1, r, g, b, a}, {(float)x1, (float)y0, 1.0f, s1, t0, r, g, b, a} }; vertex_buffer_push_back( buffer, vertices, 4, indices, 6 ); pen->x += glyph->advance_x; } } }
static int OnParseColor( LCUI_StyleSheet ss, int key, const char *str ) { LCUI_Style s = &ss->sheet[key]; if( ParseColor( s, str ) ) { return 0; } return -1; }
int CSkinSimple::Parse(MIOFILE& in) { char buf[256]; std::string strBuffer; while (in.fgets(buf, 256)) { if (match_tag(buf, "</simple>")) break; else if (match_tag(buf, "<background_image>")) { m_BackgroundImage.Parse(in); continue; } else if (match_tag(buf, "<dialog_background_image>")) { m_DialogBackgroundImage.Parse(in); continue; } else if (match_tag(buf, "<project_image>")) { m_ProjectImage.Parse(in); continue; } else if (parse_str(buf, "<static_line_color>", strBuffer)) { m_StaticLineColor = ParseColor(wxString(strBuffer.c_str(), wxConvUTF8)); continue; } else if (parse_str(buf, "<notice_alert_color>", strBuffer)) { m_NoticeAlertColor = ParseColor(wxString(strBuffer.c_str(), wxConvUTF8)); continue; } else if (match_tag(buf, "<workunit_animation_image>")) { m_WorkunitAnimationImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_running_image>")) { m_WorkunitRunningImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_suspended_image>")) { m_WorkunitSuspendedImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_waiting_image>")) { m_WorkunitWaitingImage.Parse(in); continue; } else if (parse_int(buf, "<panel_opacity>", m_iPanelOpacity)) { continue; } } InitializeDelayedValidation(); return 0; }
BOOL CBCGPTagManager::ReadColor (const CString& strValue, CBCGPColor& value) { CString strItem; if (ExcludeTag (strValue, strItem)) { return ParseColor (strItem, value); } return FALSE; }
static int IsAttrib(const char *String) { const char *AttribStrings[]={"caps","bold","hide","blink","uppercase","underline","lowercase","inverse",NULL}; int AttribFlags[]={FLAG_CAPS, FLAG_BOLD, FLAG_HIDE, FLAG_BLINK, FLAG_CAPS, FLAG_UNDER, FLAG_LOWERCASE, FLAG_INVERSE}; int val; val=MatchTokenFromList(String,AttribStrings,0); if (val > -1) return(AttribFlags[val]); return(ParseColor(String)); }
QIcon QmitkStyleManager::ThemeIcon(const QByteArray &originalSVG) { auto styleSheet = qApp->styleSheet(); if (styleSheet.isEmpty()) return QPixmap::fromImage(QImage::fromData(originalSVG)); auto iconColor = ParseColor(styleSheet, QStringLiteral("iconColor\\s*[=:]\\s*(#[0-9a-f]{6})"), QStringLiteral("#000000")); auto iconAccentColor = ParseColor(styleSheet, QStringLiteral("iconAccentColor\\s*[=:]\\s*(#[0-9a-f]{6})"), QStringLiteral("#ffffff")); auto themedSVG = QString(originalSVG).replace(QStringLiteral("#00ff00"), iconColor, Qt::CaseInsensitive); themedSVG = themedSVG.replace(QStringLiteral("#ff00ff"), iconAccentColor, Qt::CaseInsensitive); return QPixmap::fromImage(QImage::fromData(themedSVG.toLatin1())); }
static int OnParseBorderColor( LCUI_StyleSheet ss, int key, const char *str ) { LCUI_StyleRec s; if( !ParseColor( &s, str ) ) { return -1; } ss->sheet[key_border_top_color] = s; ss->sheet[key_border_right_color] = s; ss->sheet[key_border_bottom_color] = s; ss->sheet[key_border_left_color] = s; return 0; }
bool pawsSimpleTree::Setup(iDocumentNode* node) { csString colorStr; colorStr = node->GetAttributeValue("colour"); name = node->GetAttributeValue("name"); if(colorStr.GetData() != NULL) defaultColor = ParseColor(colorStr.GetData(), graphics2D); else defaultColor = 0xffffff; return true; }
bool cGuiSkin::LoadListSkin(){ listSections[0] = ParseSection("APGUI_SKIN_LIST_TOP"); listSections[1] = ParseSection("APGUI_SKIN_LIST_LEFT"); listSections[2] = ParseSection("APGUI_SKIN_LIST_DOWN"); listSections[3] = ParseSection("APGUI_SKIN_LIST_RIGHT"); listSections[4] = ParseSection("APGUI_SKIN_LIST_MIDDLE"); ParseColor("APGUI_SKIN_INPUT_TEXT_COLOR", &listSections[5], &listSections[6], &listSections[7]); return listSections[0] != 0 && listSections[1] != 0 && listSections[2] != 0 && listSections[3] != 0 && listSections[4] != 0; }
bool CSkinImage::Validate() { if (!m_bmpBitmap.Ok()) { if (!m_strDesiredBitmap.IsEmpty()) { wxImage img = wxImage(m_strDesiredBitmap, wxBITMAP_TYPE_ANY); if (img.IsOk()) { #ifdef __WXMSW__ // TODO: Choose from multiple size images if provided, else resize the closest one if ((GetXDPIScaling() > 1.05) || (GetYDPIScaling() > 1.05)) { img.Rescale((int) (img.GetWidth()*GetXDPIScaling()), (int) (img.GetHeight()*GetYDPIScaling()), wxIMAGE_QUALITY_BILINEAR ); } #endif m_bmpBitmap = wxBitmap(img); } } if (!m_bmpBitmap.Ok()) { if (show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load '%s' image. Using default.\n", (const char *)m_strComponentName.mb_str()); } m_bmpBitmap = GetScaledBitmapFromXPMData(m_ppDefaultBitmap); wxASSERT(m_bmpBitmap.Ok()); } } if (!m_colBackgroundColor.Ok()) { if (!m_strDesiredBackgroundColor.IsEmpty()) { m_colBackgroundColor = ParseColor(m_strDesiredBackgroundColor); } if (!m_colBackgroundColor.Ok()) { if (show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load '%s' background color. Using default.\n", (const char *)m_strComponentName.mb_str()); } m_colBackgroundColor = ParseColor(m_strDefaultBackgroundColor); wxASSERT(m_colBackgroundColor.Ok()); } } return true; }
VisualizeDetectedObjects::VisualizeDetectedObjects() : arrow_height_(0.5), label_height_(1.0) { ros::NodeHandle private_nh_("~"); ros_namespace_ = ros::this_node::getNamespace(); if (ros_namespace_.substr(0, 2) == "//") { ros_namespace_.erase(ros_namespace_.begin()); } std::string object_src_topic = ros_namespace_ + "/objects"; std::string markers_out_topic = ros_namespace_ + "/objects_markers"; private_nh_.param<double>("object_speed_threshold", object_speed_threshold_, 0.1); ROS_INFO("[%s] object_speed_threshold: %.2f", __APP_NAME__, object_speed_threshold_); private_nh_.param<double>("arrow_speed_threshold", arrow_speed_threshold_, 0.25); ROS_INFO("[%s] arrow_speed_threshold: %.2f", __APP_NAME__, arrow_speed_threshold_); private_nh_.param<double>("marker_display_duration", marker_display_duration_, 0.2); ROS_INFO("[%s] marker_display_duration: %.2f", __APP_NAME__, marker_display_duration_); std::vector<double> color; private_nh_.param<std::vector<double>>("label_color", color, {255.,255.,255.,1.0}); label_color_ = ParseColor(color); ROS_INFO("[%s] label_color: %s", __APP_NAME__, ColorToString(label_color_).c_str()); private_nh_.param<std::vector<double>>("arrow_color", color, {0.,255.,0.,0.8}); arrow_color_ = ParseColor(color); ROS_INFO("[%s] arrow_color: %s", __APP_NAME__, ColorToString(arrow_color_).c_str()); private_nh_.param<std::vector<double>>("hull_color", color, {51.,204.,51.,0.8}); hull_color_ = ParseColor(color); ROS_INFO("[%s] hull_color: %s", __APP_NAME__, ColorToString(hull_color_).c_str()); private_nh_.param<std::vector<double>>("box_color", color, {51.,128.,204.,0.8}); box_color_ = ParseColor(color); ROS_INFO("[%s] box_color: %s", __APP_NAME__, ColorToString(box_color_).c_str()); private_nh_.param<std::vector<double>>("model_color", color, {190.,190.,190.,0.5}); model_color_ = ParseColor(color); ROS_INFO("[%s] model_color: %s", __APP_NAME__, ColorToString(model_color_).c_str()); private_nh_.param<std::vector<double>>("centroid_color", color, {77.,121.,255.,0.8}); centroid_color_ = ParseColor(color); ROS_INFO("[%s] centroid_color: %s", __APP_NAME__, ColorToString(centroid_color_).c_str()); subscriber_detected_objects_ = node_handle_.subscribe(object_src_topic, 1, &VisualizeDetectedObjects::DetectedObjectsCallback, this); ROS_INFO("[%s] object_src_topic: %s", __APP_NAME__, object_src_topic.c_str()); publisher_markers_ = node_handle_.advertise<visualization_msgs::MarkerArray>( markers_out_topic, 1); ROS_INFO("[%s] markers_out_topic: %s", __APP_NAME__, markers_out_topic.c_str()); }
bool CSkinIcon::Validate() { if (!m_strDesiredIcon.IsEmpty()) { // Configure bitmap object with optional transparency mask wxImage img = wxImage(m_strDesiredIcon, wxBITMAP_TYPE_ANY); wxBitmap bmp = wxBitmap(img); // If PNG file has alpha channel use it as mask & ignore <transparency_mask> tag if (!(m_strDesiredTransparencyMask.IsEmpty() || img.HasAlpha())) { bmp.SetMask(new wxMask(bmp, ParseColor(m_strDesiredTransparencyMask))); } // Now set the icon object using the newly created bitmap with optional transparency mask wxIcon ico; ico.CopyFromBitmap(bmp); m_icoIcon.AddIcon(ico); } if (!m_strDesiredIcon32.IsEmpty()) { // Configure bitmap object with optional transparency mask wxImage img32 = wxImage(m_strDesiredIcon32, wxBITMAP_TYPE_ANY); wxBitmap bmp32 = wxBitmap(img32); // If PNG file has alpha channel use it as mask & ignore <transparency_mask> tag if (!(m_strDesiredTransparencyMask32.IsEmpty() || img32.HasAlpha())) { bmp32.SetMask(new wxMask(bmp32, ParseColor(m_strDesiredTransparencyMask32))); } // Now set the icon object using the newly created bitmap with optional transparency mask wxIcon ico32; ico32.CopyFromBitmap(bmp32); m_icoIcon.AddIcon(ico32); } if (!m_icoIcon.Ok()) { if (show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load '%s' icon. Using default.\n", (const char *)m_strComponentName.mb_str()); } m_icoIcon = m_icoDefaultIcon; wxASSERT(m_icoIcon.Ok()); } return true; }
bool cGuiSkin::LoadContainerSkin(){ containerSections[0] = ParseSection("APGUI_SKIN_CONTAINER_BACKGROUND"); containerSections[1] = ParseSection("APGUI_SKIN_CONTAINER_TITLEBAR"); containerSections[2] = ParseSection("APGUI_SKIN_CONTAINER_CLTITLEBAR"); containerSections[3] = ParseSection("APGUI_SKIN_CONTAINER_CLOSE_DIS"); containerSections[4] = ParseSection("APGUI_SKIN_CONTAINER_CLOSE_NORM"); containerSections[5] = ParseSection("APGUI_SKIN_CONTAINER_CLOSE_OVER"); containerSections[6] = ParseSection("APGUI_SKIN_CONTAINER_CLOSE_DOWN"); ParseColor("APGUI_SKIN_CHBOX_LABEL_COLOR", &containerSections[7], &containerSections[8], &containerSections[9]); return containerSections[0] != 0 && containerSections[1] != 0 && containerSections[2] != 0 && containerSections[3] != 0 && containerSections[4] != 0 && containerSections[5] != 0 && containerSections[6] != 0; }
/** Load a solid background. */ void LoadSolidBackground(BackgroundNode *bp) { XColor c; ParseColor(bp->value, &c); /* Create the window. */ bp->window = JXCreateSimpleWindow(display, rootWindow, 0, 0, rootWidth, rootHeight, 0, 0, 0); /* Create the pixmap. */ bp->pixmap = JXCreatePixmap(display, bp->window, 1, 1, rootDepth); JXSetForeground(display, rootGC, c.pixel); JXDrawPoint(display, bp->pixmap, rootGC, 0, 0); }
bool cGuiSkin::LoadCheckBoxSkin(){ checkBoxSections[0] = ParseSection("APGUI_SKIN_CHBOX_DISABLED_NC"); checkBoxSections[1] = ParseSection("APGUI_SKIN_CHBOX_DISABLED_CH"); checkBoxSections[2] = ParseSection("APGUI_SKIN_CHBOX_NORMAL_NC"); checkBoxSections[3] = ParseSection("APGUI_SKIN_CHBOX_NORMAL_CH"); checkBoxSections[4] = ParseSection("APGUI_SKIN_CHBOX_OVER_NC"); checkBoxSections[5] = ParseSection("APGUI_SKIN_CHBOX_OVER_CH"); checkBoxSections[6] = ParseSection("APGUI_SKIN_CHBOX_DOWN_NC"); checkBoxSections[7] = ParseSection("APGUI_SKIN_CHBOX_DOWN_CH"); ParseColor("APGUI_SKIN_CHBOX_LABEL_COLOR", &checkBoxSections[8], &checkBoxSections[9], &checkBoxSections[10]); return checkBoxSections[0] != 0 && checkBoxSections[1] != 0 && checkBoxSections[2] != 0 && checkBoxSections[3] != 0 && checkBoxSections[4] != 0 && checkBoxSections[5] != 0 && checkBoxSections[6] != 0 && checkBoxSections[7] != 0; }
bool cGuiSkin::LoadRadioSkin(){ radioSections[0] = ParseSection("APGUI_SKIN_RADIO_DISABLED_NC"); radioSections[1] = ParseSection("APGUI_SKIN_RADIO_DISABLED_CH"); radioSections[2] = ParseSection("APGUI_SKIN_RADIO_NORMAL_NC"); radioSections[3] = ParseSection("APGUI_SKIN_RADIO_NORMAL_CH"); radioSections[4] = ParseSection("APGUI_SKIN_RADIO_OVER_NC"); radioSections[5] = ParseSection("APGUI_SKIN_RADIO_OVER_CH"); radioSections[6] = ParseSection("APGUI_SKIN_RADIO_DOWN_NC"); radioSections[7] = ParseSection("APGUI_SKIN_RADIO_DOWN_CH"); ParseColor("APGUI_SKIN_RADIO_TEXT_COLOR", &radioSections[8], &radioSections[9], &radioSections[10]); return radioSections[0] != 0 && radioSections[1] != 0 && radioSections[2] != 0 && radioSections[3] != 0 && radioSections[4] != 0 && radioSections[5] != 0 && radioSections[6] != 0 && radioSections[7] != 0; }
static event_t * ReadEvent(int today) { FILE *fp; char buf[PATHLEN]; event_t head; head.next = NULL; sethomefile(buf, cuser.userid, "calendar"); fp = fopen(buf, "r"); if (fp) { while (fgets(buf, sizeof(buf), fp)) { char *date, *color, *content; event_t *t; char *strtok_pos; if (buf[0] == '#') continue; date = strtok_r(buf, " \t\n", &strtok_pos); color = strtok_r(NULL, " \t\n", &strtok_pos); content = strtok_r(NULL, "\n", &strtok_pos); if (!date || !color || !content) continue; t = malloc(sizeof(event_t)); if (ParseEventDate(date, t) || t->days < today) { free(t); continue; } t->color = ParseColor(color) + 30; for (; *content == ' ' || *content == '\t'; content++); t->content = strdup(content); InsertEvent(&head, t); } fclose(fp); } return head.next; }
bool cGuiSkin::LoadButtonSkin(){ buttonSections[0] = ParseSection("APGUI_SKIN_BUTTON_DISABLED"); buttonSections[1] = ParseSection("APGUI_SKIN_BUTTON_DISABLED_LEFT"); buttonSections[2] = ParseSection("APGUI_SKIN_BUTTON_DISABLED_RIGHT"); buttonSections[3] = ParseSection("APGUI_SKIN_BUTTON_NORMAL"); buttonSections[4] = ParseSection("APGUI_SKIN_BUTTON_NORMAL_LEFT"); buttonSections[5] = ParseSection("APGUI_SKIN_BUTTON_NORMAL_RIGHT"); buttonSections[6] = ParseSection("APGUI_SKIN_BUTTON_OVER"); buttonSections[7] = ParseSection("APGUI_SKIN_BUTTON_OVER_LEFT"); buttonSections[8] = ParseSection("APGUI_SKIN_BUTTON_OVER_RIGHT"); buttonSections[9] = ParseSection("APGUI_SKIN_BUTTON_DOWN"); buttonSections[10] = ParseSection("APGUI_SKIN_BUTTON_DOWN_LEFT"); buttonSections[11] = ParseSection("APGUI_SKIN_BUTTON_DOWN_RIGHT"); ParseColor("APGUI_SKIN_BUTTON_TEXT_COLOR", &buttonSections[12], &buttonSections[13], &buttonSections[14]); return containerSections[0] != 0 && containerSections[1] != 0 && containerSections[2] != 0 && containerSections[3] != 0 && containerSections[4] != 0 && containerSections[5] != 0 && containerSections[6] != 0 && containerSections[7] != 0 && containerSections[8] != 0 && containerSections[9] != 0 && containerSections[10] != 0 && containerSections[11] != 0; }
nsresult nsOperaProfileMigrator::CopyPreferences(PRBool aReplace) { nsresult rv; nsCOMPtr<nsIFile> operaPrefs; mOperaProfile->Clone(getter_AddRefs(operaPrefs)); operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME); nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs)); NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED); nsINIParser parser; rv = parser.Init(lf); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPrefBranch> branch(do_GetService(NS_PREFSERVICE_CONTRACTID)); // Traverse the standard transforms PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); const char* lastSectionName = nsnull; for (transform = gTransforms; transform < end; ++transform) { if (transform->sectionName) lastSectionName = transform->sectionName; if (transform->type == _OPM(COLOR)) { char* colorString = nsnull; nsresult rv = ParseColor(parser, lastSectionName, &colorString); if (NS_SUCCEEDED(rv)) { transform->stringValue = colorString; transform->prefHasValue = PR_TRUE; transform->prefSetterFunc(transform, branch); } if (colorString) free(colorString); } else { nsCAutoString val; rv = parser.GetString(lastSectionName, transform->keyName, val); if (NS_SUCCEEDED(rv)) { nsresult strerr; switch (transform->type) { case _OPM(STRING): transform->stringValue = ToNewCString(val); break; case _OPM(INT): { transform->intValue = val.ToInteger(&strerr); } break; case _OPM(BOOL): { transform->boolValue = val.ToInteger(&strerr) != 0; } break; default: break; } transform->prefHasValue = PR_TRUE; transform->prefSetterFunc(transform, branch); if (transform->type == _OPM(STRING) && transform->stringValue) { NS_Free(transform->stringValue); transform->stringValue = nsnull; } } } } // Copy Proxy Settings CopyProxySettings(parser, branch); // Copy User Content Sheet if (aReplace) CopyUserContentSheet(parser); return NS_OK; }
bool Scene::Load (char *filename){ XMLNode tempNode; // Open the Scene XML File printf ("Loading Scenefile %s...\n", filename); XMLNode sceneXML = XMLNode::openFileHelper(filename, "scene"); if (sceneXML.isEmpty ()) return false; m_Desc = CHECK_ATTR(sceneXML.getAttribute("desc")); m_Author = CHECK_ATTR(sceneXML.getAttribute("author")); printf ("Description: \n\t%s\n", m_Desc.c_str ()); printf ("Author: %s\n", m_Author.c_str ()); // Load the Background printf ("Loading Background...\n"); tempNode = sceneXML.getChildNode("background"); if (tempNode.isEmpty ()) return false; m_Background.color = ParseColor (tempNode.getChildNode("color")); m_Background.ambientLight = ParseColor (tempNode.getChildNode("ambientLight")); // Load the Lights printf ("Loading Lights...\n"); tempNode = sceneXML.getChildNode("light_list"); if (!tempNode.isEmpty ()){ unsigned int numLights = tempNode.nChildNode ("light"); for (unsigned int n = 0; n < numLights; n++){ XMLNode tempLightNode = tempNode.getChildNode("light", n); if (tempLightNode.isEmpty ()) return false; SceneLight *tempLight = new SceneLight(); tempLight->color = ParseColor (tempLightNode.getChildNode("color")); tempLight->attenuationConstant = atof(CHECK_ATTR(tempLightNode.getChildNode("attenuation").getAttribute ("constant"))); tempLight->attenuationLinear = atof(CHECK_ATTR(tempLightNode.getChildNode("attenuation").getAttribute ("linear"))); tempLight->attenuationQuadratic = atof(CHECK_ATTR(tempLightNode.getChildNode("attenuation").getAttribute ("quadratic"))); tempLight->position = ParseXYZ (tempLightNode.getChildNode("position")); m_LightList.push_back (tempLight); } } // Load the Materials printf ("Loading Materials...\n"); tempNode = sceneXML.getChildNode("material_list"); if (!tempNode.isEmpty ()){ unsigned int numMaterials = tempNode.nChildNode ("material"); for (unsigned int n = 0; n < numMaterials; n++){ XMLNode tempMaterialNode = tempNode.getChildNode("material", n); if (tempMaterialNode.isEmpty ()) return false; SceneMaterial *tempMaterial = new SceneMaterial(); tempMaterial->name = CHECK_ATTR(tempMaterialNode.getAttribute("name")); tempMaterial->texture = CHECK_ATTR(tempMaterialNode.getChildNode("texture").getAttribute("filename")); tempMaterial->diffuse = ParseColor (tempMaterialNode.getChildNode("diffuse")); tempMaterial->specular = ParseColor (tempMaterialNode.getChildNode("specular")); tempMaterial->shininess = atof(CHECK_ATTR(tempMaterialNode.getChildNode("specular").getAttribute("shininess"))); tempMaterial->transparent = ParseColor (tempMaterialNode.getChildNode("transparent")); tempMaterial->reflective = ParseColor (tempMaterialNode.getChildNode("reflective")); tempMaterial->refraction_index = ParseColor (tempMaterialNode.getChildNode("refraction_index")); if (tempMaterial->texture != ""){ if (!tempMaterial->LoadTexture ()) return false; } m_MaterialList.push_back (tempMaterial); } } // Load the Objects printf ("Loading Objects...\n"); tempNode = sceneXML.getChildNode("object_list"); if (!tempNode.isEmpty ()){ unsigned int numObjects = tempNode.nChildNode (); for (unsigned int n = 0; n < numObjects; n++){ XMLNode tempObjectNode = tempNode.getChildNode(n); if (tempObjectNode.isEmpty ()) return false; if (!strcasecmp(tempObjectNode.getName (), "sphere")){ // Load a Sphere SceneSphere *tempSphere = new SceneSphere (); tempSphere->name = CHECK_ATTR(tempObjectNode.getAttribute("name")); tempSphere->material = CHECK_ATTR(tempObjectNode.getAttribute("material")); tempSphere->radius = atof(CHECK_ATTR(tempObjectNode.getAttribute("radius"))); tempSphere->scale = ParseXYZ (tempObjectNode.getChildNode("scale")); tempSphere->rotation = ParseXYZ (tempObjectNode.getChildNode("rotation")); tempSphere->position = ParseXYZ (tempObjectNode.getChildNode("position")); tempSphere->center = ParseXYZ (tempObjectNode.getChildNode("center")); m_ObjectList.push_back (tempSphere); }else if (!strcasecmp(tempObjectNode.getName (), "triangle")){ // Load a Triangle XMLNode vertexNode; SceneTriangle *tempTriangle = new SceneTriangle (); tempTriangle->name = CHECK_ATTR(tempObjectNode.getAttribute("name")); tempTriangle->scale = ParseXYZ (tempObjectNode.getChildNode("scale")); tempTriangle->rotation = ParseXYZ (tempObjectNode.getChildNode("rotation")); tempTriangle->position = ParseXYZ (tempObjectNode.getChildNode("position")); // Load Vertex 0 vertexNode = tempObjectNode.getChildNodeWithAttribute ("vertex", "index", "0"); tempTriangle->material[0] = CHECK_ATTR(vertexNode.getAttribute("material")); tempTriangle->vertex[0] = ParseXYZ (vertexNode.getChildNode("position")); tempTriangle->normal[0] = ParseXYZ (vertexNode.getChildNode("normal")); tempTriangle->u[0] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("u"))); tempTriangle->v[0] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("v"))); // Load Vertex 1 vertexNode = tempObjectNode.getChildNodeWithAttribute ("vertex", "index", "1"); tempTriangle->material[1] = CHECK_ATTR(vertexNode.getAttribute("material")); tempTriangle->vertex[1] = ParseXYZ (vertexNode.getChildNode("position")); tempTriangle->normal[1] = ParseXYZ (vertexNode.getChildNode("normal")); tempTriangle->u[1] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("u"))); tempTriangle->v[1] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("v"))); // Load Vertex 2 vertexNode = tempObjectNode.getChildNodeWithAttribute ("vertex", "index", "2"); tempTriangle->material[2] = CHECK_ATTR(vertexNode.getAttribute("material")); tempTriangle->vertex[2] = ParseXYZ (vertexNode.getChildNode("position")); tempTriangle->normal[2] = ParseXYZ (vertexNode.getChildNode("normal")); tempTriangle->u[2] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("u"))); tempTriangle->v[2] = atof (CHECK_ATTR(vertexNode.getChildNode("texture").getAttribute("v"))); m_ObjectList.push_back (tempTriangle); }else if (!strcasecmp(tempObjectNode.getName (), "model")){ // Load a Model SceneModel *tempModel = new SceneModel (); tempModel->filename = CHECK_ATTR(tempObjectNode.getAttribute("filename")); if (tempModel->filename == ""){ printf ("No Specified Model filename\n"); return false; } tempModel->name = CHECK_ATTR(tempObjectNode.getAttribute("name")); std::string material = CHECK_ATTR(tempObjectNode.getAttribute("material")); //tempModel->material = tempObjectNode.getAttribute("material"); tempModel->scale = ParseXYZ (tempObjectNode.getChildNode("scale")); tempModel->rotation = ParseXYZ (tempObjectNode.getChildNode("rotation")); tempModel->position = ParseXYZ (tempObjectNode.getChildNode("position")); // Check the file format if (tempModel->filename.substr (tempModel->filename.length() - 4, 4) == ".3ds"){ // Load the list of triangles from the .3ds C3DS sceneObj; if (!sceneObj.Create((char *)tempModel->filename.c_str())){ printf ("Error loading .3ds file\n"); return false; } for (unsigned int obj = 0; obj < (unsigned int)sceneObj.m_iNumMeshs; obj++){ for (unsigned int n = 0; n < (unsigned int)sceneObj.m_pMeshs[obj].iNumFaces; n++){ SceneTriangle tempTriangle; Vector v1, v2, v3; // Vert 1 v1.x = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[0]].x; v1.y = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[0]].y; v1.z = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[0]].z; // Vert 2 v2.x = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[1]].x; v2.y = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[1]].y; v2.z = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[1]].z; // Vert 3 v3.x = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[2]].x; v3.y = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[2]].y; v3.z = sceneObj.m_pMeshs[obj].pVerts[sceneObj.m_pMeshs[obj].pFaces[n].corner[2]].z; // Normal Vector normal = (v1 - v2).Cross(v3 - v2).Normalize(); // Load Vertex 0 tempTriangle.material[0] = material; tempTriangle.vertex[0] = v1; tempTriangle.normal[0] = normal; // Texture Coords if (sceneObj.m_pMeshs[obj].bTextCoords){ tempTriangle.u[0] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[0]].tu; tempTriangle.v[0] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[0]].tv; }else{ tempTriangle.u[0] = 0.0f; tempTriangle.v[0] = 0.0f; } // Load Vertex 1 tempTriangle.material[1] = material; tempTriangle.vertex[1] = v2; tempTriangle.normal[1] = normal; // Texture Coords if (sceneObj.m_pMeshs[obj].bTextCoords){ tempTriangle.u[1] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[1]].tu; tempTriangle.v[1] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[1]].tv; }else{ tempTriangle.u[1] = 0.0f; tempTriangle.v[1] = 0.0f; } // Load Vertex 2 tempTriangle.material[2] = material; tempTriangle.vertex[2] = v3; tempTriangle.normal[2] = normal; // Texture Coords if (sceneObj.m_pMeshs[obj].bTextCoords){ tempTriangle.u[2] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[2]].tu; tempTriangle.v[2] = sceneObj.m_pMeshs[obj].pTexs[sceneObj.m_pMeshs[obj].pFaces[n].corner[2]].tv; }else{ tempTriangle.u[2] = 0.0f; tempTriangle.v[2] = 0.0f; } tempModel->triangleList.push_back (tempTriangle); } } sceneObj.Release(); }else if (tempModel->filename.substr (tempModel->filename.length() - 4, 4) == ".obj"){ // The following code is a modified version of code from the old RayTracer Code rt_trimesh.cpp char line[MAX_LINE_LEN]; char command[MAX_LINE_LEN]; int position; vector<Vector> vertices; vector<Vector> normals; std::ifstream infile (tempModel->filename.c_str()); if (infile.fail()){ printf ("Error loading .obj file\n"); return false; } while (infile.good ()){ infile.getline (line, MAX_LINE_LEN); ParseOBJCommand (line, MAX_LINE_LEN, command, position); if (strcmp (command,"v")==0){ Vector pos = ParseOBJVector (&(line[position])); vertices.push_back (pos); }else if (strcmp (command,"vn")==0){ Vector norm = ParseOBJVector (&(line[position])); normals.push_back (norm); }else if (strcmp (command,"f")==0){ int num = 0; // number of edges int v_index[3]; // vertex index int n_index[3]; // normal index if (!ParseOBJCoords (&(line[position]), num, v_index, n_index)){ printf ("Error parsing faces in .obj file\n"); return false; } SceneTriangle tempTriangle; // Load Vertex 0 tempTriangle.material[0] = material; tempTriangle.vertex[0] = vertices[v_index[0]]; tempTriangle.normal[0] = normals[n_index[0]]; // Texture Coords tempTriangle.u[0] = 0.0f; tempTriangle.v[0] = 0.0f; // Load Vertex 1 tempTriangle.material[1] = material; tempTriangle.vertex[1] = vertices[v_index[1]]; tempTriangle.normal[1] = normals[n_index[1]]; // Texture Coords tempTriangle.u[1] = 0.0f; tempTriangle.v[1] = 0.0f; // Load Vertex 2 tempTriangle.material[2] = material; tempTriangle.vertex[2] = vertices[v_index[2]]; tempTriangle.normal[2] = normals[n_index[2]]; // Texture Coords tempTriangle.u[2] = 0.0f; tempTriangle.v[2] = 0.0f; tempModel->triangleList.push_back (tempTriangle); }else{ //printf ("Ignoring command <%s> in obj file\n", command); } } infile.close (); }else{ printf ("Unsupported file format\n"); return false; } m_ObjectList.push_back (tempModel); }else{ printf ("Unrecognized Node <%s> in <object_list>\n", tempObjectNode.getName ()); exit (255); } } } // Load the Camera printf ("Loading Camera...\n"); tempNode = sceneXML.getChildNode("camera"); if (tempNode.isEmpty ()) return false; m_Camera.SetFOV (atof(CHECK_ATTR2(tempNode.getAttribute("fieldOfView"), "45.0"))); m_Camera.SetNearClip (atof(CHECK_ATTR2(tempNode.getAttribute("nearClip"), "0.1"))); m_Camera.SetFarClip (atof(CHECK_ATTR2(tempNode.getAttribute("farClip"), "100.0"))); m_Camera.SetPosition (ParseXYZ (tempNode.getChildNode("position"))); m_Camera.SetTarget (ParseXYZ (tempNode.getChildNode("target"))); m_Camera.SetUp (ParseXYZ (tempNode.getChildNode("up"))); printf ("Scene Loaded!\n"); return true; }
static bool DecodeField(DecodeState& ds, TxtNode *firstNode, TxtNode *defaultFirstNode, FieldMetadata *fieldDef, uint8_t *structDataStart) { Type type = fieldDef->type; uint8_t *structDataPtr = structDataStart + fieldDef->offset; if ((type & TYPE_NO_STORE_MASK) != 0) { WriteDefaultValue(structDataPtr, type); return true; } bool isCompact = ((type & TYPE_STORE_COMPACT_MASK) != 0); type = (Type)(type & TYPE_NO_FLAGS_MASK); const char *fieldName = ds.fieldNamesSeq + fieldDef->nameOffset; size_t fieldNameLen = str::Len(fieldName); TxtNode *dataNode = FindNode(firstNode, fieldName, fieldNameLen); TxtNode *defaultNode = FindNode(defaultFirstNode, fieldName, fieldNameLen); // if the node doesn't exist in data, try to get it from default data TxtNode *node = dataNode ? dataNode : defaultNode; if (!node) { WriteDefaultValue(structDataPtr, type); return true; } bool ok; if (TYPE_BOOL == type) { bool bVal; ok = ParseBool(node->valStart, node->valEnd, &bVal); if (!ok) return false; WriteStructBool(structDataPtr, bVal); } else if (TYPE_COLOR == type) { COLORREF val; ok = ParseColor(node->valStart, node->valEnd, &val); if (ok) WriteStructUInt(structDataPtr, TYPE_COLOR, val); } else if (IsUnsignedIntType(type)) { uint64_t n; ok = ParseUInt(node->valStart, node->valEnd, &n); if (ok) ok = WriteStructUInt(structDataPtr, type, n); } else if (IsSignedIntType(type)) { int64_t n; ok = ParseInt(node->valStart, node->valEnd, &n); if (ok) ok = WriteStructInt(structDataPtr, type, n); } else if (TYPE_STRUCT_PTR == type) { uint8_t *d = NULL; if (isCompact && (TextNode == node->type)) { d = DeserializeCompact(ds, node, defaultNode, fieldDef->def); } else { if (StructNode != node->type) return false; d = DeserializeRec(ds, node, defaultNode, fieldDef->def); } if (!d) goto Error; WriteStructPtrVal(structDataPtr, d); } else if (TYPE_STR == type) { char *s = node->valStart; size_t sLen = node->valEnd - s; if (s && (sLen > 0)) { // note: we don't free s because it's remembered in structDataPtr s = str::DupN(s, sLen); WriteStructStr(structDataPtr, s); } } else if (TYPE_WSTR == type) { char *s = node->valStart; size_t sLen = node->valEnd - s; if (s && (sLen > 0)) { // note: we don't free ws because it's remembered in structDataPtr WCHAR *ws = str::conv::FromUtf8(s); WriteStructWStr(structDataPtr, ws); } } else if (TYPE_FLOAT == type) { float f; ok = ParseFloat(node->valStart, node->valEnd, &f); if (ok) WriteStructFloat(structDataPtr, f); } else if (TYPE_ARRAY == type) { CrashIf(!fieldDef->def); // array elements must be a struct if (StructNode != node->type) return false; TxtNode *child; ListNode<void> *last = NULL; for (size_t i = 0; i < node->children->Count(); i++) { child = node->children->At(i); if (ArrayNode != child->type) return false; uint8_t *d = DeserializeRec(ds, child, NULL, fieldDef->def); if (!d) goto Error; // TODO: free root ListNode<void> *tmp = AllocArray<ListNode<void>>(1); tmp->val = (void*)d; if (!last) { // this is root last = tmp; // we remember it so that it gets freed in case of error WriteStructPtrVal(structDataPtr, (void*)last); } else { last->next = tmp; last = tmp; } } } else { CrashIf(true); return false; } return true; Error: return false; }
/* parse argument list. we assume that all unrecognized arguments are file names. */ void CommandLineInfo::ParseCommandLine(const WCHAR *cmdLine) { WStrVec argList; ParseCmdLine(cmdLine, argList); size_t argCount = argList.Count(); #define is_arg(txt) str::EqI(TEXT(txt), argument) #define is_arg_with_param(txt) (is_arg(txt) && (argCount > n + 1)) #define additional_param() argList.At(n + 1) #define has_additional_param() ((argCount > n + 1) && ('-' != additional_param()[0])) #define handle_string_param(name) name.Set(str::Dup(argList.At(++n))) #define handle_int_param(name) name = _wtoi(argList.At(++n)) for (size_t n = 1; n < argCount; n++) { WCHAR *argument = argList.At(n); if (is_arg("-register-for-pdf")) { makeDefault = true; exitImmediately = true; return; } else if (is_arg("-silent")) { // silences errors happening during -print-to and -print-to-default silent = true; } else if (is_arg("-print-to-default")) { printerName.Set(GetDefaultPrinterName()); if (!printerName) printDialog = true; exitWhenDone = true; } else if (is_arg_with_param("-print-to")) { handle_string_param(printerName); exitWhenDone = true; } else if (is_arg("-print-dialog")) { printDialog = true; } else if (is_arg_with_param("-print-settings")) { // argument is a comma separated list of page ranges and // advanced options [even|odd] and [noscale|shrink|fit] // e.g. -print-settings "1-3,5,10-8,odd,fit" handle_string_param(printSettings); str::RemoveChars(printSettings, L" "); str::TransChars(printSettings, L";", L","); } else if (is_arg("-exit-when-done") || is_arg("-exit-on-print")) { // only affects -print-dialog (-print-to and -print-to-default // always exit on print) and -stress-test (useful for profiling) exitWhenDone = true; } else if (is_arg_with_param("-inverse-search")) { str::ReplacePtr(&gGlobalPrefs->inverseSearchCmdLine, argList.At(++n)); gGlobalPrefs->enableTeXEnhancements = true; } else if ((is_arg_with_param("-forward-search") || is_arg_with_param("-fwdsearch")) && argCount > n + 2) { // -forward-search is for consistency with -inverse-search // -fwdsearch is for consistency with -fwdsearch-* handle_string_param(forwardSearchOrigin); handle_int_param(forwardSearchLine); } else if (is_arg_with_param("-nameddest") || is_arg_with_param("-named-dest")) { // -nameddest is for backwards compat (was used pre-1.3) // -named-dest is for consistency handle_string_param(destName); } else if (is_arg_with_param("-page")) { handle_int_param(pageNumber); } else if (is_arg("-restrict")) { restrictedUse = true; } else if (is_arg("-invertcolors") || is_arg("-invert-colors")) { // -invertcolors is for backwards compat (was used pre-1.3) // -invert-colors is for consistency // -invert-colors used to be a shortcut for -set-color-range 0xFFFFFF 0x000000 // now it non-permanently swaps textColor and backgroundColor gGlobalPrefs->fixedPageUI.invertColors = true; } else if (is_arg("-presentation")) { enterPresentation = true; } else if (is_arg("-fullscreen")) { enterFullScreen = true; } else if (is_arg_with_param("-view")) { ParseViewMode(&startView, argList.At(++n)); } else if (is_arg_with_param("-zoom")) { ParseZoomValue(&startZoom, argList.At(++n)); } else if (is_arg_with_param("-scroll")) { ParseScrollValue(&startScroll, argList.At(++n)); } else if (is_arg("-console")) { showConsole = true; } else if (is_arg_with_param("-plugin")) { // -plugin [<URL>] <parent HWND> if (argCount > n + 2 && !str::IsDigit(*argList.At(n + 1)) && *argList.At(n + 2) != '-') handle_string_param(pluginURL); // the argument is a (numeric) window handle to // become the parent of a frameless SumatraPDF // (used e.g. for embedding it into a browser plugin) hwndPluginParent = (HWND)_wtol(argList.At(++n)); } else if (is_arg_with_param("-stress-test")) { // -stress-test <file or dir path> [<file filter>] [<page/file range(s)>] [<cycle count>x] // e.g. -stress-test file.pdf 25x for rendering file.pdf 25 times // -stress-test file.pdf 1-3 render only pages 1, 2 and 3 of file.pdf // -stress-test dir 301- 2x render all files in dir twice, skipping first 300 // -stress-test dir *.pdf;*.xps render all files in dir that are either PDF or XPS handle_string_param(stressTestPath); int num; if (has_additional_param() && str::FindChar(additional_param(), '*')) handle_string_param(stressTestFilter); if (has_additional_param() && IsValidPageRange(additional_param())) handle_string_param(stressTestRanges); if (has_additional_param() && str::Parse(additional_param(), L"%dx%$", &num) && num > 0) { stressTestCycles = num; n++; } } else if (is_arg_with_param("-n")) { handle_int_param(stressParallelCount); } else if (is_arg("-rand")) { stressRandomizeFiles = true; } else if (is_arg_with_param("-bench")) { WCHAR *s = str::Dup(argList.At(++n)); pathsToBenchmark.Push(s); s = NULL; if (has_additional_param() && IsBenchPagesInfo(additional_param())) { s = str::Dup(argList.At(++n)); } pathsToBenchmark.Push(s); exitImmediately = true; } else if (is_arg("-crash-on-open")) { // to make testing of crash reporting system in pre-release/release // builds possible crashOnOpen = true; } else if (is_arg("-reuse-instance")) { // for backwards compatibility, -reuse-instance reuses whatever // instance has registered as DDE server reuseDdeInstance = true; } // TODO: remove the following deprecated options within a release or two else if (is_arg("-esc-to-exit")) { gGlobalPrefs->escToExit = true; } else if (is_arg_with_param("-bgcolor") || is_arg_with_param("-bg-color")) { // -bgcolor is for backwards compat (was used pre-1.3) // -bg-color is for consistency ParseColor(&gGlobalPrefs->mainWindowBackground, argList.At(++n)); } else if (is_arg_with_param("-lang")) { lang.Set(str::conv::ToAnsi(argList.At(++n))); } else if (is_arg("-set-color-range") && argCount > n + 2) { ParseColor(&gGlobalPrefs->fixedPageUI.textColor, argList.At(++n)); ParseColor(&gGlobalPrefs->fixedPageUI.backgroundColor, argList.At(++n)); } else if (is_arg_with_param("-fwdsearch-offset")) { handle_int_param(gGlobalPrefs->forwardSearch.highlightOffset); gGlobalPrefs->enableTeXEnhancements = true; } else if (is_arg_with_param("-fwdsearch-width")) { handle_int_param(gGlobalPrefs->forwardSearch.highlightWidth); gGlobalPrefs->enableTeXEnhancements = true; } else if (is_arg_with_param("-fwdsearch-color")) { ParseColor(&gGlobalPrefs->forwardSearch.highlightColor, argList.At(++n)); gGlobalPrefs->enableTeXEnhancements = true; } else if (is_arg_with_param("-fwdsearch-permanent")) { handle_int_param(gGlobalPrefs->forwardSearch.highlightPermanent); gGlobalPrefs->enableTeXEnhancements = true; } else if (is_arg_with_param("-manga-mode")) { const WCHAR *s = argList.At(++n); gGlobalPrefs->comicBookUI.cbxMangaMode = str::EqI(L"true", s) || str::Eq(L"1", s); } #if defined(SUPPORTS_AUTO_UPDATE) || defined(DEBUG) else if (is_arg_with_param("-autoupdate")) { n++; // this should have been handled already by AutoUpdateMain } #endif #ifdef DEBUG else if (is_arg("-enum-printers")) { EnumeratePrinters(); /* this is for testing only, exit immediately */ exitImmediately = true; return; } #endif else { // Remember this argument as a filename to open WCHAR *filePath = NULL; if (str::EndsWithI(argList.At(n), L".lnk")) filePath = ResolveLnk(argList.At(n)); if (!filePath) filePath = str::Dup(argList.At(n)); fileNames.Push(filePath); } } #undef is_arg #undef is_arg_with_param #undef additional_param #undef has_additional_param #undef handle_string_param #undef handle_int_param }
/***************************************************************************** * ParseSSAHeader: Retrieve global formatting information etc *****************************************************************************/ static void ParseSSAHeader( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; char *psz_parser = NULL; char *psz_header = malloc( p_dec->fmt_in.i_extra+1 ); int i_section_type = 1; memcpy( psz_header, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); psz_header[ p_dec->fmt_in.i_extra] = '\0'; /* Handle [Script Info] section */ psz_parser = strcasestr( psz_header, "[Script Info]" ); if( psz_parser == NULL ) goto eof; psz_parser = GotoNextLine( psz_parser ); while( psz_parser[0] != '\0' ) { int temp; char buffer_text[MAX_LINE + 1]; if( psz_parser[0] == '!' || psz_parser[0] == ';' ) /* comment */; else if( sscanf( psz_parser, "PlayResX: %d", &temp ) == 1 ) p_sys->i_original_width = ( temp > 0 ) ? temp : -1; else if( sscanf( psz_parser, "PlayResY: %d", &temp ) == 1 ) p_sys->i_original_height = ( temp > 0 ) ? temp : -1; else if( sscanf( psz_parser, "Script Type: %8192s", buffer_text ) == 1 ) { if( !strcasecmp( buffer_text, "V4.00+" ) ) p_sys->b_ass = VLC_TRUE; } else if( !strncasecmp( psz_parser, "[V4 Styles]", 11 ) ) i_section_type = 1; else if( !strncasecmp( psz_parser, "[V4+ Styles]", 12) ) { i_section_type = 2; p_sys->b_ass = VLC_TRUE; } else if( !strncasecmp( psz_parser, "[Events]", 8 ) ) i_section_type = 4; else if( !strncasecmp( psz_parser, "Style:", 6 ) ) { int i_font_size, i_bold, i_italic, i_border, i_outline, i_shadow, i_underline, i_strikeout, i_scale_x, i_scale_y, i_spacing, i_align, i_margin_l, i_margin_r, i_margin_v; char psz_temp_stylename[MAX_LINE+1]; char psz_temp_fontname[MAX_LINE+1]; char psz_temp_color1[MAX_LINE+1]; char psz_temp_color2[MAX_LINE+1]; char psz_temp_color3[MAX_LINE+1]; char psz_temp_color4[MAX_LINE+1]; if( i_section_type == 1 ) /* V4 */ { if( sscanf( psz_parser, "Style: %8192[^,],%8192[^,],%d,%8192[^,],%8192[^,],%8192[^,],%8192[^,],%d,%d,%d,%d,%d,%d,%d,%d,%d%*[^\r\n]", psz_temp_stylename, psz_temp_fontname, &i_font_size, psz_temp_color1, psz_temp_color2, psz_temp_color3, psz_temp_color4, &i_bold, &i_italic, &i_border, &i_outline, &i_shadow, &i_align, &i_margin_l, &i_margin_r, &i_margin_v ) == 16 ) { ssa_style_t *p_style = malloc( sizeof(ssa_style_t) ); p_style->psz_stylename = strdup( psz_temp_stylename ); p_style->font_style.psz_fontname = strdup( psz_temp_fontname ); p_style->font_style.i_font_size = i_font_size; ParseColor( p_dec, psz_temp_color1, &p_style->font_style.i_font_color, NULL ); ParseColor( p_dec, psz_temp_color4, &p_style->font_style.i_shadow_color, NULL ); p_style->font_style.i_outline_color = p_style->font_style.i_shadow_color; p_style->font_style.i_font_alpha = p_style->font_style.i_outline_alpha = p_style->font_style.i_shadow_alpha = 0x00; p_style->font_style.i_style_flags = 0; if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD; if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC; if( i_border == 1 ) p_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE); else if( i_border == 3 ) { p_style->font_style.i_style_flags |= STYLE_BACKGROUND; p_style->font_style.i_background_color = p_style->font_style.i_shadow_color; p_style->font_style.i_background_alpha = p_style->font_style.i_shadow_alpha; } p_style->font_style.i_shadow_width = i_shadow; p_style->font_style.i_outline_width = i_outline; p_style->i_align = 0; if( i_align == 1 || i_align == 5 || i_align == 9 ) p_style->i_align |= SUBPICTURE_ALIGN_LEFT; if( i_align == 3 || i_align == 7 || i_align == 11 ) p_style->i_align |= SUBPICTURE_ALIGN_RIGHT; if( i_align < 4 ) p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM; else if( i_align < 8 ) p_style->i_align |= SUBPICTURE_ALIGN_TOP; p_style->i_margin_h = ( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ? i_margin_r : i_margin_l; p_style->i_margin_v = i_margin_v; TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style ); } else msg_Warn( p_dec, "SSA v4 styleline parsing failed" ); } else if( i_section_type == 2 ) /* V4+ */ { /* Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding */ if( sscanf( psz_parser, "Style: %8192[^,],%8192[^,],%d,%8192[^,],%8192[^,],%8192[^,],%8192[^,],%d,%d,%d,%d,%d,%d,%d,%*f,%d,%d,%d,%d,%d,%d,%d%*[^\r\n]", psz_temp_stylename, psz_temp_fontname, &i_font_size, psz_temp_color1, psz_temp_color2, psz_temp_color3, psz_temp_color4, &i_bold, &i_italic, &i_underline, &i_strikeout, &i_scale_x, &i_scale_y, &i_spacing, &i_border, &i_outline, &i_shadow, &i_align, &i_margin_l, &i_margin_r, &i_margin_v ) == 21 ) { ssa_style_t *p_style = malloc( sizeof(ssa_style_t) ); p_style->psz_stylename = strdup( psz_temp_stylename ); p_style->font_style.psz_fontname = strdup( psz_temp_fontname ); p_style->font_style.i_font_size = i_font_size; msg_Dbg( p_dec, psz_temp_color1 ); ParseColor( p_dec, psz_temp_color1, &p_style->font_style.i_font_color, &p_style->font_style.i_font_alpha ); ParseColor( p_dec, psz_temp_color3, &p_style->font_style.i_outline_color, &p_style->font_style.i_outline_alpha ); ParseColor( p_dec, psz_temp_color4, &p_style->font_style.i_shadow_color, &p_style->font_style.i_shadow_alpha ); p_style->font_style.i_style_flags = 0; if( i_bold ) p_style->font_style.i_style_flags |= STYLE_BOLD; if( i_italic ) p_style->font_style.i_style_flags |= STYLE_ITALIC; if( i_underline ) p_style->font_style.i_style_flags |= STYLE_UNDERLINE; if( i_strikeout ) p_style->font_style.i_style_flags |= STYLE_STRIKEOUT; if( i_border == 1 ) p_style->font_style.i_style_flags |= (STYLE_ITALIC | STYLE_OUTLINE); else if( i_border == 3 ) { p_style->font_style.i_style_flags |= STYLE_BACKGROUND; p_style->font_style.i_background_color = p_style->font_style.i_shadow_color; p_style->font_style.i_background_alpha = p_style->font_style.i_shadow_alpha; } p_style->font_style.i_shadow_width = ( i_border == 1 ) ? i_shadow : 0; p_style->font_style.i_outline_width = ( i_border == 1 ) ? i_outline : 0; p_style->font_style.i_spacing = i_spacing; //p_style->font_style.f_angle = f_angle; p_style->i_align = 0; if( i_align == 0x1 || i_align == 0x4 || i_align == 0x1 ) p_style->i_align |= SUBPICTURE_ALIGN_LEFT; if( i_align == 0x3 || i_align == 0x6 || i_align == 0x9 ) p_style->i_align |= SUBPICTURE_ALIGN_RIGHT; if( i_align == 0x7 || i_align == 0x8 || i_align == 0x9 ) p_style->i_align |= SUBPICTURE_ALIGN_TOP; if( i_align == 0x1 || i_align == 0x2 || i_align == 0x3 ) p_style->i_align |= SUBPICTURE_ALIGN_BOTTOM; p_style->i_margin_h = ( p_style->i_align & SUBPICTURE_ALIGN_RIGHT ) ? i_margin_r : i_margin_l; p_style->i_margin_v = i_margin_v; /*TODO: Ignored: angle i_scale_x|y (fontscaling), i_encoding */ TAB_APPEND( p_sys->i_ssa_styles, p_sys->pp_ssa_styles, p_style ); } else msg_Dbg( p_dec, "SSA V4+ styleline parsing failed" ); } } psz_parser = GotoNextLine( psz_parser ); } eof: if( psz_header ) free( psz_header ); return; }